Skip to content

Commit fd35ec5

Browse files
author
Cristy
committed
clip MSE when computing PSNR
1 parent 83a43a9 commit fd35ec5

2 files changed

Lines changed: 26 additions & 25 deletions

File tree

magick/compare.c

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,66 +1443,66 @@ static MagickBooleanType GetPeakSignalToNoiseRatio(const Image *image,
14431443
exception);
14441444
if ((channel & RedChannel) != 0)
14451445
{
1446-
if (fabs(distortion[RedChannel]) >= MagickEpsilon)
1446+
if (distortion[RedChannel] >= MagickEpsilon)
14471447
{
1448-
if (fabs(distortion[RedChannel]-1.0) <= MagickEpsilon)
1448+
if (distortion[RedChannel] >= 1.0)
14491449
distortion[RedChannel]=1.0;
14501450
else
1451-
distortion[RedChannel]=(-10.0*MagickLog10(PerceptibleReciprocal(
1452-
distortion[RedChannel])))/MagickPSNRDistortion;
1451+
distortion[RedChannel]=10.0*MagickLog10(PerceptibleReciprocal(
1452+
distortion[RedChannel]))/MagickPSNRDistortion;
14531453
}
14541454
}
14551455
if ((channel & GreenChannel) != 0)
14561456
{
1457-
if (fabs(distortion[GreenChannel]) >= MagickEpsilon)
1457+
if (distortion[GreenChannel] >= MagickEpsilon)
14581458
{
1459-
if (fabs(distortion[GreenChannel]-1.0) <= MagickEpsilon)
1459+
if (distortion[GreenChannel] >= 1.0)
14601460
distortion[GreenChannel]=1.0;
14611461
else
1462-
distortion[GreenChannel]=(-10.0*MagickLog10(PerceptibleReciprocal(
1463-
distortion[GreenChannel])))/MagickPSNRDistortion;
1462+
distortion[GreenChannel]=10.0*MagickLog10(PerceptibleReciprocal(
1463+
distortion[GreenChannel]))/MagickPSNRDistortion;
14641464
}
14651465
}
14661466
if ((channel & BlueChannel) != 0)
14671467
{
1468-
if (fabs(distortion[BlueChannel]) >= MagickEpsilon)
1468+
if (distortion[BlueChannel] >= MagickEpsilon)
14691469
{
1470-
if (fabs(distortion[BlueChannel]-1.0) <= MagickEpsilon)
1470+
if (distortion[BlueChannel] >= 1.0)
14711471
distortion[BlueChannel]=1.0;
14721472
else
1473-
distortion[BlueChannel]=(-10.0*MagickLog10(PerceptibleReciprocal(
1474-
distortion[BlueChannel])))/MagickPSNRDistortion;
1473+
distortion[BlueChannel]=10.0*MagickLog10(PerceptibleReciprocal(
1474+
distortion[BlueChannel]))/MagickPSNRDistortion;
14751475
}
14761476
}
14771477
if (((channel & OpacityChannel) != 0) && (image->matte != MagickFalse))
14781478
{
1479-
if (fabs(distortion[OpacityChannel]) >= MagickEpsilon)
1479+
if (distortion[OpacityChannel] >= MagickEpsilon)
14801480
{
1481-
if (fabs(distortion[OpacityChannel]-1.0) <= MagickEpsilon)
1481+
if (distortion[OpacityChannel] >= 1.0)
14821482
distortion[OpacityChannel]=1.0;
14831483
else
1484-
distortion[OpacityChannel]=(-10.0*MagickLog10(PerceptibleReciprocal(
1485-
distortion[OpacityChannel])))/MagickPSNRDistortion;
1484+
distortion[OpacityChannel]=10.0*MagickLog10(PerceptibleReciprocal(
1485+
distortion[OpacityChannel]))/MagickPSNRDistortion;
14861486
}
14871487
}
14881488
if (((channel & IndexChannel) != 0) && (image->colorspace == CMYKColorspace))
14891489
{
1490-
if (fabs(distortion[BlackChannel]) >= MagickEpsilon)
1490+
if (distortion[BlackChannel] >= MagickEpsilon)
14911491
{
1492-
if (fabs(distortion[BlackChannel]-1.0) <= MagickEpsilon)
1492+
if (distortion[BlackChannel] >= 1.0)
14931493
distortion[BlackChannel]=1.0;
14941494
else
1495-
distortion[BlackChannel]=(-10.0*MagickLog10(PerceptibleReciprocal(
1496-
distortion[BlackChannel])))/MagickPSNRDistortion;
1495+
distortion[BlackChannel]=10.0*MagickLog10(PerceptibleReciprocal(
1496+
distortion[BlackChannel]))/MagickPSNRDistortion;
14971497
}
14981498
}
1499-
if (fabs(distortion[CompositeChannels]) >= MagickEpsilon)
1499+
if (distortion[CompositeChannels] >= MagickEpsilon)
15001500
{
1501-
if (fabs(distortion[CompositeChannels]-1.0) <= MagickEpsilon)
1501+
if (distortion[CompositeChannels] >= 1.0)
15021502
distortion[CompositeChannels]=1.0;
15031503
else
1504-
distortion[CompositeChannels]=(-10.0*MagickLog10(PerceptibleReciprocal(
1505-
distortion[CompositeChannels])))/MagickPSNRDistortion;
1504+
distortion[CompositeChannels]=10.0*MagickLog10(PerceptibleReciprocal(
1505+
distortion[CompositeChannels]))/MagickPSNRDistortion;
15061506
}
15071507
return(status);
15081508
}

wand/compare.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,8 @@ WandExport MagickBooleanType CompareImageCommand(ImageInfo *image_info,
12971297
case PeakSignalToNoiseRatioMetric:
12981298
{
12991299
(void) FormatLocaleFile(stderr,"%.*g (%.*g)",GetMagickPrecision(),
1300-
MagickPSNRDistortion*distortion,GetMagickPrecision(),distortion);
1300+
MagickPSNRDistortion*distortion,GetMagickPrecision(),
1301+
distortion);
13011302
break;
13021303
}
13031304
case MeanErrorPerPixelMetric:

0 commit comments

Comments
 (0)