Identify all colours in picture and output to txt ?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
snibgo
Posts: 9403
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo » 2014-06-21T06:30:07-07:00

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.
snibgo's IM pages: im.snibgo.com

Rye
Posts: 130
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

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

Post by Rye » 2014-06-21T09:13:13-07:00

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
Version: ImageMagick 6.8.3-4 2013-02-20 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: DPC OpenMP
Delegates: bzlib fontconfig freetype jng jp2 jpeg lcms lzma pango png ps tiff x xml zlib

User avatar
fmw42
Posts: 22103
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

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

Post by fmw42 » 2014-06-21T10:03:15-07:00

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

snibgo
Posts: 9403
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo » 2014-06-21T10:09:29-07:00

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).
snibgo's IM pages: im.snibgo.com

Rye
Posts: 130
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

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

Post by Rye » 2017-06-17T13:47:13-07:00

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
Version: ImageMagick 6.8.3-4 2013-02-20 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: DPC OpenMP
Delegates: bzlib fontconfig freetype jng jp2 jpeg lcms lzma pango png ps tiff x xml zlib

snibgo
Posts: 9403
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo » 2017-06-17T18:35:10-07:00

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.
snibgo's IM pages: im.snibgo.com

User avatar
anthony
Posts: 8869
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

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

Post by anthony » 2017-06-20T16:35:12-07:00

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!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

Rye
Posts: 130
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

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

Post by Rye » 2017-06-20T16:38:25-07:00

Ah. perfect !
Version: ImageMagick 6.8.3-4 2013-02-20 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: DPC OpenMP
Delegates: bzlib fontconfig freetype jng jp2 jpeg lcms lzma pango png ps tiff x xml zlib

Post Reply