]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/compare.c
(no commit message)
[imagemagick] / MagickCore / compare.c
index 0e21c7672a4e6a64a57c9bcb920e1292cfb6d285..50a832b52b939149f2cb5d87738603082e2fa812 100644 (file)
@@ -17,7 +17,7 @@
 %                               December 2003                                 %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
@@ -161,14 +161,11 @@ MagickExport Image *CompareImages(Image *image,const Image *reconstruct_image,
       return((Image *) NULL);
     }
   (void) SetImageAlphaChannel(highlight_image,OpaqueAlphaChannel,exception);
-  (void) QueryColorCompliance("#f1001ecc",AllCompliance,&highlight,
-    exception);
+  (void) QueryColorCompliance("#f1001e33",AllCompliance,&highlight,exception);
   artifact=GetImageArtifact(image,"highlight-color");
   if (artifact != (const char *) NULL)
-    (void) QueryColorCompliance(artifact,AllCompliance,&highlight,
-      exception);
-  (void) QueryColorCompliance("#ffffffcc",AllCompliance,&lowlight,
-    exception);
+    (void) QueryColorCompliance(artifact,AllCompliance,&highlight,exception);
+  (void) QueryColorCompliance("#ffffff33",AllCompliance,&lowlight,exception);
   artifact=GetImageArtifact(image,"lowlight-color");
   if (artifact != (const char *) NULL)
     (void) QueryColorCompliance(artifact,AllCompliance,&lowlight,exception);
@@ -180,7 +177,7 @@ MagickExport Image *CompareImages(Image *image,const Image *reconstruct_image,
   reconstruct_view=AcquireCacheView(reconstruct_image);
   highlight_view=AcquireCacheView(highlight_image);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(dynamic,4) shared(status)
+  #pragma omp parallel for schedule(static,4) shared(status)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -218,6 +215,14 @@ MagickExport Image *CompareImages(Image *image,const Image *reconstruct_image,
       register ssize_t
         i;
 
+      if (GetPixelMask(image,p) != 0)
+        {
+          SetPixelInfoPixel(highlight_image,&lowlight,r);
+          p+=GetPixelChannels(image);
+          q+=GetPixelChannels(reconstruct_image);
+          r+=GetPixelChannels(highlight_image);
+          continue;
+        }
       difference=MagickFalse;
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
@@ -231,23 +236,22 @@ MagickExport Image *CompareImages(Image *image,const Image *reconstruct_image,
           reconstruct_traits,
           traits;
 
-        traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
-        channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
+        channel=GetPixelChannelMapChannel(image,i);
+        traits=GetPixelChannelMapTraits(image,channel);
         reconstruct_traits=GetPixelChannelMapTraits(reconstruct_image,channel);
         if ((traits == UndefinedPixelTrait) ||
-            (reconstruct_traits == UndefinedPixelTrait))
-          continue;
-        if ((reconstruct_traits & UpdatePixelTrait) == 0)
+            (reconstruct_traits == UndefinedPixelTrait) ||
+            ((reconstruct_traits & UpdatePixelTrait) == 0))
           continue;
-        distance=p[i]-(MagickRealType)
-          GetPixelChannel(reconstruct_image,channel,q);
+        distance=p[i]-(MagickRealType) GetPixelChannel(reconstruct_image,
+          channel,q);
         if (fabs((double) distance) >= MagickEpsilon)
           difference=MagickTrue;
       }
       if (difference == MagickFalse)
-        SetPixelPixelInfo(highlight_image,&lowlight,r);
+        SetPixelInfoPixel(highlight_image,&lowlight,r);
       else
-        SetPixelPixelInfo(highlight_image,&highlight,r);
+        SetPixelInfoPixel(highlight_image,&highlight,r);
       p+=GetPixelChannels(image);
       q+=GetPixelChannels(reconstruct_image);
       r+=GetPixelChannels(highlight_image);
@@ -259,8 +263,8 @@ MagickExport Image *CompareImages(Image *image,const Image *reconstruct_image,
   highlight_view=DestroyCacheView(highlight_view);
   reconstruct_view=DestroyCacheView(reconstruct_view);
   image_view=DestroyCacheView(image_view);
-  (void) CompositeImage(difference_image,image->compose,highlight_image,0,0,
-    exception);
+  (void) CompositeImage(difference_image,highlight_image,image->compose,
+    MagickTrue,0,0,exception);
   highlight_image=DestroyImage(highlight_image);
   if (status == MagickFalse)
     difference_image=DestroyImage(difference_image);
@@ -321,7 +325,7 @@ static MagickBooleanType GetAbsoluteDistortion(const Image *image,
   image_view=AcquireCacheView(image);
   reconstruct_view=AcquireCacheView(reconstruct_image);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(dynamic,4) shared(status)
+  #pragma omp parallel for schedule(static,4) shared(status)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -355,6 +359,12 @@ static MagickBooleanType GetAbsoluteDistortion(const Image *image,
       register ssize_t
         i;
 
+      if (GetPixelMask(image,p) != 0)
+        {
+          p+=GetPixelChannels(image);
+          q+=GetPixelChannels(reconstruct_image);
+          continue;
+        }
       difference=MagickFalse;
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
@@ -365,13 +375,12 @@ static MagickBooleanType GetAbsoluteDistortion(const Image *image,
           reconstruct_traits,
           traits;
 
-        traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
-        channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
+        channel=GetPixelChannelMapChannel(image,i);
+        traits=GetPixelChannelMapTraits(image,channel);
         reconstruct_traits=GetPixelChannelMapTraits(reconstruct_image,channel);
         if ((traits == UndefinedPixelTrait) ||
-            (reconstruct_traits == UndefinedPixelTrait))
-          continue;
-        if ((reconstruct_traits & UpdatePixelTrait) == 0)
+            (reconstruct_traits == UndefinedPixelTrait) ||
+            ((reconstruct_traits & UpdatePixelTrait) == 0))
           continue;
         if (p[i] != GetPixelChannel(reconstruct_image,channel,q))
           difference=MagickTrue;
@@ -379,7 +388,7 @@ static MagickBooleanType GetAbsoluteDistortion(const Image *image,
       if (difference != MagickFalse)
         {
           channel_distortion[i]++;
-          channel_distortion[MaxPixelChannels]++;
+          channel_distortion[CompositePixelChannel]++;
         }
       p+=GetPixelChannels(image);
       q+=GetPixelChannels(reconstruct_image);
@@ -406,10 +415,14 @@ static size_t GetImageChannels(const Image *image)
   channels=0;
   for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
   {
+    PixelChannel
+      channel;
+
     PixelTrait
       traits;
 
-    traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
+    channel=GetPixelChannelMapChannel(image,i);
+    traits=GetPixelChannelMapTraits(image,channel);
     if ((traits & UpdatePixelTrait) != 0)
       channels++;
   }
@@ -436,7 +449,7 @@ static MagickBooleanType GetFuzzDistortion(const Image *image,
   image_view=AcquireCacheView(image);
   reconstruct_view=AcquireCacheView(reconstruct_image);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(dynamic,4) shared(status)
+  #pragma omp parallel for schedule(static,4) shared(status)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -467,6 +480,12 @@ static MagickBooleanType GetFuzzDistortion(const Image *image,
       register ssize_t
         i;
 
+      if (GetPixelMask(image,p) != 0)
+        {
+          p+=GetPixelChannels(image);
+          q+=GetPixelChannels(reconstruct_image);
+          continue;
+        }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
         MagickRealType
@@ -479,19 +498,18 @@ static MagickBooleanType GetFuzzDistortion(const Image *image,
           reconstruct_traits,
           traits;
 
-        traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
-        channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
+        channel=GetPixelChannelMapChannel(image,i);
+        traits=GetPixelChannelMapTraits(image,channel);
         reconstruct_traits=GetPixelChannelMapTraits(reconstruct_image,channel);
         if ((traits == UndefinedPixelTrait) ||
-            (reconstruct_traits == UndefinedPixelTrait))
-          continue;
-        if ((reconstruct_traits & UpdatePixelTrait) == 0)
+            (reconstruct_traits == UndefinedPixelTrait) ||
+            ((reconstruct_traits & UpdatePixelTrait) == 0))
           continue;
         distance=QuantumScale*(p[i]-(MagickRealType) GetPixelChannel(
           reconstruct_image,channel,q));
         distance*=distance;
         channel_distortion[i]+=distance;
-        channel_distortion[MaxPixelChannels]+=distance;
+        channel_distortion[CompositePixelChannel]+=distance;
       }
       p+=GetPixelChannels(image);
       q+=GetPixelChannels(reconstruct_image);
@@ -506,8 +524,8 @@ static MagickBooleanType GetFuzzDistortion(const Image *image,
   image_view=DestroyCacheView(image_view);
   for (i=0; i <= MaxPixelChannels; i++)
     distortion[i]/=((double) image->columns*image->rows);
-  distortion[MaxPixelChannels]/=(double) GetImageChannels(image);
-  distortion[MaxPixelChannels]=sqrt(distortion[MaxPixelChannels]);
+  distortion[CompositePixelChannel]/=(double) GetImageChannels(image);
+  distortion[CompositePixelChannel]=sqrt(distortion[CompositePixelChannel]);
   return(status);
 }
 
@@ -531,7 +549,7 @@ static MagickBooleanType GetMeanAbsoluteDistortion(const Image *image,
   image_view=AcquireCacheView(image);
   reconstruct_view=AcquireCacheView(reconstruct_image);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(dynamic,4) shared(status)
+  #pragma omp parallel for schedule(static,4) shared(status)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -562,6 +580,12 @@ static MagickBooleanType GetMeanAbsoluteDistortion(const Image *image,
       register ssize_t
         i;
 
+      if (GetPixelMask(image,p) != 0)
+        {
+          p+=GetPixelChannels(image);
+          q+=GetPixelChannels(reconstruct_image);
+          continue;
+        }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
         MagickRealType
@@ -574,18 +598,17 @@ static MagickBooleanType GetMeanAbsoluteDistortion(const Image *image,
           reconstruct_traits,
           traits;
 
-        traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
-        channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
+        channel=GetPixelChannelMapChannel(image,i);
+        traits=GetPixelChannelMapTraits(image,channel);
         reconstruct_traits=GetPixelChannelMapTraits(reconstruct_image,channel);
         if ((traits == UndefinedPixelTrait) ||
-            (reconstruct_traits == UndefinedPixelTrait))
-          continue;
-        if ((reconstruct_traits & UpdatePixelTrait) == 0)
+            (reconstruct_traits == UndefinedPixelTrait) ||
+            ((reconstruct_traits & UpdatePixelTrait) == 0))
           continue;
         distance=QuantumScale*fabs(p[i]-(MagickRealType) GetPixelChannel(
           reconstruct_image,channel,q));
         channel_distortion[i]+=distance;
-        channel_distortion[MaxPixelChannels]+=distance;
+        channel_distortion[CompositePixelChannel]+=distance;
       }
       p+=GetPixelChannels(image);
       q+=GetPixelChannels(reconstruct_image);
@@ -600,7 +623,7 @@ static MagickBooleanType GetMeanAbsoluteDistortion(const Image *image,
   image_view=DestroyCacheView(image_view);
   for (i=0; i <= MaxPixelChannels; i++)
     distortion[i]/=((double) image->columns*image->rows);
-  distortion[MaxPixelChannels]/=(double) GetImageChannels(image);
+  distortion[CompositePixelChannel]/=(double) GetImageChannels(image);
   return(status);
 }
 
@@ -654,6 +677,12 @@ static MagickBooleanType GetMeanErrorPerPixel(Image *image,
       register ssize_t
         i;
 
+      if (GetPixelMask(image,p) != 0)
+        {
+          p+=GetPixelChannels(image);
+          q+=GetPixelChannels(reconstruct_image);
+          continue;
+        }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
         MagickRealType
@@ -666,18 +695,17 @@ static MagickBooleanType GetMeanErrorPerPixel(Image *image,
           reconstruct_traits,
           traits;
 
-        traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
-        channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
+        channel=GetPixelChannelMapChannel(image,i);
+        traits=GetPixelChannelMapTraits(image,channel);
         reconstruct_traits=GetPixelChannelMapTraits(reconstruct_image,channel);
         if ((traits == UndefinedPixelTrait) ||
-            (reconstruct_traits == UndefinedPixelTrait))
-          continue;
-        if ((reconstruct_traits & UpdatePixelTrait) == 0)
+            (reconstruct_traits == UndefinedPixelTrait) ||
+            ((reconstruct_traits & UpdatePixelTrait) == 0))
           continue;
         distance=fabs((double) (alpha*p[i]-beta*GetPixelChannel(
           reconstruct_image,channel,q)));
         distortion[i]+=distance;
-        distortion[MaxPixelChannels]+=distance;
+        distortion[CompositePixelChannel]+=distance;
         mean_error+=distance*distance;
         if (distance > maximum_error)
           maximum_error=distance;
@@ -689,7 +717,7 @@ static MagickBooleanType GetMeanErrorPerPixel(Image *image,
   }
   reconstruct_view=DestroyCacheView(reconstruct_view);
   image_view=DestroyCacheView(image_view);
-  image->error.mean_error_per_pixel=distortion[MaxPixelChannels]/area;
+  image->error.mean_error_per_pixel=distortion[CompositePixelChannel]/area;
   image->error.normalized_mean_error=QuantumScale*QuantumScale*mean_error/area;
   image->error.normalized_maximum_error=QuantumScale*maximum_error;
   return(status);
@@ -715,7 +743,7 @@ static MagickBooleanType GetMeanSquaredDistortion(const Image *image,
   image_view=AcquireCacheView(image);
   reconstruct_view=AcquireCacheView(reconstruct_image);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(dynamic,4) shared(status)
+  #pragma omp parallel for schedule(static,4) shared(status)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -746,6 +774,12 @@ static MagickBooleanType GetMeanSquaredDistortion(const Image *image,
       register ssize_t
         i;
 
+      if (GetPixelMask(image,p) != 0)
+        {
+          p+=GetPixelChannels(image);
+          q+=GetPixelChannels(reconstruct_image);
+          continue;
+        }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
         MagickRealType
@@ -758,19 +792,18 @@ static MagickBooleanType GetMeanSquaredDistortion(const Image *image,
           reconstruct_traits,
           traits;
 
-        traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
-        channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
+        channel=GetPixelChannelMapChannel(image,i);
+        traits=GetPixelChannelMapTraits(image,channel);
         reconstruct_traits=GetPixelChannelMapTraits(reconstruct_image,channel);
         if ((traits == UndefinedPixelTrait) ||
-            (reconstruct_traits == UndefinedPixelTrait))
-          continue;
-        if ((reconstruct_traits & UpdatePixelTrait) == 0)
+            (reconstruct_traits == UndefinedPixelTrait) ||
+            ((reconstruct_traits & UpdatePixelTrait) == 0))
           continue;
         distance=QuantumScale*(p[i]-(MagickRealType) GetPixelChannel(
           reconstruct_image,channel,q));
         distance*=distance;
         channel_distortion[i]+=distance;
-        channel_distortion[MaxPixelChannels]+=distance;
+        channel_distortion[CompositePixelChannel]+=distance;
       }
       p+=GetPixelChannels(image);
       q+=GetPixelChannels(reconstruct_image);
@@ -785,7 +818,7 @@ static MagickBooleanType GetMeanSquaredDistortion(const Image *image,
   image_view=DestroyCacheView(image_view);
   for (i=0; i <= MaxPixelChannels; i++)
     distortion[i]/=((double) image->columns*image->rows);
-  distortion[MaxPixelChannels]/=GetImageChannels(image);
+  distortion[CompositePixelChannel]/=GetImageChannels(image);
   return(status);
 }
 
@@ -854,6 +887,12 @@ static MagickBooleanType GetNormalizedCrossCorrelationDistortion(
       register ssize_t
         i;
 
+      if (GetPixelMask(image,p) != 0)
+        {
+          p+=GetPixelChannels(image);
+          q+=GetPixelChannels(reconstruct_image);
+          continue;
+        }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
         PixelChannel
@@ -863,20 +902,19 @@ static MagickBooleanType GetNormalizedCrossCorrelationDistortion(
           reconstruct_traits,
           traits;
 
-        traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
-        channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
+        channel=GetPixelChannelMapChannel(image,i);
+        traits=GetPixelChannelMapTraits(image,channel);
         reconstruct_traits=GetPixelChannelMapTraits(reconstruct_image,channel);
         if ((traits == UndefinedPixelTrait) ||
-            (reconstruct_traits == UndefinedPixelTrait))
-          continue;
-        if ((reconstruct_traits & UpdatePixelTrait) == 0)
+            (reconstruct_traits == UndefinedPixelTrait) ||
+            ((reconstruct_traits & UpdatePixelTrait) == 0))
           continue;
         distortion[i]+=area*QuantumScale*(p[i]-image_statistics[i].mean)*
           (GetPixelChannel(reconstruct_image,channel,q)-
           reconstruct_statistics[channel].mean);
       }
       p+=GetPixelChannels(image);
-      q+=GetPixelChannels(image);
+      q+=GetPixelChannels(reconstruct_image);
     }
     if (image->progress_monitor != (MagickProgressMonitor) NULL)
       {
@@ -894,7 +932,7 @@ static MagickBooleanType GetNormalizedCrossCorrelationDistortion(
   /*
     Divide by the standard deviation.
   */
-  distortion[MaxPixelChannels]=0.0;
+  distortion[CompositePixelChannel]=0.0;
   for (i=0; i < MaxPixelChannels; i++)
   {
     MagickRealType
@@ -903,14 +941,14 @@ static MagickBooleanType GetNormalizedCrossCorrelationDistortion(
     PixelChannel
       channel;
 
-    channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
+    channel=GetPixelChannelMapChannel(image,i);
     gamma=image_statistics[i].standard_deviation*
       reconstruct_statistics[channel].standard_deviation;
     gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
     distortion[i]=QuantumRange*gamma*distortion[i];
-    distortion[MaxPixelChannels]+=distortion[i]*distortion[i];
+    distortion[CompositePixelChannel]+=distortion[i]*distortion[i];
   }
-  distortion[MaxPixelChannels]=sqrt(distortion[MaxPixelChannels]/
+  distortion[CompositePixelChannel]=sqrt(distortion[CompositePixelChannel]/
     GetImageChannels(image));
   /*
     Free resources.
@@ -939,7 +977,7 @@ static MagickBooleanType GetPeakAbsoluteDistortion(const Image *image,
   image_view=AcquireCacheView(image);
   reconstruct_view=AcquireCacheView(reconstruct_image);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(dynamic,4) shared(status)
+  #pragma omp parallel for schedule(static,4) shared(status)
 #endif
   for (y=0; y < (ssize_t) image->rows; y++)
   {
@@ -957,8 +995,8 @@ static MagickBooleanType GetPeakAbsoluteDistortion(const Image *image,
     if (status == MagickFalse)
       continue;
     p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
-    q=GetCacheViewVirtualPixels(reconstruct_view,0,y,
-      reconstruct_image->columns,1,exception);
+    q=GetCacheViewVirtualPixels(reconstruct_view,0,y,reconstruct_image->columns,
+      1,exception);
     if ((p == (const Quantum *) NULL) || (q == (const Quantum *) NULL))
       {
         status=MagickFalse;
@@ -970,6 +1008,12 @@ static MagickBooleanType GetPeakAbsoluteDistortion(const Image *image,
       register ssize_t
         i;
 
+      if (GetPixelMask(image,p) != 0)
+        {
+          p+=GetPixelChannels(image);
+          q+=GetPixelChannels(reconstruct_image);
+          continue;
+        }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
         MagickRealType
@@ -982,23 +1026,22 @@ static MagickBooleanType GetPeakAbsoluteDistortion(const Image *image,
           reconstruct_traits,
           traits;
 
-        traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
-        channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
+        channel=GetPixelChannelMapChannel(image,i);
+        traits=GetPixelChannelMapTraits(image,channel);
         reconstruct_traits=GetPixelChannelMapTraits(reconstruct_image,channel);
         if ((traits == UndefinedPixelTrait) ||
-            (reconstruct_traits == UndefinedPixelTrait))
-          continue;
-        if ((reconstruct_traits & UpdatePixelTrait) == 0)
+            (reconstruct_traits == UndefinedPixelTrait) ||
+            ((reconstruct_traits & UpdatePixelTrait) == 0))
           continue;
         distance=QuantumScale*fabs(p[i]-(MagickRealType) GetPixelChannel(
           reconstruct_image,channel,q));
         if (distance > channel_distortion[i])
           channel_distortion[i]=distance;
-        if (distance > channel_distortion[MaxPixelChannels])
-          channel_distortion[MaxPixelChannels]=distance;
+        if (distance > channel_distortion[CompositePixelChannel])
+          channel_distortion[CompositePixelChannel]=distance;
       }
       p+=GetPixelChannels(image);
-      q+=GetPixelChannels(image);
+      q+=GetPixelChannels(reconstruct_image);
     }
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp critical (MagickCore_GetPeakAbsoluteError)
@@ -1136,7 +1179,7 @@ MagickExport MagickBooleanType GetImageDistortion(Image *image,
       break;
     }
   }
-  *distortion=channel_distortion[MaxPixelChannels];
+  *distortion=channel_distortion[CompositePixelChannel];
   channel_distortion=(double *) RelinquishMagickMemory(channel_distortion);
   return(status);
 }
@@ -1378,6 +1421,12 @@ MagickExport MagickBooleanType IsImagesEqual(Image *image,
       register ssize_t
         i;
 
+      if (GetPixelMask(image,p) != 0)
+        {
+          p+=GetPixelChannels(image);
+          q+=GetPixelChannels(reconstruct_image);
+          continue;
+        }
       for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
       {
         MagickRealType
@@ -1390,13 +1439,12 @@ MagickExport MagickBooleanType IsImagesEqual(Image *image,
           reconstruct_traits,
           traits;
 
-        traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
-        channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
+        channel=GetPixelChannelMapChannel(image,i);
+        traits=GetPixelChannelMapTraits(image,channel);
         reconstruct_traits=GetPixelChannelMapTraits(reconstruct_image,channel);
         if ((traits == UndefinedPixelTrait) ||
-            (reconstruct_traits == UndefinedPixelTrait))
-          continue;
-        if ((reconstruct_traits & UpdatePixelTrait) == 0)
+            (reconstruct_traits == UndefinedPixelTrait) ||
+            ((reconstruct_traits & UpdatePixelTrait) == 0))
           continue;
         distance=fabs(p[i]-(MagickRealType) GetPixelChannel(reconstruct_image,
           channel,q));
@@ -1538,7 +1586,7 @@ MagickExport Image *SimilarityImage(Image *image,const Image *reference,
   progress=0;
   similarity_view=AcquireCacheView(similarity_image);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
+  #pragma omp parallel for schedule(static,4) shared(progress,status)
 #endif
   for (y=0; y < (ssize_t) (image->rows-reference->rows+1); y++)
   {
@@ -1575,7 +1623,12 @@ MagickExport Image *SimilarityImage(Image *image,const Image *reference,
           offset->x=x;
           offset->y=y;
         }
-      for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
+      if (GetPixelMask(similarity_image,q) != 0)
+        {
+          q+=GetPixelChannels(similarity_image);
+          continue;
+        }
+      for (i=0; i < (ssize_t) GetPixelChannels(similarity_image); i++)
       {
         PixelChannel
           channel;
@@ -1584,13 +1637,12 @@ MagickExport Image *SimilarityImage(Image *image,const Image *reference,
           similarity_traits,
           traits;
 
-        traits=GetPixelChannelMapTraits(image,(PixelChannel) i);
-        channel=GetPixelChannelMapChannel(image,(PixelChannel) i);
+        channel=GetPixelChannelMapChannel(image,i);
+        traits=GetPixelChannelMapTraits(image,channel);
         similarity_traits=GetPixelChannelMapTraits(similarity_image,channel);
         if ((traits == UndefinedPixelTrait) ||
-            (similarity_traits == UndefinedPixelTrait))
-          continue;
-        if ((similarity_traits & UpdatePixelTrait) == 0)
+            (similarity_traits == UndefinedPixelTrait) ||
+            ((similarity_traits & UpdatePixelTrait) == 0))
           continue;
         SetPixelChannel(similarity_image,channel,ClampToQuantum(QuantumRange-
           QuantumRange*similarity),q);