In ImageMagick, is it possible to -auto-gamma based on a region? -
i'm using imagemagick prepare set of ~20,000 photos timelapse video. mutual problem in timelapse videos flickering, due changing lighting conditions, passing clouds, hue changes, etc.
i've used im convert each image greyscale , -auto-gamma, drastic improvement in lighting "stability". good, not yet perfect. following, can't figure out how.
1. determine ideal auto gamma based on lower 30% of image 2. apply ideal gamma entire image each of images has sky above , buildings below. sky changes dramatically clouds pass by, buildings' lighting stable.
i tried -region, expected, applies gamma part specified. possible i'm hoping for? advice!
yes, think so.
you can crop bottom 30% of image this:
convert image.jpg -gravity south -crop x30%+0+0 bottom.jpg so means can mean of bottom 30% of image this:
convert image.jpg -gravity south -crop x30%+0+0 -format "%[mean]" info: and can quantum range in 1 go if add together in:
convert image.jpg -gravity south -crop x30%+0+0 -format "%[mean] %[fx:quantumrange]" info: now, gamma defined logarithm of mean divided logarithm of midpoint of dynamic range, can normalize both these numbers range [0-1] follows:
log(mean/quantumrange) / log(0.5) so we'll allow bc work out this:
echo "scale=4; l($mean30/$qr)/l(0.5)" | bc -l and can utilize result of apply gamma correction entire image. so, have set in single script, phone call b30gamma. save under name , type:
chmod +x b30gamma to create executable. can run on image , result saved out.jpg not destroy input image:
./b30gamma input.jpg here script:
#!/bin/bash # pick image name parameter image=$1 # mean of bottom 30% of image, , quantum range (65535 q16, or 255 q8) read mean30 qr < <(convert "$image" -gravity south -crop x30%+0+0 -format "%[mean] %[fx:quantumrange]" info:) # gamma = log(mean)/log(dynamic range centre point) gcorr=$(echo "scale=4;l($mean30/$qr)/l(0.5)" | bc -l) # debug echo image: $image, mean: $mean30, quantum range: $qr, gamma: $gcorr # apply gamma entire image convert "$image" -gamma $gcorr out.jpg imagemagick
No comments:
Post a Comment