How do I find the brightness (i.e. V in HSV) of the brightest pixel in an image?
I have a large collection of images that will be used as background assets. In order to make sure there are no bright spots that may distract the viewer, I'd like to find all the images whose brightest pixels exceed a certain threshold, so that they can be reworked.
Is there an Imagemagick operation for doing this?
HSV colorspace in IM is called HSB, so you can get a histogram of image.jpg in that way:
You need to reverse sort the output according to the third column (= brightness) and then pick the first line, which can be achieved like this (for the following, I assume Linux as OS):
Next step is to filter the brightness value itself. Let's use
sed
and be aware of an alpha-channel:(this takes the third number out of the hsb- or hsba-parenthesis, which is the percentage value of the brightness of the brightest pixel.)
Taking all this together, we can write a small script
bChecker.sh
like this to examine png- and jpg-files:Called in the directory with your images as
bash bChecker.sh 80
, this script shows all the images whose brightness exceed 80%.