color of each pixel in an image

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?".
Post Reply
whitehorse
Posts: 5
Joined: 2015-02-02T11:59:16-07:00
Authentication code: 6789

color of each pixel in an image

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: color of each pixel in an image

Post 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:
snibgo's IM pages: im.snibgo.com
whitehorse
Posts: 5
Joined: 2015-02-02T11:59:16-07:00
Authentication code: 6789

Re: color of each pixel in an image

Post by whitehorse »

This worked great. Thanks.
Post Reply