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 -----
annotate photo with average brightness
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: annotate photo with average brightness
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
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: annotate photo with average brightness
You don't need to run convert for each image, because you can "-annotate" each of the crops. For example:
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.
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
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.
snibgo's IM pages: im.snibgo.com
Re: annotate photo with average brightness
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 ...
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 ...
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: annotate photo with average brightness
I assume you mean Arabic numeral (0, 1, 2, 3, 4...) not Roman (0, I, II, III, IV, ...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.
The fx:mean is from 0.0 to 1.0, so %[fx:int(mean*10)] would do that.
snibgo's IM pages: im.snibgo.com