Skip to content

Commit 8e1ac68

Browse files
author
Cristy
committed
fix PSNR metric to return the correct DB
1 parent c1095aa commit 8e1ac68

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

magick/compare.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -1430,31 +1430,31 @@ static MagickBooleanType GetPeakSignalToNoiseRatio(const Image *image,
14301430
if ((channel & RedChannel) != 0)
14311431
{
14321432
if (fabs(distortion[RedChannel]) >= MagickEpsilon)
1433-
distortion[RedChannel]=(-10.0*MagickLog10(distortion[RedChannel]))/
1433+
distortion[RedChannel]=(10.0*MagickLog10(distortion[RedChannel]))/
14341434
48.1647;
14351435
}
14361436
if ((channel & GreenChannel) != 0)
14371437
{
14381438
if (fabs(distortion[GreenChannel]) >= MagickEpsilon)
1439-
distortion[GreenChannel]=(-10.0*MagickLog10(distortion[GreenChannel]))/
1439+
distortion[GreenChannel]=(10.0*MagickLog10(distortion[GreenChannel]))/
14401440
48.1647;
14411441
}
14421442
if ((channel & BlueChannel) != 0)
14431443
{
14441444
if (fabs(distortion[BlueChannel]) >= MagickEpsilon)
1445-
distortion[BlueChannel]=(-10.0*MagickLog10(distortion[BlueChannel]))/
1445+
distortion[BlueChannel]=(10.0*MagickLog10(distortion[BlueChannel]))/
14461446
48.1647;
14471447
}
14481448
if (((channel & OpacityChannel) != 0) && (image->matte != MagickFalse))
14491449
{
14501450
if (fabs(distortion[OpacityChannel]) >= MagickEpsilon)
1451-
distortion[OpacityChannel]=(-10.0*
1451+
distortion[OpacityChannel]=(10.0*
14521452
MagickLog10(distortion[OpacityChannel]))/48.1647;
14531453
}
14541454
if (((channel & IndexChannel) != 0) && (image->colorspace == CMYKColorspace))
14551455
{
14561456
if (fabs(distortion[BlackChannel]) >= MagickEpsilon)
1457-
distortion[BlackChannel]=(-10.0*MagickLog10(distortion[BlackChannel]))/
1457+
distortion[BlackChannel]=(10.0*MagickLog10(distortion[BlackChannel]))/
14581458
48.1647;
14591459
}
14601460
distortion[CompositeChannels]=0.0;

wand/compare.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -1227,11 +1227,21 @@ WandExport MagickBooleanType CompareImageCommand(ImageInfo *image_info,
12271227
}
12281228
if (fabs(distortion) > CompareEpsilon)
12291229
similar=MagickFalse;
1230-
if (metric == NormalizedCrossCorrelationErrorMetric)
1230+
switch (metric)
1231+
{
1232+
case NormalizedCrossCorrelationErrorMetric:
12311233
{
12321234
distortion=1.0-distortion;
12331235
similarity_metric=1.0-similarity_metric;
12341236
}
1237+
case PeakSignalToNoiseRatioMetric:
1238+
{
1239+
distortion=fabs(distortion);
1240+
similarity_metric+=1.0;
1241+
}
1242+
default:
1243+
break;
1244+
}
12351245
if (difference_image == (Image *) NULL)
12361246
status=0;
12371247
else

0 commit comments

Comments
 (0)