Page 2 of 2

Re: Identify all colours in picture and output to txt ?

Posted: 2014-06-21T06:30:07-07:00
by snibgo
My command above works for IM 6.8.9-0, but not 6.8.3-0. The following works for both:

Code: Select all

for /F "usebackq skip=1 tokens=6 delims=():, " %%C ^
in (`convert ^
  rose: ^
  -unique-colors ^
  txt:`) ^
do echo %%C >>x.txt
Remove the unique-colors line if you don't want it. Change "rose:" to any filename.

Re: Identify all colours in picture and output to txt ?

Posted: 2014-06-21T09:13:13-07:00
by Rye
EDIT: OK, this way it works:

Code: Select all

for /F "usebackq skip=1 tokens=3" %%C ^
in (`%IM%convert ^
  rose: ^
  -depth 8 ^
  txt:`) ^
do echo %%C >>x.txt
findstr # x.txt >> hex.txt
DEL x.txt
This thread can be close :) thanks

Re: Identify all colours in picture and output to txt ?

Posted: 2014-06-21T10:03:15-07:00
by fmw42
snibgo will have to comment to be sure. But I am not sure if his code was in .bat format or just for pasting into your CMD window. Try just pasting the following into the CMD window and let us know what you get for the rose: image

Code: Select all

for /F "usebackq skip=1 tokens=3" %%C ^
in (`%IM%convert ^
  rose: ^
  txt:`) ^
do echo %%C >>x.txt

Re: Identify all colours in picture and output to txt ?

Posted: 2014-06-21T10:09:29-07:00
by snibgo
I should have said: my commands are for BAT format.

If pasting or typing directly into the command window, change "%%C" to "%C" (ie, don't double the percents).

Re: Identify all colours in picture and output to txt ?

Posted: 2017-06-17T13:47:13-07:00
by Rye
Actually... seems houston is in the house again.
For some reason replacing rose: with my own image seems not to work for whatever reason...

This works (duh.):

Code: Select all

for /F "usebackq skip=1 tokens=3" %%C in (`%IM%convert rose: -depth 8 txt:`) do echo %%C >>x.txt
findstr # x.txt >> hex.txt

However as soon as I replace rose: with 0001.jpg (f.e.), the script just stops.
Any idea what I'm doing wrong here ?

-------------E-D-I-T--------
This also gets the job done, for identifying the hex codes it seems.

Code: Select all

convert img.jpg -unique-colors -depth 8  txt:- > out.txt

Re: Identify all colours in picture and output to txt ?

Posted: 2017-06-17T18:35:10-07:00
by snibgo
Rye wrote:However as soon as I replace rose: with 0001.jpg (f.e.), the script just stops.
How do you know it has stopped? Perhaps it was still working, and you killed it. If your image is large, it will take a long time.

Re: Identify all colours in picture and output to txt ?

Posted: 2017-06-20T16:35:12-07:00
by anthony
Extracting image colors...

http://www.imagemagick.org/Usage/quantize/#extract

Specifically you either use unique colors, or use the histogram: output format and extract teh image comment.

convert rose: -format %c -depth 8 histogram:info:-

This not only outputs the colors (one color per line), but also the color counts!

Re: Identify all colours in picture and output to txt ?

Posted: 2017-06-20T16:38:25-07:00
by Rye
Ah. perfect !