Page 1 of 1
Compare images and output the level of difference
Posted: 2014-03-23T02:00:47-07:00
by Elapido
I use normalize to correct levels in images. Then, I'd like to compare the original image with the processed image and have a numerical string in a text file that shows how different both images are, so as to know if the correction was strong or subtle. I've been trying with the compare command and -dissimilarity-threshold but I can't get any results. Any help? Thanx.
Re: Compare images and output the level of difference
Posted: 2014-03-23T10:07:46-07:00
by snibgo
Does the compare command work at the command line? Eg
Code: Select all
compare -metric RMSE w.png b.png NULL:
It should give two numbers: an integer and a floating-point. These go to stderr, not stdout, so to put them in a file:
Code: Select all
compare -metric RMSE w.png b.png NULL: 2>diff.txt
(This is Windows syntax, but I think Unix is the same.)
Or you can do work in a convert command, and compare two images:
Code: Select all
convert w.png ( +clone -normalize ) -metric RMSE -format "%%[distortion]" -compare info: >x.txt
(Windows BAT syntax.)
Re: Compare images and output the level of difference
Posted: 2014-03-31T23:46:31-07:00
by myspacee
Hello,
append a request. Is there any way to obtain differences expressed as a percentage ?
See that is asked before, but not find code to run.
If IM returns changed 'pixel', I can count image 'pixel' and use proportion to obtain %, eg:
changed = 13239
image resolution (800x600) = 480000
100:x=480000:13239
Is correct? can help with code?
thank you,
m.
Re: Compare images and output the level of difference
Posted: 2014-04-01T05:34:12-07:00
by snibgo
"-metric AE" gives the number of pixels that have changed. To get this as a percentage, you need to calculate in a script. (Because %[distortion] can't be used in fx.) This depends on your language. For example, in Windows BAT:
Code: Select all
for /F "usebackq" %%L in (`%IM%convert ^
rose: ^
^( +clone -normalize ^) ^
-metric AE ^
-format "AREA=%%[fx:w*h]\nCHANGED=%%[distortion]" ^
-compare info:`) ^
do set %%L
for /F "usebackq" %%L in (`%IM%identify ^
-format "CHANGED_PC=%%[fx:100*%CHANGED%/%AREA%]"
xc:`) ^
do set %%L
CHANGED_PC is set to 99.3478
Re: Compare images and output the level of difference
Posted: 2014-04-02T04:50:34-07:00
by myspacee
Thank you for reply snibgo,
very elegant; for ghetto people (like me) :]
Code: Select all
@echo off
echo -------------------------------
echo find diff
echo -------------------------------
compare -metric AE -fuzz 5% 1.png 2.png compare_fuzz.gif 2>diff.txt
set /P diff=<diff.txt
echo -------------------------------
echo pixel count for first image
echo -------------------------------
cconvert 1.png -format "%%[fx:w*h]" info: >pixelcount.txt
set /P pixelcount=<pixelcount.txt
set /A percentage=100-((%diff%*100)/%pixelcount%)
echo resolution : %pixelcount%
echo differences : %diff%
echo similar to : %percentage% %%
to use in Windows BAT.
as usually learn a lot, thank you.
m.