From: cristy Date: Sat, 29 Mar 2014 15:30:43 +0000 (+0000) Subject: (no commit message) X-Git-Tag: 7.0.1-0~2534 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4ceadb87d6f921f481f1f9e82bcbb23c962e6e96;p=imagemagick --- diff --git a/MagickCore/effect.c b/MagickCore/effect.c index b0ef02e43..ee645be4e 100644 --- a/MagickCore/effect.c +++ b/MagickCore/effect.c @@ -849,6 +849,60 @@ MagickExport Image *BlurImage(const Image *image,const double radius, % % % % % % +% C a n n y E d g e I m a g e % +% % +% % +% % +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% CannyEdgeImage() uses a multi-stage algorithm to detect a wide range of +% edges in images. +% +% The format of the EdgeImage method is: +% +% Image *CannyEdgeImage(const Image *image,const double radius, +% const double sigma,const double low_factor,const double high_factor, +% const size_t threshold,ExceptionInfo *exception) +% +% A description of each parameter follows: +% +% o image: the image. +% +% o channel: the channel type. +% +% o radius: the radius of the gaussian smoothing filter. +% +% o sigma: the sigma of the gaussian smoothing filter. +% +% o low_factor: use this low factor in hysteresis. +% +% o hight_factor: use this high factor in hysteresis. +% +% o exception: return any errors or warnings in this structure. +% +*/ +MagickExport Image *CannyEdgeImage(const Image *image,const double radius, + const double sigma,const double low_factor,const double high_factor, + ExceptionInfo *exception) +{ + Image + *edge_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); + edge_image=(Image *) NULL; + return(edge_image); +} + +/* +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% % +% % +% % % C o n v o l v e I m a g e % % % % % diff --git a/MagickCore/effect.h b/MagickCore/effect.h index 91344d0ff..37c06a3eb 100644 --- a/MagickCore/effect.h +++ b/MagickCore/effect.h @@ -63,6 +63,8 @@ extern MagickExport Image *AdaptiveSharpenImage(const Image *,const double,const double, ExceptionInfo *), *BlurImage(const Image *,const double,const double,ExceptionInfo *), + *CannyEdgeImage(const Image *,const double,const double,const double, + const double,ExceptionInfo *), *ConvolveImage(const Image *,const KernelInfo *,ExceptionInfo *), *DespeckleImage(const Image *,ExceptionInfo *), *EdgeImage(const Image *,const double,ExceptionInfo *), diff --git a/MagickCore/option.c b/MagickCore/option.c index fa1975b88..e46b43d10 100644 --- a/MagickCore/option.c +++ b/MagickCore/option.c @@ -259,6 +259,8 @@ static const OptionInfo { "-brightness-contrast", 1L, SimpleOperatorFlag, MagickFalse }, { "+cache", 0L, GlobalOptionFlag, MagickFalse }, { "-cache", 1L, GlobalOptionFlag, MagickFalse }, + { "+edge", 1L, SimpleOperatorFlag, MagickTrue }, + { "-edge", 1L, SimpleOperatorFlag, MagickFalse }, { "+caption", 0L, ImageInfoOptionFlag | NeverInterpretArgsFlag, MagickFalse }, { "-caption", 1L, ImageInfoOptionFlag | NeverInterpretArgsFlag, MagickFalse }, { "+cdl", 1L, DeprecateOptionFlag, MagickTrue }, diff --git a/MagickWand/convert.c b/MagickWand/convert.c index d9f98a7e6..d7ab8da2a 100644 --- a/MagickWand/convert.c +++ b/MagickWand/convert.c @@ -177,6 +177,7 @@ static MagickBooleanType ConvertUsage(void) "-bordercolor color border color", "-brightness-contrast geometry", " improve brightness / contrast of the image", + "-canny geometry detect edges in the image", "-cdl filename color correct with a color decision list", "-charcoal radius simulate a charcoal drawing", "-chop geometry remove pixels from the image interior", @@ -863,6 +864,17 @@ WandExport MagickBooleanType ConvertImageCommand(ImageInfo *image_info, ThrowConvertInvalidArgumentException(option,argv[i]); break; } + if (LocaleCompare("canny",option+1) == 0) + { + if (*option == '+') + break; + i++; + if (i == (ssize_t) (argc-1)) + ThrowConvertException(OptionError,"MissingArgument",option); + if (IsGeometry(argv[i]) == MagickFalse) + ThrowConvertInvalidArgumentException(option,argv[i]); + break; + } if (LocaleCompare("caption",option+1) == 0) { if (*option == '+') diff --git a/MagickWand/mogrify.c b/MagickWand/mogrify.c index 7112e4133..2857f9ac1 100644 --- a/MagickWand/mogrify.c +++ b/MagickWand/mogrify.c @@ -981,6 +981,23 @@ WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc, } case 'c': { + if (LocaleCompare("canny",option+1) == 0) + { + /* + Detect edges in the image. + */ + (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.35; + if ((flags & PsiValue) == 0) + geometry_info.psi=0.75; + mogrify_image=CannyEdgeImage(*image,geometry_info.rho, + geometry_info.sigma,geometry_info.xi,geometry_info.psi,exception); + break; + } if (LocaleCompare("cdl",option+1) == 0) { char @@ -3286,6 +3303,7 @@ static MagickBooleanType MogrifyUsage(void) "-bordercolor color border color", "-brightness-contrast geometry", " improve brightness / contrast of the image", + "-canny geometry detect edges in the image", "-cdl filename color correct with a color decision list", "-charcoal geometry simulate a charcoal drawing", "-chop geometry remove pixels from the image interior", @@ -4009,6 +4027,17 @@ WandExport MagickBooleanType MogrifyImageCommand(ImageInfo *image_info, ThrowMogrifyInvalidArgumentException(option,argv[i]); break; } + if (LocaleCompare("canny",option+1) == 0) + { + if (*option == '+') + break; + i++; + if (i == (ssize_t) argc) + ThrowMogrifyException(OptionError,"MissingArgument",option); + if (IsGeometry(argv[i]) == MagickFalse) + ThrowMogrifyInvalidArgumentException(option,argv[i]); + break; + } if (LocaleCompare("caption",option+1) == 0) { if (*option == '+') diff --git a/MagickWand/operation.c b/MagickWand/operation.c index 88aa388af..11b5c0af6 100644 --- a/MagickWand/operation.c +++ b/MagickWand/operation.c @@ -1914,6 +1914,21 @@ static MagickBooleanType CLISimpleOperatorImage(MagickCLI *cli_wand, } case 'c': { + if (LocaleCompare("canny",option+1) == 0) + { + flags=ParseGeometry(arg1,&geometry_info); + if ((flags & (RhoValue|SigmaValue)) == 0) + CLIWandExceptArgBreak(OptionError,"InvalidArgument",option,arg1); + if ((flags & SigmaValue) == 0) + geometry_info.sigma=1.0; + if ((flags & XiValue) == 0) + geometry_info.xi=0.35; + if ((flags & PsiValue) == 0) + geometry_info.psi=0.75; + new_image=CannyEdgeImage(_image,geometry_info.rho, + geometry_info.sigma,geometry_info.xi,geometry_info.psi,_exception); + break; + } if (LocaleCompare("cdl",option+1) == 0) { /* Note: arguments do not have percent escapes expanded */ diff --git a/PerlMagick/Magick.xs b/PerlMagick/Magick.xs index b66ca308f..e207408fc 100644 --- a/PerlMagick/Magick.xs +++ b/PerlMagick/Magick.xs @@ -544,6 +544,9 @@ static struct { "Poly", { {"terms", ArrayReference}, {"channel", MagickChannelOptions} } }, { "Grayscale", { {"method", MagickNoiseOptions} } }, + { "CannyEdge", { {"geometry", StringReference}, + {"radius", RealReference}, {"sigma", RealReference}, + {"low-factor", RealReference}, {"high-factor", RealReference} } }, }; static SplayTreeInfo @@ -7525,6 +7528,8 @@ Mogrify(ref,...) PolyImage = 274 Grayscale = 275 GrayscaleImage = 276 + CannyEdge = 278 + CannyEdgeImage = 279 MogrifyRegion = 666 PPCODE: { @@ -11092,6 +11097,36 @@ Mogrify(ref,...) (void) GrayscaleImage(image,method,exception); break; } + case 138: /* Canny */ + { + if (attribute_flag[0] != 0) + { + flags=ParseGeometry(argument_list[0].string_reference, + &geometry_info); + if ((flags & SigmaValue) == 0) + geometry_info.sigma=1.0; + if ((flags & XiValue) == 0) + geometry_info.xi=0.35; + if ((flags & PsiValue) == 0) + geometry_info.psi=0.75; + } + 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) + geometry_info.xi=argument_list[3].real_reference; + if (attribute_flag[4] != 0) + geometry_info.psi=argument_list[4].real_reference; + if (attribute_flag[5] != 0) + channel=(ChannelType) argument_list[5].integer_reference; + channel_mask=SetImageChannelMask(image,channel); + image=CannyEdgeImage(image,geometry_info.rho,geometry_info.sigma, + geometry_info.xi,geometry_info.psi,exception); + if (image != (Image *) NULL) + (void) SetImageChannelMask(image,channel_mask); + break; + } } if (next != (Image *) NULL) (void) CatchImageException(next); diff --git a/utilities/convert.1.in b/utilities/convert.1.in index 4a542b5a2..f80930c85 100644 --- a/utilities/convert.1.in +++ b/utilities/convert.1.in @@ -135,6 +135,7 @@ Image Operators: \-border geometry surround image with a border of color \-brightness-contrast geometry \ improve brightness / contrast of the image + \-canny geometry detect edges in the image \-charcoal radius simulate a charcoal drawing \-chop geometry remove pixels from the image interior \-clamp keep pixel values in range (0-QuantumRange) diff --git a/utilities/mogrify.1.in b/utilities/mogrify.1.in index 248f5b69a..00af63ee2 100644 --- a/utilities/mogrify.1.in +++ b/utilities/mogrify.1.in @@ -133,6 +133,7 @@ Image Operators: \-border geometry surround image with a border of color \-brightness-contrast geometry improve brightness / contrast of the image + \-canny geometry detect edges in the image \-charcoal radius simulate a charcoal drawing \-chop geometry remove pixels from the image interior \-clamp keep pixel values in range (0-QuantumRange)