(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Wed, 8 Jan 2014 23:15:49 +0000 (23:15 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Wed, 8 Jan 2014 23:15:49 +0000 (23:15 +0000)
MagickCore/compare.c
MagickWand/compare.c

index 36f49e0aad105ad725bed629e4a627ad5e395a2e..0e3ab7a97ba257559d94030a78e508a8caff8133 100644 (file)
@@ -1104,7 +1104,43 @@ static MagickBooleanType GetPeakSignalToNoiseRatio(const Image *image,
 static MagickBooleanType GetPerceptualHashDistortion(const Image *image,
   const Image *reconstruct_image,double *distortion,ExceptionInfo *exception)
 {
+  ChannelMoments
+    *image_moments,
+    *reconstruct_moments;
+
+  double
+    difference,
+    sum;
+
+  register ssize_t
+    i;
+
   *distortion=0.0;
+  image_moments=GetImageMoments(image,exception);
+  if (image_moments == (ChannelMoments *) NULL)
+    return(MagickFalse);
+  reconstruct_moments=GetImageMoments(reconstruct_image,exception);
+  if (reconstruct_moments == (ChannelMoments *) NULL)
+    {
+      image_moments=(ChannelMoments *) RelinquishMagickMemory(image_moments);
+      return(MagickFalse);
+    }
+  sum=0.0;
+  for (i=0; i < 8; i++)
+  {
+    ssize_t
+      channel;
+
+    for (channel=0; channel < MaxPixelChannels; channel++)
+    {
+      difference=reconstruct_moments[channel].I[i]-image_moments[channel].I[i];
+      sum+=difference*difference;
+    }
+  }
+  *distortion=sum;
+  reconstruct_moments=(ChannelMoments *) RelinquishMagickMemory(
+    reconstruct_moments);
+  image_moments=(ChannelMoments *) RelinquishMagickMemory(image_moments);
   return(MagickTrue);
 }
 
index 74cefc0683f3463d66e390867e29a36f34c60fd1..7b9e4bb4d97afb1669532ce6f9e428e6e91a823f 100644 (file)
@@ -1026,8 +1026,9 @@ WandExport MagickBooleanType CompareImagesCommand(ImageInfo *image_info,
             case FuzzErrorMetric:
             case MeanAbsoluteErrorMetric:
             case MeanSquaredErrorMetric:
-            case RootMeanSquaredErrorMetric:
             case PeakAbsoluteErrorMetric:
+            case PerceptualHashErrorMetric:
+            case RootMeanSquaredErrorMetric:
             {
               (void) FormatLocaleFile(stderr,"%g (%g)",QuantumRange*distortion,
                 (double) distortion);
@@ -1082,8 +1083,9 @@ WandExport MagickBooleanType CompareImagesCommand(ImageInfo *image_info,
             case FuzzErrorMetric:
             case MeanAbsoluteErrorMetric:
             case MeanSquaredErrorMetric:
-            case RootMeanSquaredErrorMetric:
             case PeakAbsoluteErrorMetric:
+            case PerceptualHashErrorMetric:
+            case RootMeanSquaredErrorMetric:
             {
               switch (image->colorspace)
               {