Farid Elyahyaoui on  wrote...
|
| Hi,
|
| I'm relatively new to imagemagick so sorry if this question sounds
| stupid to you. I tried to search for an answer on the internet but
| couldn't get a good answer to this question:
|
| How can I get the colours from an image?

A number of ways
1/  You can use
        identify -verbose image.png
    This fails for images with more than 1024 colors though.
    It will output the images color table and color histogram.

    NOTE: an image may not completely use all the colors defined in its
    color table.

2/  You can get a histogram...
    See IM Examples on  "histogram:"
      http://www.cit.gu.edu.au/~anthony/graphics/imagick6/files/#histogram
    Basically it is the text header of the "histogram:" MIFF format image
    Just ignore the binary image data.

    convert  image.png  histogram:- | \
           sed -n '/^Comment={/,/^}/{ s///; /^$/q; s/^ *//; p; }' \
              > color_table.txt

    This also tells you how many pixels use each color in the image.

3/  You can use the (NEW for IM v6.2.8-8)  -unique-colors  operator.
    this replaces each image in the current image sequence with a new
    image containg one pixel for each unique color found, in the order
    they are found during a by a row by row search through the image.

    The result is a 1 pixel high image with the image length being the
    number of unique colors.  You can output the colors to the screen
    using the txt:-  (IM text image format)

    convert  image.png -unique-colors txt:-

    You can also save those colors to use with the -map operator

    convert  image.png -unique-colors  image_colormap.png

| I'm trying to create a color palette generator based on an image such as here:
| http://www.degraeve.com/color-palette/
|

Looks like you wanted the new  -unique-colors operator and merge the
output image with its 'txt' version (comment part of the file format)

| I know I can reduce the number of colors to six or so, but I don't know how 
to extract the colors so I can save them in a text file.

Reduce them using  -colors 6   you may need to specify the colorspace
for the reducion, however this is currently under development, though
-quantize is the current way to do this.

See color reducion, colorspaces
  http://www.cit.gu.edu.au/~anthony/graphics/imagick6/quantize/#quantize

(as mentioned things are in flux)

  Anthony Thyssen ( System Programmer )    <[EMAIL PROTECTED]>
 -----------------------------------------------------------------------------
  Don't explain computers to laymen.  Simpler to explain sex to a virgin. 
                          --- Robert Heilein,  "The Moon is a Harsh Mistress"
 -----------------------------------------------------------------------------
     Anthony's Home is his Castle     http://www.cit.gu.edu.au/~anthony/
_______________________________________________
Magick-users mailing list
[email protected]
http://studio.imagemagick.org/mailman/listinfo/magick-users

Reply via email to