From: cristy Date: Sat, 27 Sep 2014 14:21:20 +0000 (+0000) Subject: (no commit message) X-Git-Tag: 7.0.1-0~1972 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3b207f84e063df4bcd421a6cf49a2d74c5190705;p=imagemagick --- diff --git a/MagickCore/effect.c b/MagickCore/effect.c index 2608e976d..8291a0952 100644 --- a/MagickCore/effect.c +++ b/MagickCore/effect.c @@ -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); +} + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % % M o t i o n B l u r I m a g e % % % % % diff --git a/MagickCore/effect.h b/MagickCore/effect.h index 91344d0ff..6979a9f26 100644 --- a/MagickCore/effect.h +++ b/MagickCore/effect.h @@ -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 *), diff --git a/MagickCore/option.c b/MagickCore/option.c index c158ad4a9..53b82d04c 100644 --- a/MagickCore/option.c +++ b/MagickCore/option.c @@ -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 }, diff --git a/MagickWand/convert.c b/MagickWand/convert.c index 0902fec35..b150e2502 100644 --- a/MagickWand/convert.c +++ b/MagickWand/convert.c @@ -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': diff --git a/MagickWand/mogrify.c b/MagickWand/mogrify.c index 535dc7c00..82605987d 100644 --- a/MagickWand/mogrify.c +++ b/MagickWand/mogrify.c @@ -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': diff --git a/MagickWand/operation.c b/MagickWand/operation.c index 96c25c6a0..07117126b 100644 --- a/MagickWand/operation.c +++ b/MagickWand/operation.c @@ -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) diff --git a/PerlMagick/Magick.xs b/PerlMagick/Magick.xs index a00505567..9485a97e7 100644 --- a/PerlMagick/Magick.xs +++ b/PerlMagick/Magick.xs @@ -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); diff --git a/PerlMagick/quantum/quantum.xs.in b/PerlMagick/quantum/quantum.xs.in index bfef70d50..aaf072003 100644 --- a/PerlMagick/quantum/quantum.xs.in +++ b/PerlMagick/quantum/quantum.xs.in @@ -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);