]> granicus.if.org Git - imagemagick/blobdiff - magick/segment.c
(no commit message)
[imagemagick] / magick / segment.c
index 428b823fe7fdd8ca67ff0e5e93d93dc34a721f00..f19300e71c413570a04252cdf92d416b26f8570e 100644 (file)
@@ -17,7 +17,7 @@
 %                                April 1993                                   %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2010 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2011 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  %
@@ -208,7 +208,7 @@ static void
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
 %  Classify() defines one or more classes.  Each pixel is thresholded to
-%  determine which class it bessize_ts to.  If the class is not identified it is
+%  determine which class it belongs to.  If the class is not identified it is
 %  assigned to the closest class based on the fuzzy c-Means technique.
 %
 %  The format of the Classify method is:
@@ -308,7 +308,7 @@ static MagickBooleanType Classify(Image *image,short **extrema,
           }
         else
           {
-            cluster=(Cluster *) AcquireAlignedMemory(1,sizeof(*cluster));
+            cluster=(Cluster *) AcquireMagickMemory(sizeof(*cluster));
             head=cluster;
           }
         if (cluster == (Cluster *) NULL)
@@ -330,7 +330,7 @@ static MagickBooleanType Classify(Image *image,short **extrema,
       /*
         No classes were identified-- create one.
       */
-      cluster=(Cluster *) AcquireAlignedMemory(1,sizeof(*cluster));
+      cluster=(Cluster *) AcquireMagickMemory(sizeof(*cluster));
       if (cluster == (Cluster *) NULL)
         ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed",
           image->filename);
@@ -445,50 +445,53 @@ static MagickBooleanType Classify(Image *image,short **extrema,
       /*
         Print cluster statistics.
       */
-      (void) fprintf(stdout,"Fuzzy C-means Statistics\n");
-      (void) fprintf(stdout,"===================\n\n");
-      (void) fprintf(stdout,"\tCluster Threshold = %g\n",(double)
+      (void) FormatLocaleFile(stdout,"Fuzzy C-means Statistics\n");
+      (void) FormatLocaleFile(stdout,"===================\n\n");
+      (void) FormatLocaleFile(stdout,"\tCluster Threshold = %g\n",(double)
         cluster_threshold);
-      (void) fprintf(stdout,"\tWeighting Exponent = %g\n",(double)
+      (void) FormatLocaleFile(stdout,"\tWeighting Exponent = %g\n",(double)
         weighting_exponent);
-      (void) fprintf(stdout,"\tTotal Number of Clusters = %lu\n\n",
-        number_clusters);
+      (void) FormatLocaleFile(stdout,"\tTotal Number of Clusters = %.20g\n\n",
+        (double) number_clusters);
       /*
         Print the total number of points per cluster.
       */
-      (void) fprintf(stdout,"\n\nNumber of Vectors Per Cluster\n");
-      (void) fprintf(stdout,"=============================\n\n");
+      (void) FormatLocaleFile(stdout,"\n\nNumber of Vectors Per Cluster\n");
+      (void) FormatLocaleFile(stdout,"=============================\n\n");
       for (cluster=head; cluster != (Cluster *) NULL; cluster=cluster->next)
-        (void) fprintf(stdout,"Cluster #%ld = %ld\n",(long) cluster->id,
-          (long) cluster->count);
+        (void) FormatLocaleFile(stdout,"Cluster #%.20g = %.20g\n",(double)
+          cluster->id,(double) cluster->count);
       /*
         Print the cluster extents.
       */
-      (void) fprintf(stdout,
+      (void) FormatLocaleFile(stdout,
         "\n\n\nCluster Extents:        (Vector Size: %d)\n",MaxDimension);
-      (void) fprintf(stdout,"================");
+      (void) FormatLocaleFile(stdout,"================");
       for (cluster=head; cluster != (Cluster *) NULL; cluster=cluster->next)
       {
-        (void) fprintf(stdout,"\n\nCluster #%ld\n\n",(long) cluster->id);
-        (void) fprintf(stdout,"%ld-%ld  %ld-%ld  %ld-%ld\n",(long)
-          cluster->red.left,(long) cluster->red.right,(long)
-          cluster->green.left,(long) cluster->green.right,(long)
-          cluster->blue.left,(long) cluster->blue.right);
+        (void) FormatLocaleFile(stdout,"\n\nCluster #%.20g\n\n",(double)
+          cluster->id);
+        (void) FormatLocaleFile(stdout,
+          "%.20g-%.20g  %.20g-%.20g  %.20g-%.20g\n",(double)
+          cluster->red.left,(double) cluster->red.right,(double)
+          cluster->green.left,(double) cluster->green.right,(double)
+          cluster->blue.left,(double) cluster->blue.right);
       }
       /*
         Print the cluster center values.
       */
-      (void) fprintf(stdout,
+      (void) FormatLocaleFile(stdout,
         "\n\n\nCluster Center Values:        (Vector Size: %d)\n",MaxDimension);
-      (void) fprintf(stdout,"=====================");
+      (void) FormatLocaleFile(stdout,"=====================");
       for (cluster=head; cluster != (Cluster *) NULL; cluster=cluster->next)
       {
-        (void) fprintf(stdout,"\n\nCluster #%ld\n\n",(long) cluster->id);
-        (void) fprintf(stdout,"%g  %g  %g\n",(double)
+        (void) FormatLocaleFile(stdout,"\n\nCluster #%.20g\n\n",(double)
+          cluster->id);
+        (void) FormatLocaleFile(stdout,"%g  %g  %g\n",(double)
           cluster->red.center,(double) cluster->green.center,(double)
           cluster->blue.center);
       }
-      (void) fprintf(stdout,"\n");
+      (void) FormatLocaleFile(stdout,"\n");
     }
   if (number_clusters > 256)
     ThrowBinaryException(ImageError,"TooManyClusters",image->filename);
@@ -555,7 +558,7 @@ static MagickBooleanType Classify(Image *image,short **extrema,
     indexes=GetCacheViewAuthenticIndexQueue(image_view);
     for (x=0; x < (ssize_t) image->columns; x++)
     {
-      indexes[x]=(IndexPacket) 0;
+      SetIndexPixelComponent(indexes+x,0);
       for (cluster=head; cluster != (Cluster *) NULL; cluster=cluster->next)
       {
         if (((ssize_t) ScaleQuantumToChar(q->red) >=
@@ -574,7 +577,7 @@ static MagickBooleanType Classify(Image *image,short **extrema,
             /*
               Classify this pixel.
             */
-            indexes[x]=(IndexPacket) cluster->id;
+            SetIndexPixelComponent(indexes+x,cluster->id);
             break;
           }
       }
@@ -624,7 +627,7 @@ static MagickBooleanType Classify(Image *image,short **extrema,
                   Classify this pixel.
                 */
                 local_minima=1.0/sum;
-                indexes[x]=(IndexPacket) j;
+                SetIndexPixelComponent(indexes+x,j);
               }
           }
         }
@@ -714,6 +717,12 @@ static inline ssize_t MagickMin(const ssize_t x,const ssize_t y)
 static void ConsolidateCrossings(ZeroCrossing *zero_crossing,
   const size_t number_crossings)
 {
+  register ssize_t
+    i,
+    j,
+    k,
+    l;
+
   ssize_t
     center,
     correct,
@@ -721,12 +730,6 @@ static void ConsolidateCrossings(ZeroCrossing *zero_crossing,
     left,
     right;
 
-  register ssize_t
-    i,
-    j,
-    k,
-    l;
-
   /*
     Consolidate zero crossings.
   */
@@ -958,11 +961,6 @@ MagickExport MagickBooleanType GetImageDynamicThreshold(const Image *image,
     green,
     red;
 
-  ssize_t
-    count,
-    *histogram[MaxDimension],
-    y;
-
   MagickBooleanType
     proceed;
 
@@ -979,6 +977,11 @@ MagickExport MagickBooleanType GetImageDynamicThreshold(const Image *image,
   short
     *extrema[MaxDimension];
 
+  ssize_t
+    count,
+    *histogram[MaxDimension],
+    y;
+
   /*
     Allocate histogram and extrema.
   */
@@ -1040,7 +1043,7 @@ MagickExport MagickBooleanType GetImageDynamicThreshold(const Image *image,
           }
         else
           {
-            cluster=(Cluster *) AcquireAlignedMemory(1,sizeof(*cluster));
+            cluster=(Cluster *) AcquireMagickMemory(sizeof(*cluster));
             head=cluster;
           }
         if (cluster == (Cluster *) NULL)
@@ -1066,7 +1069,7 @@ MagickExport MagickBooleanType GetImageDynamicThreshold(const Image *image,
       /*
         No classes were identified-- create one.
       */
-      cluster=(Cluster *) AcquireAlignedMemory(1,sizeof(*cluster));
+      cluster=(Cluster *) AcquireMagickMemory(sizeof(*cluster));
       if (cluster == (Cluster *) NULL)
         {
           (void) ThrowMagickException(exception,GetMagickModule(),
@@ -1233,9 +1236,6 @@ MagickExport MagickBooleanType GetImageDynamicThreshold(const Image *image,
 static void InitializeHistogram(const Image *image,ssize_t **histogram,
   ExceptionInfo *exception)
 {
-  ssize_t
-    y;
-
   register const PixelPacket
     *p;
 
@@ -1243,6 +1243,9 @@ static void InitializeHistogram(const Image *image,ssize_t **histogram,
     i,
     x;
 
+  ssize_t
+    y;
+
   /*
     Initialize histogram.
   */
@@ -1357,15 +1360,15 @@ static IntervalTree *InitializeIntervalTree(const ZeroCrossing *zero_crossing,
     *node,
     *root;
 
+  register ssize_t
+    i;
+
   ssize_t
     j,
     k,
     left,
     number_nodes;
 
-  register ssize_t
-    i;
-
   /*
     Allocate interval tree.
   */
@@ -1376,7 +1379,7 @@ static IntervalTree *InitializeIntervalTree(const ZeroCrossing *zero_crossing,
   /*
     The root is the entire histogram.
   */
-  root=(IntervalTree *) AcquireAlignedMemory(1,sizeof(*root));
+  root=(IntervalTree *) AcquireMagickMemory(sizeof(*root));
   root->child=(IntervalTree *) NULL;
   root->sibling=(IntervalTree *) NULL;
   root->tau=0.0;
@@ -1508,11 +1511,8 @@ static MagickRealType OptimalTau(const ssize_t *histogram,const double max_tau,
     *node,
     *root;
 
-  ssize_t
-    index,
-    j,
-    k,
-    number_nodes;
+  MagickBooleanType
+    peak;
 
   MagickRealType
     average_tau,
@@ -1525,13 +1525,16 @@ static MagickRealType OptimalTau(const ssize_t *histogram,const double max_tau,
     i,
     x;
 
-  MagickBooleanType
-    peak;
-
   size_t
     count,
     number_crossings;
 
+  ssize_t
+    index,
+    j,
+    k,
+    number_nodes;
+
   ZeroCrossing
     *zero_crossing;
 
@@ -1787,9 +1790,6 @@ MagickExport MagickBooleanType SegmentImage(Image *image,
   const ColorspaceType colorspace,const MagickBooleanType verbose,
   const double cluster_threshold,const double smooth_threshold)
 {
-  ssize_t
-    *histogram[MaxDimension];
-
   MagickBooleanType
     status;
 
@@ -1799,6 +1799,9 @@ MagickExport MagickBooleanType SegmentImage(Image *image,
   short
     *extrema[MaxDimension];
 
+  ssize_t
+    *histogram[MaxDimension];
+
   /*
     Allocate histogram and extrema.
   */
@@ -1883,12 +1886,12 @@ MagickExport MagickBooleanType SegmentImage(Image *image,
 static void ZeroCrossHistogram(MagickRealType *second_derivative,
   const MagickRealType smooth_threshold,short *crossings)
 {
-  ssize_t
-    parity;
-
   register ssize_t
     i;
 
+  ssize_t
+    parity;
+
   /*
     Merge low numbers to zero to help prevent noise.
   */