]> granicus.if.org Git - imagemagick/commitdiff
Framework for new -auto-threshold option
authorCristy <urban-warrior@imagemagick.org>
Sun, 2 Jul 2017 16:02:11 +0000 (12:02 -0400)
committerCristy <urban-warrior@imagemagick.org>
Sun, 2 Jul 2017 16:02:11 +0000 (12:02 -0400)
MagickCore/option.c
MagickCore/option.h
MagickCore/threshold.c
MagickCore/threshold.h
MagickWand/convert.c
MagickWand/mogrify.c
MagickWand/operation.c
utilities/convert.1.in
utilities/mogrify.1.in

index f46f27579fb1b5eb25acf3999cddd1ba4635d1d0..a534e7e8fe4316e31998c6507ec597770d6083d4 100644 (file)
@@ -75,6 +75,7 @@
 #include "MagickCore/splay-tree.h"
 #include "MagickCore/statistic.h"
 #include "MagickCore/string_.h"
+#include "MagickCore/threshold.h"
 #include "MagickCore/token.h"
 #include "MagickCore/utility.h"
 \f
@@ -114,6 +115,14 @@ static const OptionInfo
     { "Transparent", TransparentAlphaChannel, UndefinedOptionFlag, MagickFalse },
     { (char *) NULL, UndefinedAlphaChannel, UndefinedOptionFlag, MagickFalse }
   },
+  AutoThresholdOptions[] =
+  {
+    { "Undefined", UndefinedThresholdMethod, UndefinedOptionFlag, MagickTrue },
+    { "Kapur", KapurThresholdMethod, UndefinedOptionFlag, MagickFalse },
+    { "OTSU", OTSUThresholdMethod, UndefinedOptionFlag, MagickFalse },
+    { "Triangle", TriangleThresholdMethod, UndefinedOptionFlag, MagickFalse },
+    { (char *) NULL, UndefinedThresholdMethod, UndefinedOptionFlag, MagickFalse }
+  },
   BooleanOptions[] =
   {
     { "False", MagickFalse, UndefinedOptionFlag, MagickFalse },
@@ -326,6 +335,8 @@ static const OptionInfo
     { "-auto-level", 0L, SimpleOperatorFlag, MagickFalse },
     { "+auto-orient", 0L, DeprecateOptionFlag, MagickTrue },
     { "-auto-orient", 0L, SimpleOperatorFlag, MagickFalse },
+    { "+auto-threshold", 1L, DeprecateOptionFlag, MagickTrue },
+    { "-auto-threshold", 1L, SimpleOperatorFlag, MagickFalse },
     { "+average", 0L, DeprecateOptionFlag, MagickTrue },
     { "-average", 0L, ReplacedOptionFlag | ListOperatorFlag | FireOptionFlag, MagickTrue },
     { "+backdrop", 0L, NonMagickOptionFlag | NeverInterpretArgsFlag, MagickFalse },
@@ -1313,6 +1324,7 @@ static const OptionInfo
   {
     { "Align", MagickAlignOptions, UndefinedOptionFlag, MagickFalse },
     { "Alpha", MagickAlphaChannelOptions, UndefinedOptionFlag, MagickFalse },
+    { "AutoThreshold", MagickAutoThresholdOptions, UndefinedOptionFlag, MagickFalse },
     { "Boolean", MagickBooleanOptions, UndefinedOptionFlag, MagickFalse },
     { "Cache", MagickCacheOptions, UndefinedOptionFlag, MagickFalse },
     { "Channel", MagickChannelOptions, UndefinedOptionFlag, MagickFalse },
@@ -2073,6 +2085,7 @@ static const OptionInfo *GetOptionInfo(const CommandOption option)
   {
     case MagickAlignOptions: return(AlignOptions);
     case MagickAlphaChannelOptions: return(AlphaChannelOptions);
+    case MagickAutoThresholdOptions: return(AutoThresholdOptions);
     case MagickBooleanOptions: return(BooleanOptions);
     case MagickCacheOptions: return(CacheOptions);
     case MagickChannelOptions: return(ChannelOptions);
index 16f8fb81636b15b19c29a70ec69c158c726862ef..4d8b2e7e46c145c133887529c0a74300870fb7ab 100644 (file)
@@ -101,7 +101,8 @@ typedef enum
   MagickTypeOptions,
   MagickValidateOptions,
   MagickVirtualPixelOptions,
-  MagickWeightOptions
+  MagickWeightOptions,
+  MagickAutoThresholdOptions
 } CommandOption;
 
 typedef enum
index 51b4ad48259dc1459bdf8a3445042ce79038ef62..dac177ce4ca421d3b2f449e1de3447a82901f469 100644 (file)
@@ -360,6 +360,39 @@ MagickExport Image *AdaptiveThresholdImage(const Image *image,
 %                                                                             %
 %                                                                             %
 %                                                                             %
+%     A u t o T h r e s o l d I m a g e                                       %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  AutoThresholdImage() ...
+%
+%  The format of the AutoThresholdImage method is:
+%
+%      MagickBooleanType AutoThresholdImage(Image *image,
+%        const AutoThresholdMethod threshold_type,ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o image: The image to auto-threshold.
+%
+%    o threshold_type: choose from Kapur, OTSU, or Triangle.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+MagickExport MagickBooleanType AutoThresholdImage(Image *image,
+  const AutoThresholdMethod threshold_type,ExceptionInfo *exception)
+{
+  return(MagickTrue);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
 %     B i l e v e l I m a g e                                                 %
 %                                                                             %
 %                                                                             %
index 4f702ce35878d98a43e9938fa695c4d95b0d1c79..99913f29cd79c3c1580bd913d6da3acc41d62c98 100644 (file)
 extern "C" {
 #endif
 
+typedef enum
+{
+  UndefinedThresholdMethod,
+  KapurThresholdMethod,
+  OTSUThresholdMethod,
+  TriangleThresholdMethod
+} AutoThresholdMethod;
+
 typedef struct _ThresholdMap
   ThresholdMap;
 
@@ -34,6 +42,7 @@ extern MagickExport ThresholdMap
   *GetThresholdMap(const char *,ExceptionInfo *);
 
 extern MagickExport MagickBooleanType
+  AutoThresholdImage(Image *,const AutoThresholdMethod,ExceptionInfo *),
   BilevelImage(Image *,const double,ExceptionInfo *),
   BlackThresholdImage(Image *,const char *,ExceptionInfo *),
   ClampImage(Image *,ExceptionInfo *),
index 1875959116b2ce688ff425b778d8fc73780d0d67..8fd8cd6e0cecb10da842512e9eae6d3361d94c72 100644 (file)
@@ -176,6 +176,8 @@ static MagickBooleanType ConvertUsage(void)
       "-auto-gamma          automagically adjust gamma level of image",
       "-auto-level          automagically adjust color levels of image",
       "-auto-orient         automagically orient (rotate) image",
+      "-auto-threshold method",
+      "                     automatically perform image thresholding",
       "-bench iterations    measure performance",
       "-black-threshold value",
       "                     force all pixels below the threshold into black",
@@ -750,6 +752,23 @@ WandExport MagickBooleanType ConvertImageCommand(ImageInfo *image_info,
           break;
         if (LocaleCompare("auto-orient",option+1) == 0)
           break;
+        if (LocaleCompare("auto-threshold",option+1) == 0)
+          {
+            ssize_t
+              method;
+            
+            if (*option == '+')
+              break;
+            i++;
+            if (i == (ssize_t) argc)
+              ThrowMogrifyException(OptionError,"MissingArgument",option);
+            method=ParseCommandOption(MagickAutoThresholdOptions,MagickFalse,
+              argv[i]);
+            if (method < 0)
+              ThrowMogrifyException(OptionError,"UnrecognizedThresholdMethod",
+                argv[i]);
+            break;
+          }
         if (LocaleCompare("average",option+1) == 0)
           break;
         ThrowConvertException(OptionError,"UnrecognizedOption",option)
index 83d8cd172ae9c80ead280ce1f3af338e7453fbee..7c726b73ec8d4974fd18bbe03bd049f96edae6fa 100644 (file)
@@ -899,6 +899,17 @@ WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
               exception);
             break;
           }
+        if (LocaleCompare("auto-threshold",option+1) == 0)
+          {
+            AutoThresholdMethod
+              method;
+
+            (void) SyncImageSettings(mogrify_info,*image,exception);
+            method=(AutoThresholdMethod) ParseCommandOption(
+              MagickAutoThresholdOptions,MagickFalse,argv[i+1]);
+            (void) AutoThresholdImage(*image,method,exception);
+            break;
+          }
         break;
       }
       case 'b':
@@ -3451,6 +3462,8 @@ static MagickBooleanType MogrifyUsage(void)
       "-auto-gamma          automagically adjust gamma level of image",
       "-auto-level          automagically adjust color levels of image",
       "-auto-orient         automagically orient (rotate) image",
+      "-auto-threshold method",
+      "                     automatically perform image thresholding",
       "-bench iterations    measure performance",
       "-black-threshold value",
       "                     force all pixels below the threshold into black",
@@ -4102,6 +4115,23 @@ WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
           break;
         if (LocaleCompare("auto-orient",option+1) == 0)
           break;
+        if (LocaleCompare("auto-threshold",option+1) == 0)
+          {
+            ssize_t
+              method;
+
+            if (*option == '+')
+              break;
+            i++;
+            if (i == (ssize_t) argc)
+              ThrowMogrifyException(OptionError,"MissingArgument",option);
+            method=ParseCommandOption(MagickAutoThresholdOptions,MagickFalse,
+              argv[i]);
+            if (method < 0)
+              ThrowMogrifyException(OptionError,"UnrecognizedThresholdMethod",
+                argv[i]);
+            break;
+          }
         if (LocaleCompare("average",option+1) == 0)
           break;
         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
index 56c69aa95508186b3f46173816e09469b46825b0..09e8fbf8eb16e0f9e0fa8c1b93f9277a3050cf52 100644 (file)
@@ -1806,6 +1806,16 @@ static MagickBooleanType CLISimpleOperatorImage(MagickCLI *cli_wand,
           new_image=AutoOrientImage(_image,_image->orientation,_exception);
           break;
         }
+      if (LocaleCompare("auto-threshold",option+1) == 0)
+        {
+          AutoThresholdMethod
+            method;
+
+          method=(AutoThresholdMethod) ParseCommandOption(
+            MagickAutoThresholdOptions,MagickFalse,argv[i+1]);
+          (void) AutoThresholdImage(_image,method,_exception);
+          break;
+        }
       CLIWandExceptionBreak(OptionError,"UnrecognizedOption",option);
     }
     case 'b':
index 580245f16614158b05804c8949fb974980a4bade..c9880f7c082cf584af43380dc223c9dff5605305 100644 (file)
@@ -127,6 +127,8 @@ Image Operators:
   \-auto-gamma          automagically adjust gamma level of image
   \-auto-level          automagically adjust color levels of image
   \-auto-orient         automatically orient image
+  \-auto-threshold method
+                       automatically perform image thresholding
   \-bench iterations    measure performance
   \-black-threshold value
                        force all pixels below the threshold into black
index f50aaddd37642f637d42c37ea183166f7304c9af..9a53089cff7a992cdfb8d3f11396b9fa90d96afc 100644 (file)
@@ -125,6 +125,8 @@ Image Operators:
   \-auto-gamma          automagically adjust gamma level of image
   \-auto-level          automagically adjust color levels of image
   \-auto-orient         automatically orient image
+  \-auto-threshold method
+                       automatically perform image thresholding
   \-bench iterations    measure performance
   \-black-threshold value
                        force all pixels below the threshold into black