Get Pixel RGB Value
Get Pixel RGB Value
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Get Pixel RGB Value
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
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