Page 1 of 1

Compute the difference between two images but with different dimensions

Posted: 2017-08-17T07:27:25-07:00
by aigo
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.6-0. Mac OS Sierra 10.12.6

Thanks.

Aigo

Re: Compute the difference between two images but with different dimensions

Posted: 2017-08-17T07:31:00-07:00
by snibgo
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.

Re: Compute the difference between two images but with different dimensions

Posted: 2017-08-17T07:46:22-07:00
by aigo
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

Re: Compute the difference between two images but with different dimensions

Posted: 2017-08-17T08:20:37-07:00
by snibgo
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.

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)
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.

Re: Compute the difference between two images but with different dimensions

Posted: 2017-08-17T09:58:37-07:00
by fmw42
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

Posted: 2017-08-17T13:41:04-07:00
by aigo
snibgo wrote:
2017-08-17T08:20:37-07:00
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.

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)
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.
Hi snibgo,

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

Posted: 2017-08-17T13:43:41-07:00
by aigo
fmw42 wrote:
2017-08-17T09:58:37-07:00
You can compare two different size images with histogram comparison metrics. See my bash unix script, histcompare, at my link below.
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.

Re: Compute the difference between two images but with different dimensions

Posted: 2017-08-17T14:16:08-07:00
by snibgo
aigo wrote:Is it possible to retrieve just the second value?
In bash:

Code: Select all

$ value=`compare -metric rmse rose: r.png NULL: 2>&1 | sed -n 's/^.*[(]\(.*\)[)]$/\1/p'`

$ echo $value
0.0452665
("sed" baffles me, so I guess I got that snippet from Fred.)

Re: Compute the difference between two images but with different dimensions

Posted: 2017-08-17T15:09:41-07:00
by fmw42
aigo wrote:
2017-08-17T13:43:41-07:00
fmw42 wrote:
2017-08-17T09:58:37-07:00
You can compare two different size images with histogram comparison metrics. See my bash unix script, histcompare, at my link below.
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)?
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 chi-squared.