thanks for reading. I’m having performance issues with a script I’ve written that performs an ImageMagick compare.
This is the script:
#!/bin/sh
find */ -name '*.tif' > temp-tif-list.txt
FILE="temp-tif-list.txt"
exec 3<&0
exec 0<$FILE
while read line
do
J2K=`echo "$line" | sed 's/.tif/.jp2/'`
PSNR=`compare -quiet -metric psnr $line $J2K null: 2>&1 | cut -d . -f 1`
VALUE=45
if [ "$PSNR" -le "$VALUE" ]
then
echo "possible problem with $line... compare value is $PSNR" >> visual-check.txt
continue
fi
done
echo "Deleting generated files..."
rm -f temp-tif-list.txt
exec 0<&3
this script is being run against a directory structure that looks something like this:
foo/
foo-1.tif
foo-1.jp2
foo-2.tif
foo-2.jp2
foo2/
foo2-1.tif
foo2-1.jp2
foo2-2.tif
foo2-2.jp2
...
...
etc
Everything goes wrong pretty quickly; once the script starts the compare on foo-1.tif and foo-1.jp2 it seems to hang (CPU jumps to 799%). Any suggestions are greatly appreciated!
Cheers!
EDIT: ImageMagick was getting stuck on TIFFs with multiple pages. Changing the following
PSNR=`compare -quiet -metric psnr $line $J2K null: 2>&1 | cut -d . -f 1`
to
PSNR=`compare -quiet -metric psnr $line[0] $J2K null: 2>&1 | cut -d . -f 1`
seems to be the way towards a slightly more functional script.
Somehow, some of the TIFFs I working with have multiple page images. Until I can determine why that’s happening, the work-around looks something like this:
the
[0]tells ImageMagick to use the first page of the TIFF.