Get Pixel RGB Value

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
billbell52

Get Pixel RGB Value

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Get Pixel RGB Value

Post 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
Post Reply