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: 12159
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 »

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: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

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

Post 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
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post 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
snibgo
Posts: 12159
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 »

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: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

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

Post 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
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
snibgo
Posts: 12159
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 »

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: 8883
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 »

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
https://imagemagick.org/Usage/
Rye
Posts: 158
Joined: 2013-02-25T10:43:05-07:00
Authentication code: 6789

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

Post by Rye »

Ah. perfect !
Version: ImageMagick-7.0.7-28-Q16-x64-static http://www.imagemagick.org
Copyright: Copyright (C) 1999-2018 ImageMagick Studio LLC
Post Reply