How to get RGB values using JMagick?

倖福魔咒の 提交于 2019-12-23 01:53:18

问题


How to get RGB values using JMagick(a wrapper of imagemagick) ?


回答1:


If you want to get the "red" value of a specific image, on the commandline, you could use the following syntax. For the JMagick API, just look up how you'll have to translate this into API calls:

 identify  -format "%[fx:s.p{111,111}.r]"  input.jpg
   0.427451
  • fx: is ImageMagick's special effects image operator that allows you to query all sorts of properties from an image, use them in a mathematical expression and apply them on the image;

  • s. tells ImageMagick to select the current image in the sequence for applying the fx operation;

  • p{111,111}. tells fx to use the pixel at column 111, row 111 for this operation (if you skip the pixel coordinates, fx defaults to p{0,0}, which is the pixel in the top left corner;

  • r queries the red channel of the selected pixel;

  • 0.427451 is the result: it means it is 42.7451% of the maximum value of the channel (255 for 8-bit, 65535 for 16-bit).


 identify  -format "%[fx:s.p{111,111}.z]"  input.jpg
   8
  • z queries the channel depth used for the pixel. Result is 8.

You can also query the Hue, Saturation and Lightness values for a pixel after converting the image to the HSL color system:

identify  -colorspace hsl  -format "%[fx:s.p{111,111}.hue]"  input.jpg 
   0.538012

identify  -colorspace hsl  -format "%[fx:s.p{111,111}.saturation]"  input.jpg 
   0.53271

identify  -colorspace hsl  -format "%[fx:s.p{111,111}.lightness]"  input.jpg 
   0.790196


来源:https://stackoverflow.com/questions/11653914/how-to-get-rgb-values-using-jmagick

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!