imagemagick - How to find the brightest pixel? -
how find brightness (i.e. v in hsv) of brightest pixel in image?
i have large collection of images used background assets. in order make sure there no bright spots may distract viewer, i'd find images brightest pixels exceed threshold, can reworked.
is there imagemagick operation doing this?
hsv colorspace in im called hsb, can histogram of image.jpg in way:
convert image.jpg -colorspace hsb -format %c histogram:info:-
you need reverse sort output according third column (= brightness) , pick first line, can achieved (for following, assume linux os):
convert image.jpg -colorspace hsb -format %c histogram:info:- \ | sort -t',' -gr -k 3 | head -1
next step filter brightness value itself. let's use sed
, aware of alpha-channel:
sed 's/.* hsb.*,.*,\([0-9.]*\)%.*/\1/'
(this takes third number out of hsb- or hsba-parenthesis, percentage value of brightness of brightest pixel.)
taking together, can write small script bchecker.sh
examine png- , jpg-files:
#/bin/bash threshold=${1-75} echo checking threshold $threshold% find . -name "*.png" -o -name "*.jpg" | while read pic; val=$(convert "$pic" -colorspace hsb -format %c histogram:info:- | \ sort -t',' -gr -k 3 | head -1 | \ sed 's/.* hsb.*,.*,\([0-9.]*\)%.*/\1/') (( $(echo "$threshold < $val" | bc) )) && echo "$pic: brightness exceeds threshold ($val%)" done
called in directory images bash bchecker.sh 80
, script shows images brightness exceed 80%.
Comments
Post a Comment