From: Cristy Date: Sun, 2 Jul 2017 16:02:11 +0000 (-0400) Subject: Framework for new -auto-threshold option X-Git-Tag: 7.0.6-1~101 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9c08c99835d17c0875e17ce4c16fe3411c9429a6;p=imagemagick Framework for new -auto-threshold option --- diff --git a/MagickCore/option.c b/MagickCore/option.c index f46f27579..a534e7e8f 100644 --- a/MagickCore/option.c +++ b/MagickCore/option.c @@ -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" @@ -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); diff --git a/MagickCore/option.h b/MagickCore/option.h index 16f8fb816..4d8b2e7e4 100644 --- a/MagickCore/option.h +++ b/MagickCore/option.h @@ -101,7 +101,8 @@ typedef enum MagickTypeOptions, MagickValidateOptions, MagickVirtualPixelOptions, - MagickWeightOptions + MagickWeightOptions, + MagickAutoThresholdOptions } CommandOption; typedef enum diff --git a/MagickCore/threshold.c b/MagickCore/threshold.c index 51b4ad482..dac177ce4 100644 --- a/MagickCore/threshold.c +++ b/MagickCore/threshold.c @@ -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); +} + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % % B i l e v e l I m a g e % % % % % diff --git a/MagickCore/threshold.h b/MagickCore/threshold.h index 4f702ce35..99913f29c 100644 --- a/MagickCore/threshold.h +++ b/MagickCore/threshold.h @@ -22,6 +22,14 @@ 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 *), diff --git a/MagickWand/convert.c b/MagickWand/convert.c index 187595911..8fd8cd6e0 100644 --- a/MagickWand/convert.c +++ b/MagickWand/convert.c @@ -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) diff --git a/MagickWand/mogrify.c b/MagickWand/mogrify.c index 83d8cd172..7c726b73e 100644 --- a/MagickWand/mogrify.c +++ b/MagickWand/mogrify.c @@ -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) diff --git a/MagickWand/operation.c b/MagickWand/operation.c index 56c69aa95..09e8fbf8e 100644 --- a/MagickWand/operation.c +++ b/MagickWand/operation.c @@ -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': diff --git a/utilities/convert.1.in b/utilities/convert.1.in index 580245f16..c9880f7c0 100644 --- a/utilities/convert.1.in +++ b/utilities/convert.1.in @@ -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 diff --git a/utilities/mogrify.1.in b/utilities/mogrify.1.in index f50aaddd3..9a53089cf 100644 --- a/utilities/mogrify.1.in +++ b/utilities/mogrify.1.in @@ -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