Page 1 of 1

annotate photo with average brightness

Posted: 2016-07-18T07:38:48-07:00
by prysm1
Hi all

I wrote a script below. It basically splits a photo into a 10x10 image and each components are measured for average brightness and annotated with
the brightness value. the components are then reassembled into a single image. An example output image is shown here https://www.flickr.com/gp/uberclacker/U6BL20

I was wondering if there was a better way to do this. I basically dont feel splitting is the right approach. Maybe there is a way to tell imagemagick to
work only on a certain region of a photo?

regards
prysm


---- start script ----
#!/bin/sh

awklib=/home/fernan/lib/awk
wff="awk -f $awklib/wf.awk"
tmpdir="/tmp"

if test $# -le 0
then
echo "usage: wf [command] [parameters]"
exit 1
fi
if test $1 = "z"
then
convert $2 -crop 10x10@ +repage +adjoin $tmpdir/tile_%02d.tiff
for FILE in $tmpdir/tile_*.tiff
do
d=`convert $FILE -colorspace gray -format %[fx:100*mean] info:`
z=`$wff z $d`
convert $FILE -fill white -undercolor '#00000080' -pointsize 70 -gravity South -annotate +0+5 $z $FILE
done
montage -mode concatenate -tile 10x $tmpdir/tile_*.tiff $3
rm $tmpdir/tile_*.tiff
fi
---- endscript -----

Re: annotate photo with average brightness

Posted: 2016-07-18T09:14:42-07:00
by fmw42
You can get the average brightness of blocks of an image by -scale down getting the pixel values (which are the block averages) via txt:, then -scale up

Re: annotate photo with average brightness

Posted: 2016-07-18T18:54:24-07:00
by snibgo
You don't need to run convert for each image, because you can "-annotate" each of the crops. For example:

Code: Select all

convert wizard: -crop 10x10@ +repage -gravity south -fill lime -pointsize 10 -precision 4 -annotate +0+0 %[fx:mean*100] wiz-%06d.png
If you want the proper grayscale mean, you'll need to use the proper formula.

Sadly, "-annotate" needs the "+repage". If it didn't, you could reassemble the pieces within the same convert command.

I guess that in v7, it can be done somehow in a single command.

Re: annotate photo with average brightness

Posted: 2016-07-20T09:49:10-07:00
by prysm1
thanks snibgo, fmw42

That single convert approach was cool. I will look into it further.
Unfortunately it will not work directly based on how I use the script. I currently annotate the image with a roman numeral based on a range of bightness for example 0 = 0 to 10, I = 11 to 20 etc.

Another thing I tried was using the command below. but it was much slower.
convert image.png -extract 0x0+100+100 -colorspace gray -format %[fx:100*mean] info:
convert image.png -fill white -pointsize 70 -annotate +0+0 ...

Re: annotate photo with average brightness

Posted: 2016-07-20T09:58:13-07:00
by snibgo
prysm1 wrote:I currently annotate the image with a roman numeral based on a range of bightness for example 0 = 0 to 10, I = 11 to 20 etc.
I assume you mean Arabic numeral (0, 1, 2, 3, 4...) not Roman (0, I, II, III, IV, ...

The fx:mean is from 0.0 to 1.0, so %[fx:int(mean*10)] would do that.