Page 1 of 1

Output single color as TXT:

Posted: 2013-09-15T10:22:40-07:00
by Werty
I need to output files as TXT: but only output a single color like "White", I'm using...

Convert myfile.png myfile.txt

..and get a 40MB large txt file when outputting a 1024x1024 image, which is quite too large, as it outputs all colors.

I only need it to output white colors in the txt file.

Thanks.

Re: Output single color as TXT:

Posted: 2013-09-15T11:29:36-07:00
by snibgo
I'm not sure what you want. Perhaps "-unique-colors" would help.

Re: Output single color as TXT:

Posted: 2013-09-15T11:42:13-07:00
by fmw42
In unix

convert image txt:- | grep "white"

Re: Output single color as TXT:

Posted: 2013-09-15T13:02:58-07:00
by Werty
I'm on windows :)

I would like to have IM outputting the white colors only, instead of....

0,0: ( 0, 0, 0) #000000 black
1,0: ( 0, 0, 0) #000000 black
2,0: ( 0, 0, 0) #000000 black
3,0: ( 0, 0, 0) #000000 black
4,0: ( 255, 255, 255) #FFFFFF white
5,0: ( 0, 0, 0) #000000 black
6,0: ( 255, 255, 255) #FFFFFF white
7,0: ( 0, 0, 0) #000000 black
8,0: ( 0, 0, 0) #000000 black

.. I would like....

4,0: ( 255, 255, 255) #FFFFFF white
6,0: ( 255, 255, 255) #FFFFFF white

..only.

I read somewhere anthony mentioning it could be done, but didnt leave a solution.

Re: Output single color as TXT:

Posted: 2013-09-15T13:57:15-07:00
by snibgo

Code: Select all

convert myfile.png txt: |find "white"
"find" is a standard Windows tool.

Re: Output single color as TXT:

Posted: 2013-09-15T14:16:01-07:00
by Werty
Thanks, but I'm already sorting the .txt file, picking out the "white"'s, I would like IM to be faster outputting that .txt file.

I would guess that if it only should write the whites, the process would be much faster, like looking up the color of the pixel, if it's white then create the text line for the output, if it's black then just move on instead of spending time writing something that's not needed.

The 1024x1024 images i use are mostly pure black, with a few whites, around 1000 only, so no need to output that million of blacks. :)

Re: Output single color as TXT:

Posted: 2013-09-15T14:54:26-07:00
by snibgo
Sorting will take a long time. Do you need to do this before filtering the white pixels?

"txt:" will always write all the pixels. If the white pixels are clustered near each other, you might "-trim" first.

Re: Output single color as TXT:

Posted: 2013-09-15T15:29:13-07:00
by fmw42
There is a special function create to support -sparse-color ... to efficiently get all non-transparent pixels as text input to -sparse-color. I use it in my stainedglass script. It is a simplified output like txt: but only displays the corrdinates and color for all non-fully-transparent pixels. It has been available since 6.8.3.10

For example

convert rose: +transparent white sparse-color:
61,11,white 62,15,white 62,16,white 63,16,white 14,37,white 12,38,white 13,38,white 23,39,white 12,40,white 24,40,white 25,40,white 11,41,white 12,41,white 21,41,white 26,41,white 20,42,white 28,42,white 29,43,white 18,44,white 30,44,white 31,44,white

This is a list of x,y,color triplets

I do not recall where it is documented. I cannot find it right now.

So all you need to do is make everything not white into transparent and it will find all the white pixels quickly.

Re: Output single color as TXT:

Posted: 2013-09-15T15:43:42-07:00
by snibgo
Ah, that's useful. It's mentioned in the changelog. It could usefully be added to http://www.imagemagick.org/Usage/files/#special_formats

Re: Output single color as TXT:

Posted: 2013-09-15T15:55:05-07:00
by fmw42
It also needs to be added some where on http://www.imagemagick.org/script/formats.php

I am trying to edit the documentation, but seem to have lost upload permission.

Anthony would need to edit the page you reference. I will try to send him a note about it.

Re: Output single color as TXT:

Posted: 2013-09-16T15:46:39-07:00
by fmw42
sparse-color: is documented at http://www.imagemagick.org/script/formats.php#supported

I missed finding it before.

Re: Output single color as TXT:

Posted: 2013-09-21T05:47:09-07:00
by Werty
Sorry for replying so late, I dont have my own internet currently :P

The sparsecolor: sounds awesome as my pics are only pure black and white, I'll check it out as soon as I have upgraded my IM installation, I'm currently on 6.7.6-1 as I had to downgrade because INLINE:DATA was broken in a newer 8.5.x.x I tried.

Thanks, I'll report back, when I'm able to :P

Re: Output single color as TXT:

Posted: 2013-10-05T08:13:40-07:00
by Werty
It's me again, I promised to report back :p

Things are now running much much faster, whole process (including some scripting) took about 15 seconds before, now it's almost instant, :)

Thanks again.

Re: Output single color as TXT:

Posted: 2013-10-08T00:07:25-07:00
by anthony
I must have missed the inclusion of "sparse-color:" format.

I would have liked it better if it was newline separated rather than space separated. The "-sparse-color" operator would not care, but it would make it easier for scripts to parse!.

Added to IM Examples (just below "txt:")

http://www.imagemagick.org/Usage/files/#sparse-color

(give it a few hours to appear)