% MagickCore Image Effects Methods %
% %
% Software Design %
-% John Cristy %
+% Cristy %
% October 1996 %
% %
% %
-% Copyright 1999-2013 ImageMagick Studio LLC, a non-profit organization %
+% Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
#include "MagickCore/image-private.h"
#include "MagickCore/list.h"
#include "MagickCore/log.h"
+#include "MagickCore/matrix.h"
#include "MagickCore/memory_.h"
#include "MagickCore/memory-private.h"
#include "MagickCore/monitor.h"
#include "MagickCore/monitor-private.h"
#include "MagickCore/montage.h"
#include "MagickCore/morphology.h"
+#include "MagickCore/morphology-private.h"
#include "MagickCore/paint.h"
#include "MagickCore/pixel-accessor.h"
#include "MagickCore/pixel-private.h"
/*
Edge detect the image brighness channel, level, blur, and level again.
*/
- edge_image=EdgeImage(image,radius,sigma,exception);
+ edge_image=EdgeImage(image,radius,exception);
if (edge_image == (Image *) NULL)
{
blur_image=DestroyImage(blur_image);
return((Image *) NULL);
}
(void) AdaptiveLevelImage(edge_image,"20%,95%",exception);
- gaussian_image=GaussianBlurImage(edge_image,radius,sigma,exception);
+ gaussian_image=BlurImage(edge_image,radius,sigma,exception);
if (gaussian_image != (Image *) NULL)
{
edge_image=DestroyImage(edge_image);
if (kernel[i] == (MagickRealType *) NULL)
break;
normalize=0.0;
- j=(ssize_t) (width-i)/2;
+ j=(ssize_t) (width-i-1)/2;
k=0;
for (v=(-j); v <= j; v++)
{
k++;
}
}
- if (fabs(normalize) < MagickEpsilon)
- normalize=MagickEpsilon;
- normalize=PerceptibleReciprocal(normalize);
- for (k=0; k < (j*j); k++)
- kernel[i][k]=normalize*kernel[i][k];
+ kernel[i][(j-1)/2]+=(1.0-normalize);
+ if (sigma < MagickEpsilon)
+ kernel[i][(j-1)/2]=1.0;
}
if (i < (ssize_t) width)
{
(blur_traits == UndefinedPixelTrait))
continue;
if (((blur_traits & CopyPixelTrait) != 0) ||
- (GetPixelMask(image,p) != 0))
+ (GetPixelReadMask(image,p+center) == 0))
{
SetPixelChannel(blur_image,channel,p[center+i],q);
continue;
/*
Edge detect the image brighness channel, level, sharp, and level again.
*/
- edge_image=EdgeImage(image,radius,sigma,exception);
+ edge_image=EdgeImage(image,radius,exception);
if (edge_image == (Image *) NULL)
{
sharp_image=DestroyImage(sharp_image);
return((Image *) NULL);
}
(void) AdaptiveLevelImage(edge_image,"20%,95%",exception);
- gaussian_image=GaussianBlurImage(edge_image,radius,sigma,exception);
+ gaussian_image=BlurImage(edge_image,radius,sigma,exception);
if (gaussian_image != (Image *) NULL)
{
edge_image=DestroyImage(edge_image);
k++;
}
}
- if (fabs(normalize) < MagickEpsilon)
- normalize=MagickEpsilon;
- normalize=PerceptibleReciprocal(normalize);
- for (k=0; k < (j*j); k++)
- kernel[i][k]=normalize*kernel[i][k];
+ kernel[i][(k-1)/2]=(double) ((-2.0)*normalize);
+ if (sigma < MagickEpsilon)
+ kernel[i][(k-1)/2]=1.0;
}
if (i < (ssize_t) width)
{
center,
j;
- j=(ssize_t) ceil((double) width*QuantumScale*
- GetPixelIntensity(edge_image,r)-0.5);
+ j=(ssize_t) ceil((double) width*(1.0-QuantumScale*
+ GetPixelIntensity(edge_image,r))-0.5);
if (j < 0)
j=0;
else
(sharp_traits == UndefinedPixelTrait))
continue;
if (((sharp_traits & CopyPixelTrait) != 0) ||
- (GetPixelMask(image,p) != 0))
+ (GetPixelReadMask(image,p+center) == 0))
{
SetPixelChannel(sharp_image,channel,p[center+i],q);
continue;
% the radius should be larger than sigma. Use a radius of 0 and BlurImage()
% selects a suitable radius for you.
%
-% BlurImage() differs from GaussianBlurImage() in that it uses a separable
-% kernel which is faster but mathematically equivalent to the non-separable
-% kernel.
-%
% The format of the BlurImage method is:
%
% Image *BlurImage(const Image *image,const double radius,
% o exception: return any errors or warnings in this structure.
%
*/
+MagickExport Image *BlurImage(const Image *image,const double radius,
+ const double sigma,ExceptionInfo *exception)
+{
+ char
+ geometry[MaxTextExtent];
+
+ KernelInfo
+ *kernel_info;
+
+ Image
+ *blur_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");
+ blur_image=MorphologyApply(image,ConvolveMorphology,1,kernel_info,
+ UndefinedCompositeOp,0.0,exception);
+ kernel_info=DestroyKernelInfo(kernel_info);
+ return(blur_image);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% %
+% %
+% %
+% 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 lower_percent,
+% const double upper_percent,ExceptionInfo *exception)
+%
+% A description of each parameter follows:
+%
+% o image: the image.
+%
+% o radius: the radius of the gaussian smoothing filter.
+%
+% o sigma: the sigma of the gaussian smoothing filter.
+%
+% o lower_precent: percentage of edge pixels in the lower threshold.
+%
+% o upper_percent: percentage of edge pixels in the upper threshold.
+%
+% o exception: return any errors or warnings in this structure.
+%
+*/
-static MagickRealType *GetBlurKernel(const size_t width,const double sigma)
+typedef struct _CannyInfo
{
double
- normalize;
+ magnitude,
+ intensity;
- MagickRealType
- *kernel;
+ int
+ orientation;
+
+ ssize_t
+ x,
+ y;
+} CannyInfo;
+
+static inline MagickBooleanType IsAuthenticPixel(const Image *image,
+ const ssize_t x,const ssize_t y)
+{
+ if ((x < 0) || (x >= (ssize_t) image->columns))
+ return(MagickFalse);
+ if ((y < 0) || (y >= (ssize_t) image->rows))
+ return(MagickFalse);
+ return(MagickTrue);
+}
+
+static MagickBooleanType TraceEdges(Image *edge_image,CacheView *edge_view,
+ MatrixInfo *canny_cache,const ssize_t x,const ssize_t y,
+ const double lower_threshold,ExceptionInfo *exception)
+{
+ CannyInfo
+ edge,
+ pixel;
+
+ MagickBooleanType
+ status;
+
+ register Quantum
+ *q;
register ssize_t
i;
- ssize_t
- j,
- k;
-
- /*
- Generate a 1-D convolution kernel.
- */
- (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
- kernel=(MagickRealType *) MagickAssumeAligned(AcquireAlignedMemory((size_t)
- width,sizeof(*kernel)));
- if (kernel == (MagickRealType *) NULL)
- return(0);
- normalize=0.0;
- j=(ssize_t) width/2;
- i=0;
- for (k=(-j); k <= j; k++)
+ q=GetCacheViewAuthenticPixels(edge_view,x,y,1,1,exception);
+ if (q == (Quantum *) NULL)
+ return(MagickFalse);
+ *q=QuantumRange;
+ status=SyncCacheViewAuthenticPixels(edge_view,exception);
+ if (status == MagickFalse)
+ return(MagickFalse);;
+ if (GetMatrixElement(canny_cache,0,0,&edge) == MagickFalse)
+ return(MagickFalse);
+ edge.x=x;
+ edge.y=y;
+ if (SetMatrixElement(canny_cache,0,0,&edge) == MagickFalse)
+ return(MagickFalse);
+ for (i=1; i != 0; )
{
- kernel[i]=(MagickRealType) (exp(-((double) k*k)/(2.0*MagickSigma*
- MagickSigma))/(MagickSQ2PI*MagickSigma));
- normalize+=kernel[i];
- i++;
+ ssize_t
+ v;
+
+ i--;
+ status=GetMatrixElement(canny_cache,i,0,&edge);
+ if (status == MagickFalse)
+ return(MagickFalse);
+ for (v=(-1); v <= 1; v++)
+ {
+ ssize_t
+ u;
+
+ for (u=(-1); u <= 1; u++)
+ {
+ if ((u == 0) && (v == 0))
+ continue;
+ if (IsAuthenticPixel(edge_image,edge.x+u,edge.y+v) == MagickFalse)
+ continue;
+ /*
+ Not an edge if gradient value is below the lower threshold.
+ */
+ q=GetCacheViewAuthenticPixels(edge_view,edge.x+u,edge.y+v,1,1,
+ exception);
+ if (q == (Quantum *) NULL)
+ return(MagickFalse);
+ status=GetMatrixElement(canny_cache,edge.x+u,edge.y+v,&pixel);
+ if (status == MagickFalse)
+ return(MagickFalse);
+ if ((GetPixelIntensity(edge_image,q) == 0.0) &&
+ (pixel.intensity >= lower_threshold))
+ {
+ *q=QuantumRange;
+ status=SyncCacheViewAuthenticPixels(edge_view,exception);
+ if (status == MagickFalse)
+ return(MagickFalse);
+ edge.x+=u;
+ edge.y+=v;
+ status=SetMatrixElement(canny_cache,i,0,&edge);
+ if (status == MagickFalse)
+ return(MagickFalse);
+ i++;
+ }
+ }
+ }
}
- for (i=0; i < (ssize_t) width; i++)
- kernel[i]/=normalize;
- return(kernel);
+ return(MagickTrue);
}
-MagickExport Image *BlurImage(const Image *image,const double radius,
- const double sigma,ExceptionInfo *exception)
+MagickExport Image *CannyEdgeImage(const Image *image,const double radius,
+ const double sigma,const double lower_percent,const double upper_percent,
+ ExceptionInfo *exception)
{
-#define BlurImageTag "Blur/Image"
-
CacheView
- *blur_view,
- *image_view;
+ *edge_view;
- Image
- *blur_image;
+ CannyInfo
+ pixel;
- MagickBooleanType
- status;
+ char
+ geometry[MaxTextExtent];
- MagickOffsetType
- progress;
+ double
+ lower_threshold,
+ max,
+ min,
+ upper_threshold;
- MagickRealType
- *kernel;
+ Image
+ *edge_image;
- register ssize_t
- i;
+ KernelInfo
+ *kernel_info;
- size_t
- width;
+ MagickBooleanType
+ status;
+
+ MatrixInfo
+ *canny_cache;
ssize_t
- center,
- x,
y;
- /*
- Initialize blur image attributes.
- */
- assert(image != (Image *) NULL);
+ 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);
- blur_image=CloneImage(image,0,0,MagickTrue,exception);
- if (blur_image == (Image *) NULL)
+ /*
+ Filter out noise.
+ */
+ (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");
+ edge_image=MorphologyApply(image,ConvolveMorphology,1,kernel_info,
+ UndefinedCompositeOp,0.0,exception);
+ kernel_info=DestroyKernelInfo(kernel_info);
+ if (edge_image == (Image *) NULL)
return((Image *) NULL);
- if (fabs(sigma) < MagickEpsilon)
- return(blur_image);
- if (SetImageStorageClass(blur_image,DirectClass,exception) == MagickFalse)
+ if (SetImageColorspace(edge_image,GRAYColorspace,exception) == MagickFalse)
{
- blur_image=DestroyImage(blur_image);
+ edge_image=DestroyImage(edge_image);
return((Image *) NULL);
}
- width=GetOptimalKernelWidth1D(radius,sigma);
- kernel=GetBlurKernel(width,sigma);
- if (kernel == (MagickRealType *) NULL)
- {
- blur_image=DestroyImage(blur_image);
- ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
- }
- if (image->debug != MagickFalse)
- {
- char
- format[MaxTextExtent],
- *message;
-
- register const MagickRealType
- *k;
-
- (void) LogMagickEvent(TransformEvent,GetMagickModule(),
- " blur image with kernel width %.20g:",(double) width);
- message=AcquireString("");
- k=kernel;
- for (i=0; i < (ssize_t) width; i++)
- {
- *message='\0';
- (void) FormatLocaleString(format,MaxTextExtent,"%.20g: ",(double) i);
- (void) ConcatenateString(&message,format);
- (void) FormatLocaleString(format,MaxTextExtent,"%g ",(double) *k++);
- (void) ConcatenateString(&message,format);
- (void) LogMagickEvent(TransformEvent,GetMagickModule(),"%s",message);
- }
- message=DestroyString(message);
- }
/*
- Blur rows.
+ Find the intensity gradient of the image.
*/
+ canny_cache=AcquireMatrixInfo(edge_image->columns,edge_image->rows,
+ sizeof(CannyInfo),exception);
+ if (canny_cache == (MatrixInfo *) NULL)
+ {
+ edge_image=DestroyImage(edge_image);
+ return((Image *) NULL);
+ }
status=MagickTrue;
- progress=0;
- center=(ssize_t) GetPixelChannels(image)*(width/2L);
- image_view=AcquireVirtualCacheView(image,exception);
- blur_view=AcquireAuthenticCacheView(blur_image,exception);
+ edge_view=AcquireVirtualCacheView(edge_image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp parallel for schedule(static,4) shared(progress,status) \
- magick_threads(image,blur_image,image->rows,1)
+ #pragma omp parallel for schedule(static,4) shared(status) \
+ magick_threads(edge_image,edge_image,edge_image->rows,1)
#endif
- for (y=0; y < (ssize_t) image->rows; y++)
+ for (y=0; y < (ssize_t) edge_image->rows; y++)
{
register const Quantum
*restrict p;
- register Quantum
- *restrict q;
-
register ssize_t
x;
if (status == MagickFalse)
continue;
- p=GetCacheViewVirtualPixels(image_view,-((ssize_t) width/2L),y,
- image->columns+width,1,exception);
- q=QueueCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
+ p=GetCacheViewVirtualPixels(edge_view,0,y,edge_image->columns+1,2,
exception);
- if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
+ if (p == (const Quantum *) NULL)
{
status=MagickFalse;
continue;
}
- for (x=0; x < (ssize_t) image->columns; x++)
+ for (x=0; x < (ssize_t) edge_image->columns; x++)
{
- register ssize_t
- i;
+ CannyInfo
+ pixel;
- for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
- {
- double
- alpha,
- gamma,
- pixel;
-
- PixelChannel
- channel;
+ double
+ dx,
+ dy;
- PixelTrait
- blur_traits,
- traits;
+ register const Quantum
+ *restrict kernel_pixels;
- register const MagickRealType
- *restrict k;
+ ssize_t
+ v;
- register const Quantum
- *restrict pixels;
+ static double
+ Gx[2][2] =
+ {
+ { -1.0, +1.0 },
+ { -1.0, +1.0 }
+ },
+ Gy[2][2] =
+ {
+ { +1.0, +1.0 },
+ { -1.0, -1.0 }
+ };
- register ssize_t
+ (void) ResetMagickMemory(&pixel,0,sizeof(pixel));
+ dx=0.0;
+ dy=0.0;
+ kernel_pixels=p;
+ for (v=0; v < 2; v++)
+ {
+ ssize_t
u;
- channel=GetPixelChannelChannel(image,i);
- traits=GetPixelChannelTraits(image,channel);
- blur_traits=GetPixelChannelTraits(blur_image,channel);
- if ((traits == UndefinedPixelTrait) ||
- (blur_traits == UndefinedPixelTrait))
- continue;
- if (((blur_traits & CopyPixelTrait) != 0) ||
- (GetPixelMask(image,p) != 0))
- {
- SetPixelChannel(blur_image,channel,p[center+i],q);
- continue;
- }
- k=kernel;
- pixels=p;
- pixel=0.0;
- if ((blur_traits & BlendPixelTrait) == 0)
- {
- /*
- No alpha blending.
- */
- for (u=0; u < (ssize_t) width; u++)
- {
- pixel+=(*k)*pixels[i];
- k++;
- pixels+=GetPixelChannels(image);
- }
- SetPixelChannel(blur_image,channel,ClampToQuantum(pixel),q);
- continue;
- }
- /*
- Alpha blending.
- */
- gamma=0.0;
- for (u=0; u < (ssize_t) width; u++)
+ for (u=0; u < 2; u++)
{
- alpha=(double) (QuantumScale*GetPixelAlpha(image,pixels));
- pixel+=(*k)*alpha*pixels[i];
- gamma+=(*k)*alpha;
- k++;
- pixels+=GetPixelChannels(image);
+ double
+ intensity;
+
+ intensity=GetPixelIntensity(edge_image,kernel_pixels+u);
+ dx+=0.5*Gx[v][u]*intensity;
+ dy+=0.5*Gy[v][u]*intensity;
}
- gamma=PerceptibleReciprocal(gamma);
- SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
+ kernel_pixels+=edge_image->columns+1;
}
- p+=GetPixelChannels(image);
- q+=GetPixelChannels(blur_image);
- }
- if (SyncCacheViewAuthenticPixels(blur_view,exception) == MagickFalse)
- status=MagickFalse;
- if (image->progress_monitor != (MagickProgressMonitor) NULL)
- {
- MagickBooleanType
- proceed;
+ pixel.magnitude=hypot(dx,dy);
+ pixel.orientation=0;
+ if (fabs(dx) > MagickEpsilon)
+ {
+ double
+ slope;
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp critical (MagickCore_BlurImage)
-#endif
- proceed=SetImageProgress(image,BlurImageTag,progress++,blur_image->rows+
- blur_image->columns);
- if (proceed == MagickFalse)
- status=MagickFalse;
- }
+ slope=dy/dx;
+ if (slope < 0.0)
+ {
+ if (slope < -2.41421356237)
+ pixel.orientation=0;
+ else
+ if (slope < -0.414213562373)
+ pixel.orientation=1;
+ else
+ pixel.orientation=2;
+ }
+ else
+ {
+ if (slope > 2.41421356237)
+ pixel.orientation=0;
+ else
+ if (slope > 0.414213562373)
+ pixel.orientation=3;
+ else
+ pixel.orientation=2;
+ }
+ }
+ if (SetMatrixElement(canny_cache,x,y,&pixel) == MagickFalse)
+ continue;
+ p+=GetPixelChannels(edge_image);
+ }
}
- blur_view=DestroyCacheView(blur_view);
- image_view=DestroyCacheView(image_view);
+ edge_view=DestroyCacheView(edge_view);
/*
- Blur columns.
+ Non-maxima suppression, remove pixels that are not considered to be part
+ of an edge.
*/
- center=(ssize_t) GetPixelChannels(blur_image)*(width/2L);
- image_view=AcquireVirtualCacheView(blur_image,exception);
- blur_view=AcquireAuthenticCacheView(blur_image,exception);
+ (void) GetMatrixElement(canny_cache,0,0,&pixel);
+ max=pixel.intensity;
+ min=pixel.intensity;
+ edge_view=AcquireAuthenticCacheView(edge_image,exception);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp parallel for schedule(static,4) shared(progress,status) \
- magick_threads(image,blur_image,image->columns,1)
+ #pragma omp parallel for schedule(static,4) shared(status) \
+ magick_threads(edge_image,edge_image,edge_image->rows,1)
#endif
- for (x=0; x < (ssize_t) blur_image->columns; x++)
+ for (y=0; y < (ssize_t) edge_image->rows; y++)
{
- register const Quantum
- *restrict p;
-
register Quantum
*restrict q;
register ssize_t
- y;
+ x;
if (status == MagickFalse)
continue;
- p=GetCacheViewVirtualPixels(image_view,x,-((ssize_t) width/2L),1,
- blur_image->rows+width,exception);
- q=GetCacheViewAuthenticPixels(blur_view,x,0,1,blur_image->rows,exception);
- if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
+ q=GetCacheViewAuthenticPixels(edge_view,0,y,edge_image->columns,1,
+ exception);
+ if (q == (Quantum *) NULL)
{
status=MagickFalse;
continue;
}
- for (y=0; y < (ssize_t) blur_image->rows; y++)
+ for (x=0; x < (ssize_t) edge_image->columns; x++)
{
- register ssize_t
- i;
+ CannyInfo
+ alpha_pixel,
+ beta_pixel,
+ pixel;
- for (i=0; i < (ssize_t) GetPixelChannels(blur_image); i++)
+ (void) GetMatrixElement(canny_cache,x,y,&pixel);
+ switch (pixel.orientation)
{
- double
- alpha,
- gamma,
- pixel;
-
- PixelChannel
- channel;
-
- PixelTrait
- blur_traits,
- traits;
-
- register const MagickRealType
- *restrict k;
-
- register const Quantum
- *restrict pixels;
-
- register ssize_t
- u;
-
- channel=GetPixelChannelChannel(blur_image,i);
- traits=GetPixelChannelTraits(blur_image,channel);
- blur_traits=GetPixelChannelTraits(blur_image,channel);
- if ((traits == UndefinedPixelTrait) ||
- (blur_traits == UndefinedPixelTrait))
- continue;
- if (((blur_traits & CopyPixelTrait) != 0) ||
- (GetPixelMask(image,p) != 0))
- {
- SetPixelChannel(blur_image,channel,p[center+i],q);
- continue;
- }
- k=kernel;
- pixels=p;
- pixel=0.0;
- if ((blur_traits & BlendPixelTrait) == 0)
- {
- /*
- No alpha blending.
- */
- for (u=0; u < (ssize_t) width; u++)
- {
- pixel+=(*k)*pixels[i];
- k++;
- pixels+=GetPixelChannels(blur_image);
- }
- SetPixelChannel(blur_image,channel,ClampToQuantum(pixel),q);
- continue;
- }
- /*
- Alpha blending.
- */
- gamma=0.0;
- for (u=0; u < (ssize_t) width; u++)
+ case 0:
{
- alpha=(double) (QuantumScale*GetPixelAlpha(blur_image,
- pixels));
- pixel+=(*k)*alpha*pixels[i];
- gamma+=(*k)*alpha;
- k++;
- pixels+=GetPixelChannels(blur_image);
+ /*
+ 0 degrees, north and south.
+ */
+ (void) GetMatrixElement(canny_cache,x,y-1,&alpha_pixel);
+ (void) GetMatrixElement(canny_cache,x,y+1,&beta_pixel);
+ break;
+ }
+ case 1:
+ {
+ /*
+ 45 degrees, northwest and southeast.
+ */
+ (void) GetMatrixElement(canny_cache,x-1,y-1,&alpha_pixel);
+ (void) GetMatrixElement(canny_cache,x+1,y+1,&beta_pixel);
+ break;
+ }
+ case 2:
+ {
+ /*
+ 90 degrees, east and west.
+ */
+ (void) GetMatrixElement(canny_cache,x-1,y,&alpha_pixel);
+ (void) GetMatrixElement(canny_cache,x+1,y,&beta_pixel);
+ break;
+ }
+ case 3:
+ {
+ /*
+ 135 degrees, northeast and southwest.
+ */
+ (void) GetMatrixElement(canny_cache,x+1,y-1,&beta_pixel);
+ (void) GetMatrixElement(canny_cache,x-1,y+1,&alpha_pixel);
+ break;
}
- gamma=PerceptibleReciprocal(gamma);
- SetPixelChannel(blur_image,channel,ClampToQuantum(gamma*pixel),q);
}
- p+=GetPixelChannels(blur_image);
- q+=GetPixelChannels(blur_image);
- }
- if (SyncCacheViewAuthenticPixels(blur_view,exception) == MagickFalse)
- status=MagickFalse;
- if (blur_image->progress_monitor != (MagickProgressMonitor) NULL)
- {
- MagickBooleanType
- proceed;
-
+ pixel.intensity=pixel.magnitude;
+ if ((pixel.magnitude < alpha_pixel.magnitude) ||
+ (pixel.magnitude < beta_pixel.magnitude))
+ pixel.intensity=0;
+ (void) SetMatrixElement(canny_cache,x,y,&pixel);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp critical (MagickCore_BlurImage)
+ #pragma omp critical (MagickCore_CannyEdgeImage)
#endif
- proceed=SetImageProgress(blur_image,BlurImageTag,progress++,
- blur_image->rows+blur_image->columns);
- if (proceed == MagickFalse)
- status=MagickFalse;
+ {
+ if (pixel.intensity < min)
+ min=pixel.intensity;
+ if (pixel.intensity > max)
+ max=pixel.intensity;
}
+ *q=0;
+ q+=GetPixelChannels(edge_image);
+ }
+ if (SyncCacheViewAuthenticPixels(edge_view,exception) == MagickFalse)
+ status=MagickFalse;
}
- blur_view=DestroyCacheView(blur_view);
- image_view=DestroyCacheView(image_view);
- kernel=(MagickRealType *) RelinquishAlignedMemory(kernel);
- blur_image->type=image->type;
- if (status == MagickFalse)
- blur_image=DestroyImage(blur_image);
- return(blur_image);
+ edge_view=DestroyCacheView(edge_view);
+ /*
+ Estimate hysteresis threshold.
+ */
+ lower_threshold=lower_percent*(max-min)+min;
+ upper_threshold=upper_percent*(max-min)+min;
+ /*
+ Hysteresis threshold.
+ */
+ edge_view=AcquireAuthenticCacheView(edge_image,exception);
+ for (y=0; y < (ssize_t) edge_image->rows; y++)
+ {
+ register ssize_t
+ x;
+
+ if (status == MagickFalse)
+ continue;
+ for (x=0; x < (ssize_t) edge_image->columns; x++)
+ {
+ CannyInfo
+ pixel;
+
+ register const Quantum
+ *restrict p;
+
+ /*
+ Edge if pixel gradient higher than upper threshold.
+ */
+ p=GetCacheViewVirtualPixels(edge_view,x,y,1,1,exception);
+ if (p == (const Quantum *) NULL)
+ continue;
+ status=GetMatrixElement(canny_cache,x,y,&pixel);
+ if (status == MagickFalse)
+ continue;
+ if ((GetPixelIntensity(edge_image,p) == 0.0) &&
+ (pixel.intensity >= upper_threshold))
+ status=TraceEdges(edge_image,edge_view,canny_cache,x,y,lower_threshold,
+ exception);
+ }
+ }
+ edge_view=DestroyCacheView(edge_view);
+ /*
+ Free resources.
+ */
+ canny_cache=DestroyMatrixInfo(canny_cache);
+ return(edge_image);
}
\f
/*
MagickExport Image *ConvolveImage(const Image *image,
const KernelInfo *kernel_info,ExceptionInfo *exception)
{
- return(MorphologyImage(image,CorrelateMorphology,1,kernel_info,exception));
+ Image
+ *convolve_image;
+
+ convolve_image=MorphologyApply(image,ConvolveMorphology,1,kernel_info,
+ UndefinedCompositeOp,0.0,exception);
+ return(convolve_image);
}
\f
/*
ssize_t
y;
+ assert(image != (const Image *) NULL);
+ assert(image->signature == MagickSignature);
+ if (image->debug != MagickFalse)
+ (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(f != (Quantum *) NULL);
assert(g != (Quantum *) NULL);
p=f+(columns+2);
r=p+(y_offset*(columns+2)+x_offset);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) \
- magick_threads(image,image,rows,1)
+ magick_threads(image,image,1,1)
#endif
for (y=0; y < (ssize_t) rows; y++)
{
s=q-(y_offset*(columns+2)+x_offset);
#if defined(MAGICKCORE_OPENMP_SUPPORT)
#pragma omp parallel for schedule(static,4) \
- magick_threads(image,image,rows,1)
+ magick_threads(image,image,1,1)
#endif
for (y=0; y < (ssize_t) rows; y++)
{
MagickBooleanType
status;
+ MemoryInfo
+ *buffer_info,
+ *pixel_info;
+
Quantum
*restrict buffer,
*restrict pixels;
Allocate image buffer.
*/
length=(size_t) ((image->columns+2)*(image->rows+2));
- pixels=(Quantum *) AcquireQuantumMemory(length,sizeof(*pixels));
- buffer=(Quantum *) AcquireQuantumMemory(length,sizeof(*buffer));
- if ((pixels == (Quantum *) NULL) || (buffer == (Quantum *) NULL))
+ pixel_info=AcquireVirtualMemory(length,sizeof(*pixels));
+ buffer_info=AcquireVirtualMemory(length,sizeof(*buffer));
+ if ((pixel_info == (MemoryInfo *) NULL) ||
+ (buffer_info == (MemoryInfo *) NULL))
{
- if (buffer != (Quantum *) NULL)
- buffer=(Quantum *) RelinquishMagickMemory(buffer);
- if (pixels != (Quantum *) NULL)
- pixels=(Quantum *) RelinquishMagickMemory(pixels);
+ if (buffer_info != (MemoryInfo *) NULL)
+ buffer_info=RelinquishVirtualMemory(buffer_info);
+ if (pixel_info != (MemoryInfo *) NULL)
+ pixel_info=RelinquishVirtualMemory(pixel_info);
despeckle_image=DestroyImage(despeckle_image);
ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
}
+ pixels=(Quantum *) GetVirtualMemoryBlob(pixel_info);
+ buffer=(Quantum *) GetVirtualMemoryBlob(buffer_info);
/*
Reduce speckle in the image.
*/
register Quantum
*restrict q;
- q=QueueCacheViewAuthenticPixels(despeckle_view,0,y,
- despeckle_image->columns,1,exception);
+ q=GetCacheViewAuthenticPixels(despeckle_view,0,y,despeckle_image->columns,
+ 1,exception);
if (q == (Quantum *) NULL)
{
status=MagickFalse;
}
despeckle_view=DestroyCacheView(despeckle_view);
image_view=DestroyCacheView(image_view);
- buffer=(Quantum *) RelinquishMagickMemory(buffer);
- pixels=(Quantum *) RelinquishMagickMemory(pixels);
+ buffer_info=RelinquishVirtualMemory(buffer_info);
+ pixel_info=RelinquishVirtualMemory(pixel_info);
despeckle_image->type=image->type;
if (status == MagickFalse)
despeckle_image=DestroyImage(despeckle_image);
% The format of the EdgeImage method is:
%
% Image *EdgeImage(const Image *image,const double radius,
-% const double sigma,ExceptionInfo *exception)
+% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
%
% o radius: the radius of the pixel neighborhood.
%
-% o sigma: the standard deviation of the Gaussian, in pixels.
-%
% o exception: return any errors or warnings in this structure.
%
*/
MagickExport Image *EdgeImage(const Image *image,const double radius,
- const double sigma,ExceptionInfo *exception)
+ ExceptionInfo *exception)
{
Image
*edge_image;
size_t
width;
- ssize_t
- j,
- u,
- v;
-
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);
- width=GetOptimalKernelWidth1D(radius,sigma);
+ width=GetOptimalKernelWidth1D(radius,0.5);
kernel_info=AcquireKernelInfo((const char *) NULL);
if (kernel_info == (KernelInfo *) NULL)
ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
+ (void) ResetMagickMemory(kernel_info,0,sizeof(*kernel_info));
kernel_info->width=width;
kernel_info->height=width;
+ kernel_info->x=(ssize_t) (kernel_info->width-1)/2;
+ kernel_info->y=(ssize_t) (kernel_info->height-1)/2;
+ kernel_info->signature=MagickSignature;
kernel_info->values=(MagickRealType *) MagickAssumeAligned(
- AcquireAlignedMemory(kernel_info->width,kernel_info->width*
+ AcquireAlignedMemory(kernel_info->width,kernel_info->height*
sizeof(*kernel_info->values)));
if (kernel_info->values == (MagickRealType *) NULL)
{
kernel_info=DestroyKernelInfo(kernel_info);
ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
}
- j=(ssize_t) kernel_info->width/2;
- i=0;
- for (v=(-j); v <= j; v++)
- {
- for (u=(-j); u <= j; u++)
- {
- kernel_info->values[i]=(MagickRealType) (-1.0);
- i++;
- }
- }
- kernel_info->values[i/2]=(MagickRealType) (width*width-1.0);
- edge_image=ConvolveImage(image,kernel_info,exception);
+ for (i=0; i < (ssize_t) (kernel_info->width*kernel_info->height); i++)
+ kernel_info->values[i]=(-1.0);
+ kernel_info->values[i/2]=(double) kernel_info->width*kernel_info->height-1.0;
+ edge_image=MorphologyApply(image,ConvolveMorphology,1,kernel_info,
+ UndefinedCompositeOp,0.0,exception);
kernel_info=DestroyKernelInfo(kernel_info);
return(edge_image);
}
MagickExport Image *EmbossImage(const Image *image,const double radius,
const double sigma,ExceptionInfo *exception)
{
+ double
+ gamma,
+ normalize;
+
Image
*emboss_image;
ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
kernel_info->width=width;
kernel_info->height=width;
+ kernel_info->x=(ssize_t) (width-1)/2;
+ kernel_info->y=(ssize_t) (width-1)/2;
kernel_info->values=(MagickRealType *) MagickAssumeAligned(
AcquireAlignedMemory(kernel_info->width,kernel_info->width*
sizeof(*kernel_info->values)));
kernel_info=DestroyKernelInfo(kernel_info);
ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
}
- j=(ssize_t) kernel_info->width/2;
+ j=(ssize_t) (kernel_info->width-1)/2;
k=j;
i=0;
for (v=(-j); v <= j; v++)
}
k--;
}
- emboss_image=ConvolveImage(image,kernel_info,exception);
+ normalize=0.0;
+ for (i=0; i < (ssize_t) (kernel_info->width*kernel_info->height); i++)
+ normalize+=kernel_info->values[i];
+ gamma=PerceptibleReciprocal(normalize);
+ for (i=0; i < (ssize_t) (kernel_info->width*kernel_info->height); i++)
+ kernel_info->values[i]*=gamma;
+ emboss_image=MorphologyApply(image,ConvolveMorphology,1,kernel_info,
+ UndefinedCompositeOp,0.0,exception);
kernel_info=DestroyKernelInfo(kernel_info);
if (emboss_image != (Image *) NULL)
(void) EqualizeImage(emboss_image,exception);
MagickExport Image *GaussianBlurImage(const Image *image,const double radius,
const double sigma,ExceptionInfo *exception)
{
- Image
- *blur_image;
+ char
+ geometry[MaxTextExtent];
KernelInfo
*kernel_info;
- register ssize_t
- i;
-
- size_t
- width;
-
- ssize_t
- j,
- u,
- v;
+ Image
+ *blur_image;
assert(image != (const Image *) NULL);
assert(image->signature == MagickSignature);
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
- width=GetOptimalKernelWidth2D(radius,sigma);
- kernel_info=AcquireKernelInfo((const char *) NULL);
+ (void) FormatLocaleString(geometry,MaxTextExtent,"gaussian:%.20gx%.20g",
+ radius,sigma);
+ kernel_info=AcquireKernelInfo(geometry);
if (kernel_info == (KernelInfo *) NULL)
ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
- (void) ResetMagickMemory(kernel_info,0,sizeof(*kernel_info));
- kernel_info->width=width;
- kernel_info->height=width;
- kernel_info->signature=MagickSignature;
- kernel_info->values=(MagickRealType *) MagickAssumeAligned(
- AcquireAlignedMemory(kernel_info->width,kernel_info->width*
- sizeof(*kernel_info->values)));
- if (kernel_info->values == (MagickRealType *) NULL)
- {
- kernel_info=DestroyKernelInfo(kernel_info);
- ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
- }
- j=(ssize_t) kernel_info->width/2;
- i=0;
- for (v=(-j); v <= j; v++)
- {
- for (u=(-j); u <= j; u++)
- {
- kernel_info->values[i]=(MagickRealType) (exp(-((double) u*u+v*v)/(2.0*
- MagickSigma*MagickSigma))/(2.0*MagickPI*MagickSigma*MagickSigma));
- i++;
- }
- }
- blur_image=ConvolveImage(image,kernel_info,exception);
+ blur_image=MorphologyApply(image,ConvolveMorphology,1,kernel_info,
+ UndefinedCompositeOp,0.0,exception);
kernel_info=DestroyKernelInfo(kernel_info);
return(blur_image);
}
MagickExport Image *MotionBlurImage(const Image *image,const double radius,
const double sigma,const double angle,ExceptionInfo *exception)
{
+#define BlurImageTag "Blur/Image"
+
CacheView
*blur_view,
*image_view,
(blur_traits == UndefinedPixelTrait))
continue;
if (((blur_traits & CopyPixelTrait) != 0) ||
- (GetPixelMask(image,p) != 0))
+ (GetPixelReadMask(image,p) == 0))
{
SetPixelChannel(blur_image,channel,p[i],q);
continue;
{
degrees+=5.0;
preview_image=ShearImage(thumbnail,degrees,degrees,exception);
- (void) FormatLocaleString(label,MaxTextExtent,"shear %gx%g",
- degrees,2.0*degrees);
+ (void) FormatLocaleString(label,MaxTextExtent,"shear %gx%g",degrees,
+ 2.0*degrees);
break;
}
case RollPreview:
preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
if (preview_image == (Image *) NULL)
break;
- (void) FormatLocaleString(factor,MaxTextExtent,"100,100,%g",
- 2.0*percentage);
+ (void) FormatLocaleString(factor,MaxTextExtent,"100,100,%g",2.0*
+ percentage);
(void) ModulateImage(preview_image,factor,exception);
(void) FormatLocaleString(label,MaxTextExtent,"modulate %s",factor);
break;
preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
if (preview_image == (Image *) NULL)
break;
- (void) FormatLocaleString(factor,MaxTextExtent,"100,%g",
- 2.0*percentage);
+ (void) FormatLocaleString(factor,MaxTextExtent,"100,%g",2.0*percentage);
(void) ModulateImage(preview_image,factor,exception);
(void) FormatLocaleString(label,MaxTextExtent,"modulate %s",factor);
break;
case SharpenPreview:
{
preview_image=SharpenImage(thumbnail,radius,sigma,exception);
- (void) FormatLocaleString(label,MaxTextExtent,"sharpen %gx%g",
- radius,sigma);
+ (void) FormatLocaleString(label,MaxTextExtent,"sharpen %gx%g",radius,
+ sigma);
break;
}
case BlurPreview:
break;
(void) BilevelImage(thumbnail,(double) (percentage*((double)
QuantumRange+1.0))/100.0,exception);
- (void) FormatLocaleString(label,MaxTextExtent,"threshold %g",
- (double) (percentage*((double) QuantumRange+1.0))/100.0);
+ (void) FormatLocaleString(label,MaxTextExtent,"threshold %g",(double)
+ (percentage*((double) QuantumRange+1.0))/100.0);
break;
}
case EdgeDetectPreview:
{
- preview_image=EdgeImage(thumbnail,radius,sigma,exception);
+ preview_image=EdgeImage(thumbnail,radius,exception);
(void) FormatLocaleString(label,MaxTextExtent,"edge %g",radius);
break;
}
{
preview_image=SpreadImage(thumbnail,radius,thumbnail->interpolate,
exception);
- (void) FormatLocaleString(label,MaxTextExtent,"spread %g",
- radius+0.5);
+ (void) FormatLocaleString(label,MaxTextExtent,"spread %g",radius+0.5);
break;
}
case SolarizePreview:
preview_image=CloneImage(thumbnail,0,0,MagickTrue,exception);
if (preview_image == (Image *) NULL)
break;
- (void) SolarizeImage(preview_image,(double) QuantumRange*
- percentage/100.0,exception);
+ (void) SolarizeImage(preview_image,(double) QuantumRange*percentage/
+ 100.0,exception);
(void) FormatLocaleString(label,MaxTextExtent,"solarize %g",
(QuantumRange*percentage)/100.0);
break;
degrees+=10.0;
preview_image=ShadeImage(thumbnail,MagickTrue,degrees,degrees,
exception);
- (void) FormatLocaleString(label,MaxTextExtent,"shade %gx%g",
- degrees,degrees);
+ (void) FormatLocaleString(label,MaxTextExtent,"shade %gx%g",degrees,
+ degrees);
break;
}
case RaisePreview:
break;
geometry.width=(size_t) (2*i+2);
geometry.height=(size_t) (2*i+2);
- geometry.x=i/2;
- geometry.y=i/2;
+ geometry.x=(i-1)/2;
+ geometry.y=(i-1)/2;
(void) RaiseImage(preview_image,&geometry,MagickTrue,exception);
(void) FormatLocaleString(label,MaxTextExtent,
"raise %.20gx%.20g%+.20g%+.20g",(double) geometry.width,(double)
degrees+=5.0f;
preview_image=WaveImage(thumbnail,0.5*degrees,2.0*degrees,
image->interpolate,exception);
- (void) FormatLocaleString(label,MaxTextExtent,"wave %gx%g",
- 0.5*degrees,2.0*degrees);
+ (void) FormatLocaleString(label,MaxTextExtent,"wave %gx%g",0.5*degrees,
+ 2.0*degrees);
break;
}
case OilPaintPreview:
{
preview_image=OilPaintImage(thumbnail,(double) radius,(double) sigma,
exception);
- (void) FormatLocaleString(label,MaxTextExtent,"charcoal %gx%g",
- radius,sigma);
+ (void) FormatLocaleString(label,MaxTextExtent,"charcoal %gx%g",radius,
+ sigma);
break;
}
case CharcoalDrawingPreview:
{
preview_image=CharcoalImage(thumbnail,(double) radius,(double) sigma,
exception);
- (void) FormatLocaleString(label,MaxTextExtent,"charcoal %gx%g",
- radius,sigma);
+ (void) FormatLocaleString(label,MaxTextExtent,"charcoal %gx%g",radius,
+ sigma);
break;
}
case JPEGPreview:
% %
% %
% %
-% R a d i a l B l u r I m a g e %
+% R o t a t i o n a l B l u r I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
-% RadialBlurImage() applies a radial blur to the image.
+% RotationalBlurImage() applies a radial blur to the image.
%
% Andrew Protano contributed this effect.
%
-% The format of the RadialBlurImage method is:
+% The format of the RotationalBlurImage method is:
%
-% Image *RadialBlurImage(const Image *image,const double angle,
+% Image *RotationalBlurImage(const Image *image,const double angle,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
% o exception: return any errors or warnings in this structure.
%
*/
-MagickExport Image *RadialBlurImage(const Image *image,const double angle,
+MagickExport Image *RotationalBlurImage(const Image *image,const double angle,
ExceptionInfo *exception)
{
CacheView
blur_image=DestroyImage(blur_image);
return((Image *) NULL);
}
- blur_center.x=(double) image->columns/2.0;
- blur_center.y=(double) image->rows/2.0;
+ blur_center.x=(double) (image->columns-1)/2.0;
+ blur_center.y=(double) (image->rows-1)/2.0;
blur_radius=hypot(blur_center.x,blur_center.y);
n=(size_t) fabs(4.0*DegreesToRadians(angle)*sqrt((double) blur_radius)+2UL);
theta=DegreesToRadians(angle)/(double) (n-1);
(blur_traits == UndefinedPixelTrait))
continue;
if (((blur_traits & CopyPixelTrait) != 0) ||
- (GetPixelMask(image,p) != 0))
+ (GetPixelReadMask(image,p) == 0))
{
SetPixelChannel(blur_image,channel,p[i],q);
continue;
proceed;
#if defined(MAGICKCORE_OPENMP_SUPPORT)
- #pragma omp critical (MagickCore_RadialBlurImage)
+ #pragma omp critical (MagickCore_RotationalBlurImage)
#endif
proceed=SetImageProgress(image,BlurImageTag,progress++,image->rows);
if (proceed == MagickFalse)
width,width*sizeof(*kernel)));
if (kernel == (MagickRealType *) NULL)
ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
- j=(ssize_t) width/2;
+ j=(ssize_t) (width-1)/2;
i=0;
for (v=(-j); v <= j; v++)
{
*/
status=MagickTrue;
progress=0;
- center=(ssize_t) (GetPixelChannels(image)*(image->columns+width)*(width/2L)+
- GetPixelChannels(image)*(width/2L));
+ center=(ssize_t) (GetPixelChannels(image)*(image->columns+width)*
+ ((width-1)/2L)+GetPixelChannels(image)*((width-1)/2L));
image_view=AcquireVirtualCacheView(image,exception);
luminance_view=AcquireVirtualCacheView(luminance_image,exception);
blur_view=AcquireAuthenticCacheView(blur_image,exception);
if (status == MagickFalse)
continue;
- p=GetCacheViewVirtualPixels(image_view,-((ssize_t) width/2L),y-(ssize_t)
- (width/2L),image->columns+width,width,exception);
- l=GetCacheViewVirtualPixels(luminance_view,-((ssize_t) width/2L),y-(ssize_t)
- (width/2L),luminance_image->columns+width,width,exception);
+ p=GetCacheViewVirtualPixels(image_view,-((ssize_t) (width-1)/2L),y-(ssize_t)
+ ((width-1)/2L),image->columns+width,width,exception);
+ l=GetCacheViewVirtualPixels(luminance_view,-((ssize_t) (width-1)/2L),y-
+ (ssize_t) ((width-1)/2L),luminance_image->columns+width,width,exception);
q=QueueCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
exception);
if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
(blur_traits == UndefinedPixelTrait))
continue;
if (((blur_traits & CopyPixelTrait) != 0) ||
- (GetPixelMask(image,p) != 0))
+ (GetPixelReadMask(image,p+center) == 0))
{
SetPixelChannel(blur_image,channel,p[center+i],q);
continue;
pixels+=GetPixelChannels(image);
luminance_pixels+=GetPixelChannels(luminance_image);
}
- pixels+=image->columns*GetPixelChannels(image);
+ pixels+=(image->columns-1)*GetPixelChannels(image);
luminance_pixels+=luminance_image->columns*
GetPixelChannels(luminance_image);
}
contrast=GetPixelIntensity(image,pixels)-intensity;
if (fabs(contrast) < threshold)
{
- alpha=(double) (QuantumScale*
- GetPixelAlpha(image,pixels));
+ alpha=(double) (QuantumScale*GetPixelAlpha(image,pixels));
pixel+=(*k)*alpha*pixels[i];
gamma+=(*k)*alpha;
}
pixels+=GetPixelChannels(image);
luminance_pixels+=GetPixelChannels(luminance_image);
}
- pixels+=image->columns*GetPixelChannels(image);
+ pixels+=(image->columns-1)*GetPixelChannels(image);
luminance_pixels+=luminance_image->columns*
GetPixelChannels(luminance_image);
}
shade_image=DestroyImage(shade_image);
return((Image *) NULL);
}
- if (image->colorspace == sRGBColorspace)
- (void) TransformImageColorspace(linear_image,RGBColorspace,exception);
if (SetImageStorageClass(shade_image,DirectClass,exception) == MagickFalse)
{
linear_image=DestroyImage(linear_image);
(shade_traits == UndefinedPixelTrait))
continue;
if (((shade_traits & CopyPixelTrait) != 0) ||
- (GetPixelMask(linear_image,p) != 0))
+ (GetPixelReadMask(linear_image,center) == 0))
{
SetPixelChannel(shade_image,channel,center[i],q);
continue;
shade_view=DestroyCacheView(shade_view);
image_view=DestroyCacheView(image_view);
linear_image=DestroyImage(linear_image);
- if (image->colorspace == sRGBColorspace)
- (void) TransformImageColorspace(shade_image,sRGBColorspace,exception);
if (status == MagickFalse)
shade_image=DestroyImage(shade_image);
return(shade_image);
const double sigma,ExceptionInfo *exception)
{
double
+ gamma,
normalize;
Image
(void) ResetMagickMemory(kernel_info,0,sizeof(*kernel_info));
kernel_info->width=width;
kernel_info->height=width;
+ kernel_info->x=(ssize_t) (width-1)/2;
+ kernel_info->y=(ssize_t) (width-1)/2;
kernel_info->signature=MagickSignature;
kernel_info->values=(MagickRealType *) MagickAssumeAligned(
- AcquireAlignedMemory(kernel_info->width,kernel_info->width*
+ AcquireAlignedMemory(kernel_info->width,kernel_info->height*
sizeof(*kernel_info->values)));
if (kernel_info->values == (MagickRealType *) NULL)
{
ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
}
normalize=0.0;
- j=(ssize_t) kernel_info->width/2;
+ j=(ssize_t) (kernel_info->width-1)/2;
i=0;
for (v=(-j); v <= j; v++)
{
}
}
kernel_info->values[i/2]=(double) ((-2.0)*normalize);
- sharp_image=ConvolveImage(image,kernel_info,exception);
+ normalize=0.0;
+ for (i=0; i < (ssize_t) (kernel_info->width*kernel_info->height); i++)
+ normalize+=kernel_info->values[i];
+ gamma=PerceptibleReciprocal(normalize);
+ for (i=0; i < (ssize_t) (kernel_info->width*kernel_info->height); i++)
+ kernel_info->values[i]*=gamma;
+ sharp_image=MorphologyApply(image,ConvolveMorphology,1,kernel_info,
+ UndefinedCompositeOp,0.0,exception);
kernel_info=DestroyKernelInfo(kernel_info);
return(sharp_image);
}
const int
id = GetOpenMPThreadId();
- register const Quantum
- *restrict p;
-
register Quantum
*restrict q;
if (status == MagickFalse)
continue;
- p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
q=QueueCacheViewAuthenticPixels(spread_view,0,y,spread_image->columns,1,
exception);
- if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
+ if (q == (Quantum *) NULL)
{
status=MagickFalse;
continue;
%
% o sigma: the standard deviation of the Gaussian, in pixels.
%
-% o amount: the percentage of the difference between the original and the
+% o gain: the percentage of the difference between the original and the
% blur image that is added back into the original.
%
-% o threshold: the threshold in pixels needed to apply the diffence amount.
+% o threshold: the threshold in pixels needed to apply the diffence gain.
%
% o exception: return any errors or warnings in this structure.
%
*/
MagickExport Image *UnsharpMaskImage(const Image *image,const double radius,
- const double sigma,const double amount,const double threshold,
+ const double sigma,const double gain,const double threshold,
ExceptionInfo *exception)
{
#define SharpenImageTag "Sharpen/Image"
(unsharp_traits == UndefinedPixelTrait))
continue;
if (((unsharp_traits & CopyPixelTrait) != 0) ||
- (GetPixelMask(image,p) != 0))
+ (GetPixelReadMask(image,p) != 0))
{
SetPixelChannel(unsharp_image,channel,p[i],q);
continue;
if (fabs(2.0*pixel) < quantum_threshold)
pixel=(double) p[i];
else
- pixel=(double) p[i]+amount*pixel;
+ pixel=(double) p[i]+gain*pixel;
SetPixelChannel(unsharp_image,channel,ClampToQuantum(pixel),q);
}
p+=GetPixelChannels(image);