How to get the image brightness?
Posted: 2013-09-06T11:20:40-07:00
Hello,
I'm trying to determine the brightness of an image using the MagickWand programming interface. I managed to get a brightness value on the command line with the following command:
Which MagickWand function should I use to get that value?
I'm not sure if the above method to get the image brightness is good. If anyone knows a better method to get the brightness value, please tell me.
I'm trying to determine the brightness of an image using the MagickWand programming interface. I managed to get a brightness value on the command line with the following command:
I am interested in the brightness value (i.e. 77.1542%), but I don't know how to get this value with the API. I have come this far:$ convert image.jpg -colorspace hsb -resize 1x1 txt:-
# ImageMagick pixel enumeration: 1,1,255,hsb
0,0: ( 55, 33,197) #3721C5 hsb(21.413%,12.9335%,77.1542%)
Code: Select all
/* Use ImageMagick to get the image brightness */
int get_image_brightness(const char *path) {
MagickBooleanType status;
MagickWand *magick_wand;
MagickWandGenesis();
magick_wand = NewMagickWand();
status = MagickReadImage(magick_wand, path);
if (status == MagickFalse)
return -1;
MagickSetColorspace(magick_wand, HSBColorspace);
MagickResizeImage(magick_wand, 1, 1, MitchellFilter, 1);
/* TODO: Get brightness value here */
magick_wand = DestroyMagickWand(magick_wand);
MagickWandTerminus();
return 0;
}
I'm not sure if the above method to get the image brightness is good. If anyone knows a better method to get the brightness value, please tell me.