Page 1 of 1

Selected conversion from PNG to TXT

Posted: 2016-08-08T13:32:35-07:00
by AndreaImage
Hi

i need to convert from PNG to TXT
but i don't need to convert all the image
i need to know only the information releated to the white pixel

i already perform something with a double DO LOOP using another library but it takes some minute (about 5) because the image it's quite big

is there some other way using Imagemagick ?

maybe compiling some batch file...

thank to everyone

Re: Selected conversion from PNG to TXT

Posted: 2016-08-08T13:36:08-07:00
by snibgo
How do you convert "from PNG to TXT"? That sounds like OCR (optical character recognition), which IM doesn't do. A program called tesseract can do that.

IM can be useful for preparing an image for OCR.

Without seeing your image, further advice is difficult.

Re: Selected conversion from PNG to TXT

Posted: 2016-08-08T14:04:07-07:00
by AndreaImage
more easy

if you run -convert c:\image.png c:\image_out.txt

in the text file you will find for each pixel the releated color

but i don0t need all the pixel, just the white pixel

is not an ocr application

i just need to know where are located the white pixels in the image

thanks

Re: Selected conversion from PNG to TXT

Posted: 2016-08-08T14:57:59-07:00
by snibgo
Okay, you want the locations of all the white pixels.

Code: Select all

convert in.png +transparent White sparse-color:

Re: Selected conversion from PNG to TXT

Posted: 2016-08-08T15:42:28-07:00
by fmw42
Snibgo: Should I suggest that sparse-color: be changed to output as list rather than a string?

Re: Selected conversion from PNG to TXT

Posted: 2016-08-08T17:03:31-07:00
by snibgo
Well, it's a pain having to split it into lines.

coders\txt.c function WriteTXTImage() once had code to test for an attribute that was supposed to insert '\n' characters. But that code has since been removed.

I think it's dangerous to change IM so it always breaks into lines. But adding an option to tell it to do so would be useful.

Re: Selected conversion from PNG to TXT

Posted: 2016-08-08T17:12:13-07:00
by glennrp
To get a list of the white pixels:

Code: Select all

magick image.png txt:- | grep white

Re: Selected conversion from PNG to TXT

Posted: 2016-08-08T17:30:23-07:00
by snibgo
glenrp wrote:magick image.png txt:- | grep white
Yes, provided the input is fully opaque. If it has transparency, "white" is written as "srgba(255,255,255,1)".

Re: Selected conversion from PNG to TXT

Posted: 2016-08-08T23:11:56-07:00
by AndreaImage
thanks for the reply

just some question

Code: Select all

 convert in.png +transparent White sparse-color: 
is this code write the output to some files?

Code: Select all

 image.png txt:- | grep white 
i don't think that "grep" is for Windows, i read somewhere to use find, is necessary to declare the output file?

thanks again

Re: Selected conversion from PNG to TXT

Posted: 2016-08-08T23:42:03-07:00
by fmw42
Use redirect:

Code: Select all

convert in.png +transparent White sparse-color: > textfile.txt
or

Code: Select all

convert image.png txt:- | grep "white" > textfile.txt

Search google for "grep for windows"

http://gnuwin32.sourceforge.net/packages/grep.htm
http://www.wingrep.com/
http://www.wingrep.com/download.htm

Lots of results.

Re: Selected conversion from PNG to TXT

Posted: 2016-08-09T00:16:00-07:00
by snibgo
Or:

Code: Select all

convert in.png +transparent White sparse-color:textfile.txt

The Microsoft program is called "findstr". So:

Code: Select all

convert in.png txt:- | findstr white
or

Code: Select all

convert in.png txt:- | findstr white >textfile.txt
This is far slower than the previous method.

Re: Selected conversion from PNG to TXT

Posted: 2016-08-09T02:22:46-07:00
by AndreaImage
Thanks again

just last question

is it possibile to revert the output to the text file but just one information to each line?

thanks again

Re: Selected conversion from PNG to TXT

Posted: 2016-08-09T09:05:49-07:00
by fmw42
In unix, you can do

Code: Select all

convert in.png  +transparent White sparse-color: | tr " " "\n"