Page 1 of 1

Get Pixel RGB Value

Posted: 2010-09-16T07:38:40-07:00
by billbell52
I cannot find the correct syntax to get the RGB value of a specific pixel. I looked through the docs and forum. I am sure it is easy but it eludes me. Thanks.

Re: Get Pixel RGB Value

Posted: 2010-09-16T10:01:08-07:00
by fmw42
There are a number of ways:

1) convert rose:[1x1+10+10] txt:-
# ImageMagick pixel enumeration: 1,1,255,rgb
0,0: ( 72, 64, 57) #484039 rgb(72,64,57)

or

convert rose:[1x1+10+10] txt:- | tail -n +2 | sed -n 's/^.*\(rgb.*\)$/\1/p'
rgb(72,64,57)


2) convert rose: -format "%[pixel:s.p{10,10}]" info:
rgb(72,64,57)


But sometimes with the above you will get colornames instead

3) convert rose:[1x1+10+10] -format "rgb(%[fx:round(255*u.r)],%[fx:round(255*u.g)],%[fx:round(255*u.b)])" info:
rgb(72,64,57)


see

http://www.imagemagick.org/Usage/files/#txt
http://www.imagemagick.org/Usage/transform/#fx_escapes
http://www.imagemagick.org/script/fx.php