The result of a 'compare -metric PSNR' for identical images has changed between
6.9.3 and 6.9.5 (I dont have a 6.9.4 to test). This problem is also in the
7 series. Instead of the result being 'inf' it has now become '0'. Is this a bug or done on purpose???
> compare --version
Version: ImageMagick 6.9.3-4 Q16 amd64 2016-03-15 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules
Delegates (built-in): bzlib cairo fftw fontconfig freetype fpx jbig jng jp2 jpeg lcms lqr ltdl png rsvg tiff webp wmf x xml zlib
> convert -size 100x100 xc:white canvaswhite.jpg
> compare -metric PSNR canvaswhite.jpg canvaswhite.jpg /dev/null
inf
-----
> compare --version
Version: ImageMagick 6.9.5-10 Q16 amd64 2016-11-01 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules
Delegates (built-in): bzlib cairo fftw fontconfig fpx freetype jbig jng jp2 jpeg lcms lqr ltdl lzma png rsvg tiff webp wmf x xml zlib
> convert -size 100x100 xc:white canvaswhite.jpg
> compare -metric PSNR canvaswhite.jpg canvaswhite.jpg /dev/null
0
-----
> compare --version
Version: ImageMagick 7.0.2-9 Q16 amd64 2017-02-26 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules
Delegates (built-in): bzlib cairo fftw fontconfig fpx freetype jbig jng jp2 jpeg lcms lqr ltdl lzma png rsvg tiff webp wmf x xml zlib
> convert -size 100x100 xc:white canvaswhite.jpg
> compare -metric PSNR canvaswhite.jpg canvaswhite.jpg /dev/null
0
PSNR no longer returns inf
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: PSNR no longer returns inf
It seems to have changed for me between 6.9.5.3 (inf) and 6.9.5.4 (0)
Possibly related to this entry in the changelog:
Possibly related to this entry in the changelog:
2016-07-35 6.9.5-4 Cristy <quetzlzacatenango@image...>
Prevent buffer overflow (bug report from Ibrahim el-sayed).
Re: PSNR no longer returns inf
We corrected for a possible divide by zero:
If distortion[channel] is zero, we no longer divide by zero and instead return zero. If our analysis / patch is incorrect, let us know.
Code: Select all
distortion[RedChannel]=20.0*MagickLog10((double) 1.0/sqrt(distortion[RedChannel]));
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: PSNR no longer returns inf
From http://www.imagemagick.org/Usage/compare/#statistics
Since the mean squared difference is zero and the maximum mean squared difference is not 0, then the ratio is 0 and the log(0) is inf. So properly this metric should be returning inf.PSNR .... Peak Signal to noise ratio (used in image compression papers)
The ratio of mean square difference to the maximum mean square
that can exist between any two images, expressed as a decibel
value.
The higher the PSNR the closer the closer the images are, with
a maximum difference occurring at 1. A PSNR of 20 means
differences are 1/100 of maximum
Re: PSNR no longer returns inf
If we use an infinitesimal small value instead of 0, it returns 300 rather than inf. This avoids the divide by zero and returns a maximal PSNR. We can't properly perform a divide by zero so the alternatively we could check for 0 and if found return inf otherwise return 20.0*MagickLog10(1/sqrt(distortion[channel])). What's your preference?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: PSNR no longer returns inf
alternatively we could check for 0 and if found return inf
Re: PSNR no longer returns inf
Thanks for the problem report. We can reproduce it and will have a patch to fix it in GIT master branch @ https://github.com/ImageMagick/ImageMagick later today. The patch will be available in the beta releases of ImageMagick @ http://www.imagemagick.org/download/beta/ by sometime tomorrow.