Page 1 of 1

Working on individual pixels in ImageMagick

Posted: 2009-06-16T07:36:28-07:00
by pitosalas
In my quest for better performance I am looking into calling the ImageMagick command line utilities directly instead of loading images into the Ruby memory space.

I've perused and perused the doc but I can't quite figure out how I would examine individual pixels. For example, let's say I have a 1xn image, b&w. I would like to walk through all the pixels and identify the black to white transitions and white to black.

In other words, if the image looks like this:

w w w b b w b b w

I would like to generate 5 pairs of numbers, as follows:

[0, 2] (white section goes from pixel 0 to 2)
[3, 4] (black section goes from pixel 3 to 4)
[5, 5] (and so on)
[6, 7]
[8, 8]

I've puzzeled around the -format and -fx switches but it seems to get very hairy very quickly.

Can anyone help me understand, or point me to some examples?

Thanks a lot!

Pito

Re: Working on individual pixels in ImageMagick

Posted: 2009-06-16T10:24:40-07:00
by fmw42
you can list out all the pixels by converting the image to txt: output format. see http://www.imagemagick.org/Usage/files/#txt. from there you would be on your own to group pixels.