]> granicus.if.org Git - imagemagick/commitdiff
(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Sat, 27 Sep 2014 14:21:20 +0000 (14:21 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Sat, 27 Sep 2014 14:21:20 +0000 (14:21 +0000)
MagickCore/effect.c
MagickCore/effect.h
MagickCore/option.c
MagickWand/convert.c
MagickWand/mogrify.c
MagickWand/operation.c
PerlMagick/Magick.xs
PerlMagick/quantum/quantum.xs.in

index 2608e976da76389e871b214884ffe631b47a2fc1..8291a09520e7251934b513b9d94da65e4c4b90ed 100644 (file)
@@ -1395,6 +1395,65 @@ MagickExport Image *GaussianBlurImage(const Image *image,const double radius,
 %                                                                             %
 %                                                                             %
 %                                                                             %
+%     K u w a h a r a I m a g e                                               %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  KuwaharaImage() is an edge perserving blur.
+%
+%  The format of the KuwaharaImage method is:
+%
+%      Image *KuwaharaImage(const Image *image,const double radius,
+%        const double sigma,ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o image: the image.
+%
+%    o radius: the radius of the Gaussian, in pixels, not counting the center
+%      pixel.
+%
+%    o sigma: the standard deviation of the Gaussian, in pixels.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+MagickExport Image *KuwaharaImage(const Image *image,const double radius,
+  const double sigma,ExceptionInfo *exception)
+{
+  char
+    geometry[MaxTextExtent];
+
+  KernelInfo
+    *kernel_info;
+
+  Image
+    *kuwahara_image;
+
+  assert(image != (const Image *) NULL);
+  assert(image->signature == MagickSignature);
+  if (image->debug != MagickFalse)
+    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+  assert(exception != (ExceptionInfo *) NULL);
+  assert(exception->signature == MagickSignature);
+  (void) FormatLocaleString(geometry,MaxTextExtent,
+    "blur:%.20gx%.20g;blur:%.20gx%.20g+90",radius,sigma,radius,sigma);
+  kernel_info=AcquireKernelInfo(geometry);
+  if (kernel_info == (KernelInfo *) NULL)
+    ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
+  kuwahara_image=MorphologyApply(image,ConvolveMorphology,1,kernel_info,
+    UndefinedCompositeOp,0.0,exception);
+  kernel_info=DestroyKernelInfo(kernel_info);
+  return(kuwahara_image);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
 %     M o t i o n B l u r I m a g e                                           %
 %                                                                             %
 %                                                                             %
index 91344d0fff7ab9eeccb33ea4a7e5d58044e7871b..6979a9f2675ca977aa25ec1d2cc8014138dbb485 100644 (file)
@@ -68,6 +68,7 @@ extern MagickExport Image
   *EdgeImage(const Image *,const double,ExceptionInfo *),
   *EmbossImage(const Image *,const double,const double,ExceptionInfo *),
   *GaussianBlurImage(const Image *,const double,const double,ExceptionInfo *),
+  *KuwaharaImage(const Image *,const double,const double,ExceptionInfo *),
   *MotionBlurImage(const Image *,const double,const double,const double,
     ExceptionInfo *),
   *PreviewImage(const Image *,const PreviewType,ExceptionInfo *),
index c158ad4a960876e97fa302877e208041c48a38bf..53b82d04ce91fe0d4736b950ac1e2c0a3305af93 100644 (file)
@@ -478,6 +478,8 @@ static const OptionInfo
     { "-interword-spacing", 1L, ImageInfoOptionFlag | DrawInfoOptionFlag, MagickFalse },
     { "+kerning", 0L, ImageInfoOptionFlag | DrawInfoOptionFlag, MagickFalse },
     { "-kerning", 1L, ImageInfoOptionFlag | DrawInfoOptionFlag, MagickFalse },
+    { "+kuwahara", 0L, DeprecateOptionFlag, MagickTrue },
+    { "-kuwahara", 1L, SimpleOperatorFlag, MagickFalse },
     { "+label", 0L, ImageInfoOptionFlag | NeverInterpretArgsFlag, MagickFalse },
     { "-label", 1L, ImageInfoOptionFlag | NeverInterpretArgsFlag, MagickFalse },
     { "+lat", 1L, DeprecateOptionFlag, MagickTrue },
index 0902fec35af982036b34cb62a4d76724fa3c5363..b150e2502971b0efb0904a22b120ca7d8a17812c 100644 (file)
@@ -226,6 +226,7 @@ static MagickBooleanType ConvertUsage(void)
       "-identify            identify the format and characteristics of the image",
       "-ift                 implements the inverse discrete Fourier transform (DFT)",
       "-implode amount      implode image pixels about the center",
+      "-kuwahara geometry   edge preserving blur",
       "-lat geometry        local adaptive thresholding",
       "-level value         adjust the level of image contrast",
       "-level-colors color,color",
@@ -1881,6 +1882,17 @@ WandExport MagickBooleanType ConvertImageCommand(ImageInfo *image_info,
               ThrowConvertInvalidArgumentException(option,argv[i]);
             break;
           }
+        if (LocaleCompare("kuwahara",option+1) == 0)
+          {
+            if (*option == '+')
+              break;
+            i++;
+            if (i == (ssize_t) argc)
+              ThrowConvertException(OptionError,"MissingArgument",option);
+            if (IsGeometry(argv[i]) == MagickFalse)
+              ThrowConvertInvalidArgumentException(option,argv[i]);
+            break;
+          }
         ThrowConvertException(OptionError,"UnrecognizedOption",option)
       }
       case 'l':
index 535dc7c0040903e0dfd0a431899bebe292551c7a..82605987d3bf07ab69b42da2ba03b817ba887f3d 100644 (file)
@@ -1895,6 +1895,21 @@ WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
             draw_info->kerning=geometry_info.rho;
             break;
           }
+        if (LocaleCompare("kuwahara",option+1) == 0)
+          {
+            /*
+              Edge preserving blur.
+            */
+            (void) SyncImageSettings(mogrify_info,*image,exception);
+            flags=ParseGeometry(argv[i+1],&geometry_info);
+            if ((flags & SigmaValue) == 0)
+              geometry_info.sigma=1.0;
+            if ((flags & XiValue) == 0)
+              geometry_info.xi=0.0;
+            mogrify_image=KuwaharaImage(*image,geometry_info.rho,
+              geometry_info.sigma,exception);
+            break;
+          }
         break;
       }
       case 'l':
@@ -3391,6 +3406,7 @@ static MagickBooleanType MogrifyUsage(void)
       "-implode amount      implode image pixels about the center",
       "-interpolative-resize geometry",
       "                     resize image using interpolation",
+      "-kuwahara geometry   edge preserving blur",
       "-lat geometry        local adaptive thresholding",
       "-level value         adjust the level of image contrast",
       "-level-colors color,color",
@@ -5025,6 +5041,15 @@ WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info,
               ThrowMogrifyInvalidArgumentException(option,argv[i]);
             break;
           }
+        if (LocaleCompare("kuwahara",option+1) == 0)
+          {
+            i++;
+            if (i == (ssize_t) argc)
+              ThrowMogrifyException(OptionError,"MissingArgument",option);
+            if (IsGeometry(argv[i]) == MagickFalse)
+              ThrowMogrifyInvalidArgumentException(option,argv[i]);
+            break;
+          }
         ThrowMogrifyException(OptionError,"UnrecognizedOption",option)
       }
       case 'l':
index 96c25c6a0fde02edb502e8413cf64e933a9a7495..07117126b7a6a7dfb3d22e2178f81b46558df069 100644 (file)
@@ -2550,6 +2550,24 @@ static MagickBooleanType CLISimpleOperatorImage(MagickCLI *cli_wand,
         }
       CLIWandExceptionBreak(OptionError,"UnrecognizedOption",option);
     }
+    case 'k':
+    {
+      if (LocaleCompare("kuwahara",option+1) == 0)
+        {
+          /*
+            Edge preserving blur.
+          */
+          flags=ParseGeometry(arg1,&geometry_info);
+          if ((flags & (RhoValue|SigmaValue)) == 0)
+            CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1);
+          if ((flags & SigmaValue) == 0)
+            geometry_info.sigma=1.0;
+          new_image=KuwaharaImage(_image,geometry_info.rho,geometry_info.sigma,
+           _exception);
+          break;
+        }
+      CLIWandExceptionBreak(OptionError,"UnrecognizedOption",option);
+    }
     case 'l':
     {
       if (LocaleCompare("lat",option+1) == 0)
index a00505567b3ad734a87c53d8242ddb2bb36aad6f..9485a97e7cfabeb82a6fce975c61165bb77475dc 100644 (file)
@@ -553,6 +553,8 @@ static struct
     { "MeanShift", { {"geometry", StringReference},
       {"width", IntegerReference}, {"height", IntegerReference},
       {"distance", RealReference} } },
+    { "Kuwahara", { {"geometry", StringReference}, {"radius", RealReference},
+      {"sigma", RealReference}, {"channel", MagickChannelOptions} } },
   };
 
 static SplayTreeInfo
@@ -7543,6 +7545,8 @@ Mogrify(ref,...)
     HoughLineImage     = 281
     MeanShift          = 282
     MeanShiftImage     = 283
+    Kuwahara           = 284
+    KuwaharaImage      = 285
     MogrifyRegion      = 666
   PPCODE:
   {
@@ -11191,6 +11195,28 @@ Mogrify(ref,...)
             geometry_info.sigma,geometry_info.xi,exception);
           break;
         }
+        case 141:  /* Kuwahara */
+        {
+          if (attribute_flag[0] != 0)
+            {
+              flags=ParseGeometry(argument_list[0].string_reference,
+                &geometry_info);
+              if ((flags & SigmaValue) == 0)
+                geometry_info.sigma=1.0;
+            }
+          if (attribute_flag[1] != 0)
+            geometry_info.rho=argument_list[1].real_reference;
+          if (attribute_flag[2] != 0)
+            geometry_info.sigma=argument_list[2].real_reference;
+          if (attribute_flag[3] != 0)
+            channel=(ChannelType) argument_list[3].integer_reference;
+          channel_mask=SetImageChannelMask(image,channel);
+          image=KuwaharaImage(image,geometry_info.rho,geometry_info.sigma,
+            exception);
+          if (image != (Image *) NULL)
+            (void) SetImageChannelMask(image,channel_mask);
+          break;
+        }
       }
       if (next != (Image *) NULL)
         (void) CatchImageException(next);
index bfef70d50c218078ef93406705c6de3b39a1a275..aaf0720037168569acc85a2d8670a00a7d1cb7b6 100644 (file)
@@ -553,6 +553,8 @@ static struct
     { "MeanShift", { {"geometry", StringReference},
       {"width", IntegerReference}, {"height", IntegerReference},
       {"double", RealReference} } },
+    { "Kuwahara", { {"geometry", StringReference}, {"radius", RealReference},
+      {"sigma", RealReference}, {"channel", MagickChannelOptions} } },
   };
 
 static SplayTreeInfo
@@ -7543,6 +7545,8 @@ Mogrify(ref,...)
     HoughLineImage     = 281
     MeanShift          = 282
     MeanShiftImage     = 283
+    Kuwahara           = 284
+    KuwaharaImage      = 285
     MogrifyRegion      = 666
   PPCODE:
   {
@@ -11189,6 +11193,28 @@ Mogrify(ref,...)
             geometry_info.sigma,geometry_info.xi,exception);
           break;
         }
+        case 141:  /* Kuwahara */
+        {
+          if (attribute_flag[0] != 0)
+            {
+              flags=ParseGeometry(argument_list[0].string_reference,
+                &geometry_info);
+              if ((flags & SigmaValue) == 0)
+                geometry_info.sigma=1.0;
+            }
+          if (attribute_flag[1] != 0)
+            geometry_info.rho=argument_list[1].real_reference;
+          if (attribute_flag[2] != 0)
+            geometry_info.sigma=argument_list[2].real_reference;
+          if (attribute_flag[3] != 0)
+            channel=(ChannelType) argument_list[3].integer_reference;
+          channel_mask=SetImageChannelMask(image,channel);
+          image=KuwaharaImage(image,geometry_info.rho,geometry_info.sigma,
+            exception);
+          if (image != (Image *) NULL)
+            (void) SetImageChannelMask(image,channel_mask);
+          break;
+        }
       }
       if (next != (Image *) NULL)
         (void) CatchImageException(next);