PSNR is different for the same images, different formats

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
ritave
Posts: 2
Joined: 2014-07-17T03:05:06-07:00
Authentication code: 6789

PSNR is different for the same images, different formats

Post by ritave »

OS: Windows 8 Enterprise
Magick Version: 6.8.9
Bug: When calculating PSNR between two images, the PSNR differs depending on the format of the files (but the same content).
Steps to reproduce:
Download reference images: http://www.filedropper.com/refimages

Code: Select all

UTIL_DB_compare_.exe -metric PSNR f00140_ref.png f00140_ref.bmp asd.png
1.#INF // Images reported the same

UTIL_DB_compare_.exe -metric PSNR f00140_ref.png f00140.png p.png
29.6955

UTIL_DB_compare_.exe -metric PSNRf00140_ref.bmp f00140.bmp b.png
28.4461 // But the PSNR differs

UTIL_DB_compare_.exe -metric PSNR p.png b.png total.png
1.#INF // And yet the resulting images dont
ritave
Posts: 2
Joined: 2014-07-17T03:05:06-07:00
Authentication code: 6789

Re: PSNR is different for the same images, different formats

Post by ritave »

I got some more debug info:
This is due to the 1 bit alpha channel in png files.
GetMeanSquaredDistortion@compare.c might be calculated wrongly in some way. When I commented out the calculations for alpha channel as well as harcoded

Code: Select all

distortion[CompositeChannels]/=(double) GetNumberChannels(image,channel);
to

Code: Select all

distortion[CompositeChannels]/=(double) 3;
the results are the same in both file formats
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: PSNR is different for the same images, different formats

Post by magick »

We can reproduce the problem you posted and have a patch in ImageMagick 6.8.9-6 Beta, available by sometime tomorrow. Thanks.
jesse1
Posts: 6
Joined: 2014-10-01T08:33:59-07:00
Authentication code: 6789

Re: PSNR is different for the same images, different formats

Post by jesse1 »

Can you please explain what this fix means?
I compared images successfully with 6.8.9.5, but with latest version it returns error "image morphology differs". What should I do about it?

update: I updated not to latest but to 6.8.9.7 since it is last available version via brew for mac osx.
and a full error code is: compare: image morphology differs `<path to image>' @ error/compare.c/CompareImageChannels/173
jesse1
Posts: 6
Joined: 2014-10-01T08:33:59-07:00
Authentication code: 6789

Re: PSNR is different for the same images, different formats

Post by jesse1 »

I found it, it was because of alpha channel which was present in one image but absent in another. After adding option "-alpha Off", it started working again.
Post Reply