]> granicus.if.org Git - imagemagick/commitdiff
(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Tue, 26 Jan 2010 20:31:51 +0000 (20:31 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Tue, 26 Jan 2010 20:31:51 +0000 (20:31 +0000)
magick/feature.c

index 6f7def52147478f30670d93ca7d165f84f3e4025..f07943d387b94d289c113603e03a0f513739fc95 100644 (file)
@@ -148,7 +148,8 @@ MagickExport ChannelFeatures *GetImageChannelFeatures(const Image *image,
     *tones;
 
   long
-    y;
+    y,
+    z;
 
   MagickBooleanType
     status;
@@ -514,6 +515,9 @@ MagickExport ChannelFeatures *GetImageChannelFeatures(const Image *image,
   /*
     Compute texture features.
   */
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+  #pragma omp parallel for schedule(dynamic,4) shared(status)
+#endif
   for (y=0; y < (long) number_tones; y++)
   {
     register long
@@ -524,7 +528,7 @@ MagickExport ChannelFeatures *GetImageChannelFeatures(const Image *image,
       for (i=0; i < 4; i++)
       {
         /*
-          Angular second moment.
+          Angular second moment:  measure of homogeneity of the image.
         */
         channel_features[RedChannel].angular_second_moment[i]+=
           pixels[x][y].tones[i].red*pixels[x][y].tones[i].red;
@@ -536,11 +540,60 @@ MagickExport ChannelFeatures *GetImageChannelFeatures(const Image *image,
           channel_features[OpacityChannel].angular_second_moment[i]+=
             pixels[x][y].tones[i].opacity*pixels[x][y].tones[i].opacity;
         if (image->colorspace == CMYKColorspace)
-          channel_features[IndexChannel].angular_second_moment[i]+=
+          channel_features[BlackChannel].angular_second_moment[i]+=
             pixels[x][y].tones[i].index*pixels[x][y].tones[i].index;
       }
     }
   }
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+  #pragma omp parallel for schedule(dynamic,4) shared(status)
+#endif
+  for (z=0; z < (long) number_tones; z++)
+  {
+    register long
+      y;
+
+    SpatialDependenceMatrix
+      pixel;
+
+    (void) ResetMagickMemory(&pixel,0,sizeof(pixel));
+    for (y=0; y < (long) number_tones; y++)
+    {
+      register long
+        x;
+
+      for (x=0; x < (long) number_tones; x++)
+      {
+        for (i=0; i < 4; i++)
+        {
+          /*
+            Contrast:  amount of local variations present in an image.
+          */
+          if (((y-x) == z) || ((x-y) == z))
+            {
+              pixel.tones[i].red+=pixels[x][y].tones[i].red;
+              pixel.tones[i].green+=pixels[x][y].tones[i].green;
+              pixel.tones[i].blue+=pixels[x][y].tones[i].blue;
+              if (image->matte != MagickFalse)
+                pixel.tones[i].opacity+=pixels[x][y].tones[i].opacity;
+              if (image->colorspace == CMYKColorspace)
+                pixel.tones[i].index+=pixels[x][y].tones[i].index;
+            }
+        }
+      }
+    }
+    for (i=0; i < 4; i++)
+    {
+      channel_features[RedChannel].contrast[i]+=z*z*pixel.tones[i].red;
+      channel_features[GreenChannel].contrast[i]+=z*z*pixel.tones[i].green;
+      channel_features[BlueChannel].contrast[i]+=z*z*pixel.tones[i].blue;
+      if (image->matte != MagickFalse)
+        channel_features[OpacityChannel].contrast[i]+=z*z*
+          pixel.tones[i].opacity;
+      if (image->colorspace == CMYKColorspace)
+        channel_features[BlackChannel].contrast[i]+=z*z*pixel.tones[i].index;
+    }
+  }
   /*
     Relinquish resources.
   */