Page 1 of 1

Get all pixel RGB values

Posted: 2020-05-20T02:46:36-07:00
by ClumsyNinja
CLI / ImageMagick-7.0.9-Q16

I'm working on an automation project and wish to get the rgb value of every pixel in an image.

By taking samples from this forum I have figured out how to get the value of one pixel and output it to a file. This gets the RGB value of pixel 30,40.

Code: Select all

convert "d:\MJT\files\IMtests\Image1.bmp" -format '%[pixel:p{40,30}]'  info:-  > "d:\MJT\files\IMtests\Image1RGB.txt"
I can automate getting every pixel in a loop and increment x/y by 1 each time, but even on a small 250x250 image this means a time consuming loop of 62,500 pixels.

I'm not entirely sure what the extra info is in the output, but I can parse out the extra info and have figured out that 'srgba(30,40,50,1)' means the rgb is 30,40,50. I'm guessing i need to edit something in '%[pixel:p{40,30}]'

Is there a way to output all pixels at once?

Apologies for being so uninformed. I have only dabbled with ImageMagick a little in the past and found it invaluable alongside my automation projects.

Re: Get all pixel RGB values

Posted: 2020-05-20T03:41:35-07:00
by snibgo
For v7, I suggest you use "magick", not "convert" (and not "magick convert").

The txt: format gives you all the pixels:

Code: Select all

magick in.bmp txt:out.txt

Re: Get all pixel RGB values

Posted: 2020-05-20T04:11:34-07:00
by ClumsyNinja
Oh my goodness!! That's incredible, and simple. Thank you.