jonrescca wrote:The hint by Anthony gave me excellent results, after little tweaking of the treshold, I could even pick out the images with just some clipped pixels.
A small expansion of the script to make it work with less extra shell wrapping.
Code: Select all
#!/bin/sh
#
# usage: clipping_detector.sh threshold *.tif > clippers.csv
#
ClippingTreshhold="$1"
shift;
sub detect_clipping() {
ImageFile="$1"
LuminosityMean=$( convert "$ImageFile" -channel RGB -threshold 99% -separate -append -format "%[mean]" info:)
ImageFileName=$( basename "$ImageFile" )
ClippingDetected=$( perl -e "if ( $LuminosityMean > $ClippingTreshhold ) { print 1; } else { print 0; }" )
if [ $ClippingDetected -eq 1 ]; then
echo >&2 "$ImageFileName $LuminosityMean"
echo "$ImageFile,$ImageFileName,$LuminosityMean"
else
echo >&2 "$ImageFileName -"
echo "$ImageFile,$ImageFileName,-"
fi
}
for i in "$@"; do
detect_clipping "$i"
done
The output is split into standard output (for CVS, comma separated list, file) and standard error for progress report.
if you want to do recursion use...
find . -name '*.tif' -print 0 | xargs -0 clipping_detector.sh 80 > clippers.cvs
Most importantly I quote filename variables and use -print0 with xargs. this allows it to correct handle files with spaces and other unusual characters.
What I really would like to do is be able to replace the shell function in the above with a single "convert" call that will output the results specified to stdout and stderr. Currently "convert" can output to either or both.. for example...
Code: Select all
convert "$ImageFile" -channel RGB -threshold 99% -separate -append \
-format "%f %[mean]" -write info:fd:2 -format "%d/%f,%f,%[mean]" info:
will write the results to stderr (for progress) and stdout (for result recording).
See Basics: Alternative identify output handling
http://www.imagemagick.org/Usage/basics/#identify_alt
And File Handling, File Descriptor output
http://www.imagemagick.org/Usage/files/#fd
The problem is that at this time IM can not select different strings based on the threshold. It can output a different number (using %[fx:...]) or color string (using %[pixel:]) but it can not output different strings based on either number or string comparison. That is currently it can not handle the 'IF' condition that follows.
Sorry for my rant. This is something that is of major concern to me in IMv7 CLI redevelopment, I am feeling a need for a better form of string macro processing, than simply percent escapes.