ImageJ - compare original and resized image on similarity -


dear colleagues. me please next question. want resize huge amount of images , substitute original images resized saving disk space. before substitution want sure, resized image same original image different dimensions (not white list, not malevich's square , on). there way check such similarity sure resizing successful? thanks.

one idea might downscale image tentative down-resed version, scale original size , compare original. if seem pretty similar, overwrite original tentative conversion, if not, report error.

here's how might in bash comments. can rehashed other languages of course, or can use system() shell out , use command line version language.

#!/bin/bash  # downscale image , check if correct # supply image name parameter  original="$1" tentative="t-$$-$original" echo debug: tentative filename=$tentative  # size of original can resize size origsize=$(identify -format "%g" "$original") echo debug: origsize=$origsize  # downsizing of image, saving result tentatively convert image.jpg -resize 800x800 "$tentative"  # test quality/success of conversion looking @ psnr psnr=$(convert "$tentative" -resize $origsize\! "$original" -metric psnr -format "%[distortion]" -compare info:) echo debug: psnr=$psnr  # psnr above 20 pretty indicative of similarity - use "bc" shell doesn't floats if [ $(echo "$psnr>20" | bc) -eq 1 ];    echo $original looks else    echo $original wrong fi 

one thing beware of transparency - don't convert gif or png (both of support transparency) jpeg (which doesn't) , resize , compare - asking trouble. see in script above retain image extension , pre-pend bits front rather end of filename.


Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -