Page 1 of 1

color of each pixel in an image

Posted: 2015-02-02T12:11:09-07:00
by whitehorse
Hi all,

I run ImageMagick on LinuxMint. I want to know if there is a way for ImageMagick to return the color of each pixel in an image. I want to use this information to construct a physical mosaic (not on the computer) without making reference to the original image. So the output would need to be human readable. So it would be helpful if the output started from the bottom line of the image and gave all the pixel colors in order from left to right, and then proceeded to the second bottom most line, etc. It would also be helpful if a summary was given at the each of how many pixels were X color, Y color, Z color, etc. I am thinking that I will use an image that has only 16, 24, or 32 colors.

Thanks,

Matthew

Re: color of each pixel in an image

Posted: 2015-02-02T12:52:23-07:00
by snibgo
IM starts at the top and works down, so we "-flip" to invert it. Dumping every pixel as text is easy:

Code: Select all

convert in.png -flip txt:
Summarising each row is a little harder. After inverting, we chop it into rows. Then we write the text histogram of each image, ie each row of the input image. To make the output easier to read, we can use a format like "%s\n%c\n\n" which writes the image number and a newline, then the histogram followed by two newlines.

Code: Select all

convert in.png -flip -crop x1 -define histogram:unique-colors=true -format %s\n%c\n\n histogram:info:

Re: color of each pixel in an image

Posted: 2015-02-03T14:20:36-07:00
by whitehorse
This worked great. Thanks.