Page 1 of 1
finding the RGB value of a pixel
Posted: 2009-05-05T14:21:25-07:00
by drewvy
Is there a way to ask for the RGB values of a pixel at location X, Y?
Re: finding the RGB value of a pixel
Posted: 2009-05-05T14:30:02-07:00
by magick
Is there a way to ask for the RGB values of a pixel at location X, Y?
What are you using? The command-line, PerlMagick, MagickCore, MagickWand, Magick++, iMagick? The answer depends on your interface to ImageMagick.
Re: finding the RGB value of a pixel
Posted: 2009-05-05T14:31:17-07:00
by drewvy
The command line.
Re: finding the RGB value of a pixel
Posted: 2009-05-05T16:50:53-07:00
by fmw42
convert rose.png[1x1+10+10] txt:
# ImageMagick pixel enumeration: 1,1,65535,rgb
0,0: (18504,16448,14649) #484840403939 rgb(72,64,57)
or
convert rose.png[1x1+10+10] -format "%[fx:int(255*r)],%[fx:int(255*g)],%[fx:int(255*b)]" info:
72,64,57
Re: finding the RGB value of a pixel
Posted: 2009-05-05T17:00:06-07:00
by drewvy
I don't understand this [1x1+10+10]
What does this mean?
Re: finding the RGB value of a pixel
Posted: 2009-05-05T17:06:52-07:00
by fmw42
It is a subsection of the image that is 1x1 pixel at offset x=10 and y=10 from the upper left corner.
see
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/files/#read_mods
you can also do it this way:
convert rose.png -format "%[fx:int(255*p{10,10}.r)],%[fx:int(255*p{10,10}.g)],%[fx:int(255*p{10,10}.b)]" info:
72,64,57
see
http://www.imagemagick.org/script/fx.php
http://www.imagemagick.org/Usage/transform/#fx_escapes
If you are on Windows, see
http://www.imagemagick.org/Usage/windows/
Re: finding the RGB value of a pixel
Posted: 2009-05-05T20:44:33-07:00
by anthony
drewvy wrote:I don't understand this [1x1+10+10]
Its a crop done immediateally after reading, before the image is added to the current image sequence in memory.
Equivelent to
Code: Select all
convert rose.png -crop 1x1+10+10 txt:-
just faster.
NOTE you may have to quote the square brackets as it is a 'shell meta-charcater'
so the original command should have been...
Code: Select all
convert rose.png'[1x1+10+10]' txt:-
Another alternative is
Code: Select all
convert rose.png -format "%[pixel:p{10,10}]" info:
Though that may produce a color name, instead of the pixels RGB values. For a 16 bit image it may also use percent values in the RGB value it returns. Fred's more complex method gurantees the return of a the 8bit RGB values.
For more methdos and information see
IM Examples, Color Quantization and Dithering, Extracting Colors
http://www.imagemagick.org/Usage/quantize/#extract