Compare images and output the level of difference
Compare images and output the level of difference
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.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Compare images and output the level of difference
Does the compare command work at the command line? Eg
It should give two numbers: an integer and a floating-point. These go to stderr, not stdout, so to put them in a file:
(This is Windows syntax, but I think Unix is the same.)
Or you can do work in a convert command, and compare two images:
(Windows BAT syntax.)
Code: Select all
compare -metric RMSE w.png b.png NULL:
Code: Select all
compare -metric RMSE w.png b.png NULL: 2>diff.txt
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
snibgo's IM pages: im.snibgo.com
Re: Compare images and output the level of difference
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.
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.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Compare images and output the level of difference
"-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:
CHANGED_PC is set to 99.3478
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
snibgo's IM pages: im.snibgo.com
Re: Compare images and output the level of difference
Thank you for reply snibgo,
very elegant; for ghetto people (like me) :]
to use in Windows BAT.
as usually learn a lot, thank you.
m.
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% %%
as usually learn a lot, thank you.
m.