Compute the difference between two images but with different dimensions
Compute the difference between two images but with different dimensions
Hi all,
I am trying to compare two similar images but with different dimensions. I have tried using the compare function in IM but it requires both images to be of same dimension.
Is there a way to go around this?
My IM version is 7.0.60. Mac OS Sierra 10.12.6
Thanks.
Aigo
I am trying to compare two similar images but with different dimensions. I have tried using the compare function in IM but it requires both images to be of same dimension.
Is there a way to go around this?
My IM version is 7.0.60. Mac OS Sierra 10.12.6
Thanks.
Aigo

 Posts: 9605
 Joined: 20100123T23:01:3307:00
 Authentication code: 1151
 Location: England, UK
Re: Compute the difference between two images but with different dimensions
What do you want to measure? IM compares corresponding pixels in the two images.
The obvious method would resize one to the size of the other. Or resize them both to the average size of the two images. But perhaps you want to measure something different.
The obvious method would resize one to the size of the other. Or resize them both to the average size of the two images. But perhaps you want to measure something different.
snibgo's IM pages: im.snibgo.com
Re: Compute the difference between two images but with different dimensions
Hi Snibgo,
Thanks for responding so fast. yes, I have done that but I worry that the resizing messes with the pixels in the images further.
I am looking to measure the difference between two images, hoping it will give measurable insight into how good they will look in comparison to the original image.
Also, kindly explain what the two values outputted mean.
Thanks!
Aigo
Thanks for responding so fast. yes, I have done that but I worry that the resizing messes with the pixels in the images further.
I am looking to measure the difference between two images, hoping it will give measurable insight into how good they will look in comparison to the original image.
Also, kindly explain what the two values outputted mean.
Thanks!
Aigo

 Posts: 9605
 Joined: 20100123T23:01:3307:00
 Authentication code: 1151
 Location: England, UK
Re: Compute the difference between two images but with different dimensions
There are many ways of comparing two images. IM works by doing some arithmetic on each pair of pixels (one per image). For example, RMSE is the square root of the mean error (where "error" really means "difference"). So the differences in values from the two pixels are squared, then all added together, then divided by the number of pixels to get the mean, then the square root is taken.
I generally work with RMSE. Some people prefer PSNR.
The first number is on a scale of zero to QuantumRange. For Q16, QuantumRange is 65535. The second number is the same, but on a scale of 0.0 to 1.0. I often multiply the second number by 100 to get a percentage, 4.52665%.
As your images are different sizes, another possibility is to extend one to match the size of the other. But then you have these extra "invented" pixels.
If you can post samples, perhaps we can advise better.
I generally work with RMSE. Some people prefer PSNR.
Code: Select all
f:\web\im>%IM%convert rose: level 0,90% r.png
f:\web\im>%IM%compare metric RMSE rose: r.png NULL:
2966.54 (0.0452665)
As your images are different sizes, another possibility is to extend one to match the size of the other. But then you have these extra "invented" pixels.
If you can post samples, perhaps we can advise better.
snibgo's IM pages: im.snibgo.com
Re: Compute the difference between two images but with different dimensions
You can compare two different size images with histogram comparison metrics. See my bash unix script, histcompare, at my link below.
Re: Compute the difference between two images but with different dimensions
Hi snibgo,snibgo wrote: ↑20170817T08:20:3707:00There are many ways of comparing two images. IM works by doing some arithmetic on each pair of pixels (one per image). For example, RMSE is the square root of the mean error (where "error" really means "difference"). So the differences in values from the two pixels are squared, then all added together, then divided by the number of pixels to get the mean, then the square root is taken.
I generally work with RMSE. Some people prefer PSNR.
The first number is on a scale of zero to QuantumRange. For Q16, QuantumRange is 65535. The second number is the same, but on a scale of 0.0 to 1.0. I often multiply the second number by 100 to get a percentage, 4.52665%.Code: Select all
f:\web\im>%IM%convert rose: level 0,90% r.png f:\web\im>%IM%compare metric RMSE rose: r.png NULL: 2966.54 (0.0452665)
As your images are different sizes, another possibility is to extend one to match the size of the other. But then you have these extra "invented" pixels.
If you can post samples, perhaps we can advise better.
Thanks for your response.
Is it possible to retrieve just the second value?
Thanks!
Aigo.
Re: Compute the difference between two images but with different dimensions
Hi Fred,
Thanks for your response.
With regards to the metrics used in the scripts, which do you recommend will be a better indicator of difference between two images...(a measure of how different they are)?
Thanks!
Aigo.

 Posts: 9605
 Joined: 20100123T23:01:3307:00
 Authentication code: 1151
 Location: England, UK
Re: Compute the difference between two images but with different dimensions
In bash:aigo wrote:Is it possible to retrieve just the second value?
Code: Select all
$ value=`compare metric rmse rose: r.png NULL: 2>&1  sed n 's/^.*[(]\(.*\)[)]$/\1/p'`
$ echo $value
0.0452665
snibgo's IM pages: im.snibgo.com
Re: Compute the difference between two images but with different dimensions
I would try them against a set of test images to determine for your images what might be best. But as a guess, I would suggest correlation or chisquared.