]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/effect.c
(no commit message)
[imagemagick] / MagickCore / effect.c
index 08aed152e707bee4ecfd3a4955c4c2a1bd0ea1fe..fdb39351dc887cf8fb007954ecb46912de331d84 100644 (file)
@@ -229,14 +229,14 @@ MagickExport Image *AdaptiveBlurImage(const Image *image,const double radius,
   /*
     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);
@@ -554,14 +554,14 @@ MagickExport Image *AdaptiveSharpenImage(const Image *image,const double radius,
   /*
     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);
@@ -821,25 +821,15 @@ MagickExport Image *AdaptiveSharpenImage(const Image *image,const double radius,
 MagickExport Image *BlurImage(const Image *image,const double radius,
   const double sigma,ExceptionInfo *exception)
 {
-  double
-    normalize;
-
-  Image
-    *blur_image;
+  char
+    geometry[MaxTextExtent];
 
   KernelInfo
     *kernel_info;
 
-  register ssize_t
-    i;
-
-  size_t
-    width;
-
-  ssize_t
-    j,
-    u,
-    v;
+  Image
+    *blur_image,
+    *morphology_image;
 
   assert(image != (const Image *) NULL);
   assert(image->signature == MagickSignature);
@@ -847,41 +837,27 @@ MagickExport Image *BlurImage(const Image *image,const double radius,
     (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,"blur:%.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->x=(ssize_t) width/2;
-  kernel_info->y=(ssize_t) width/2;
-  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)
+  morphology_image=MorphologyImage(image,ConvolveMorphology,1,kernel_info,
+    exception);
+  kernel_info=DestroyKernelInfo(kernel_info);
+  if (morphology_image == (Image *) NULL)
+    return((Image *) NULL);
+  (void) FormatLocaleString(geometry,MaxTextExtent,"blur:%.20gx%.20g+90",radius,
+    sigma);
+  kernel_info=AcquireKernelInfo(geometry);
+  if (kernel_info == (KernelInfo *) NULL)
     {
-      kernel_info=DestroyKernelInfo(kernel_info);
+      morphology_image=DestroyImage(morphology_image);
       ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
     }
-  normalize=0.0;
-  j=(ssize_t) (kernel_info->width-1)/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));
-      normalize+=kernel_info->values[i];
-      i++;
-    }
-  }
-  kernel_info->values[i/2]+=(1.0-normalize);
-  if (sigma < MagickEpsilon)
-    kernel_info->values[i/2]=1.0;
-  blur_image=ConvolveImage(image,kernel_info,exception);
+  blur_image=MorphologyImage(morphology_image,ConvolveMorphology,1,kernel_info,
+    exception);
+  morphology_image=DestroyImage(morphology_image);
   kernel_info=DestroyKernelInfo(kernel_info);
   return(blur_image);
 }
@@ -916,7 +892,7 @@ MagickExport Image *BlurImage(const Image *image,const double radius,
 MagickExport Image *ConvolveImage(const Image *image,
   const KernelInfo *kernel_info,ExceptionInfo *exception)
 {
-  return(MorphologyImage(image,CorrelateMorphology,1,kernel_info,exception));
+  return(MorphologyImage(image,ConvolveMorphology,1,kernel_info,exception));
 }
 \f
 /*
@@ -1229,7 +1205,7 @@ MagickExport Image *DespeckleImage(const Image *image,ExceptionInfo *exception)
 %  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:
 %
@@ -1237,30 +1213,20 @@ MagickExport Image *DespeckleImage(const Image *image,ExceptionInfo *exception)
 %
 %    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;
+  char
+    geometry[MaxTextExtent];
 
   KernelInfo
     *kernel_info;
 
-  register ssize_t
-    i;
-
-  size_t
-    width;
-
-  ssize_t
-    j,
-    u,
-    v;
+  Image
+    *edge_image;
 
   assert(image != (const Image *) NULL);
   assert(image->signature == MagickSignature);
@@ -1268,34 +1234,11 @@ MagickExport Image *EdgeImage(const Image *image,const double radius,
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(exception != (ExceptionInfo *) NULL);
   assert(exception->signature == MagickSignature);
-  width=GetOptimalKernelWidth1D(radius,sigma);
-  kernel_info=AcquireKernelInfo((const char *) NULL);
+  (void) FormatLocaleString(geometry,MaxTextExtent,"laplacian:%.20g",radius);
+  kernel_info=AcquireKernelInfo(geometry);
   if (kernel_info == (KernelInfo *) NULL)
     ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
-  kernel_info->width=width;
-  kernel_info->height=width;
-  kernel_info->x=(ssize_t) width/2;
-  kernel_info->y=(ssize_t) width/2;
-  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-1)/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);
+  edge_image=MorphologyImage(image,ConvolveMorphology,1,kernel_info,exception);
   kernel_info=DestroyKernelInfo(kernel_info);
   return(edge_image);
 }
@@ -1366,8 +1309,8 @@ MagickExport Image *EmbossImage(const Image *image,const double radius,
     ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
   kernel_info->width=width;
   kernel_info->height=width;
-  kernel_info->x=(ssize_t) width/2;
-  kernel_info->y=(ssize_t) width/2;
+  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)));
@@ -1386,13 +1329,14 @@ MagickExport Image *EmbossImage(const Image *image,const double radius,
       kernel_info->values[i]=(MagickRealType) (((u < 0) || (v < 0) ? -8.0 :
         8.0)*exp(-((double) u*u+v*v)/(2.0*MagickSigma*MagickSigma))/
         (2.0*MagickPI*MagickSigma*MagickSigma));
-      if (u != k)
-        kernel_info->values[i]=0.0;
+      if (u == k)
+        kernel_info->values[i]=v == k ? 1.0 : 0.0;
       i++;
     }
     k--;
   }
-  emboss_image=ConvolveImage(image,kernel_info,exception);
+  emboss_image=MorphologyImage(image,ConvolveMorphology,1,kernel_info,
+    exception);
   kernel_info=DestroyKernelInfo(kernel_info);
   if (emboss_image != (Image *) NULL)
     (void) EqualizeImage(emboss_image,exception);
@@ -1435,22 +1379,14 @@ MagickExport Image *EmbossImage(const Image *image,const double radius,
 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);
@@ -1458,36 +1394,12 @@ MagickExport Image *GaussianBlurImage(const Image *image,const double radius,
     (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->x=(ssize_t) width/2;
-  kernel_info->y=(ssize_t) width/2;
-  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-1)/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=MorphologyImage(image,ConvolveMorphology,1,kernel_info,exception);
   kernel_info=DestroyKernelInfo(kernel_info);
   return(blur_image);
 }
@@ -2103,7 +2015,7 @@ MagickExport Image *PreviewImage(const Image *image,const PreviewType preview,
       }
       case EdgeDetectPreview:
       {
-        preview_image=EdgeImage(thumbnail,radius,sigma,exception);
+        preview_image=EdgeImage(thumbnail,radius,exception);
         (void) FormatLocaleString(label,MaxTextExtent,"edge %g",radius);
         break;
       }
@@ -2141,8 +2053,8 @@ MagickExport Image *PreviewImage(const Image *image,const PreviewType preview,
           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)
@@ -2387,8 +2299,8 @@ MagickExport Image *RadialBlurImage(const Image *image,const double angle,
       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);
@@ -2652,7 +2564,7 @@ MagickExport Image *SelectiveBlurImage(const Image *image,const double radius,
     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++)
   {
@@ -2721,8 +2633,8 @@ MagickExport Image *SelectiveBlurImage(const Image *image,const double radius,
   */
   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);
@@ -2750,10 +2662,10 @@ MagickExport Image *SelectiveBlurImage(const Image *image,const double radius,
 
     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))
@@ -3177,25 +3089,14 @@ MagickExport Image *ShadeImage(const Image *image,const MagickBooleanType gray,
 MagickExport Image *SharpenImage(const Image *image,const double radius,
   const double sigma,ExceptionInfo *exception)
 {
-  double
-    normalize;
-
-  Image
-    *sharp_image;
+  char
+    geometry[MaxTextExtent];
 
   KernelInfo
     *kernel_info;
 
-  register ssize_t
-    i;
-
-  size_t
-    width;
-
-  ssize_t
-    j,
-    u,
-    v;
+  Image
+    *sharp_image;
 
   assert(image != (const Image *) NULL);
   assert(image->signature == MagickSignature);
@@ -3203,41 +3104,14 @@ MagickExport Image *SharpenImage(const Image *image,const double radius,
     (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,"LoG:%.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->x=(ssize_t) width/2;
-  kernel_info->y=(ssize_t) width/2;
-  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");
-    }
-  normalize=0.0;
-  j=(ssize_t) (kernel_info->width-1)/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));
-      normalize+=kernel_info->values[i];
-      i++;
-    }
-  }
-  kernel_info->values[i/2]=(double) ((-2.0)*normalize);
-  if (sigma < MagickEpsilon)
-    kernel_info->values[i/2]=1.0;
-  sharp_image=ConvolveImage(image,kernel_info,exception);
+  ScaleGeometryKernelInfo(kernel_info,"56!,100%");
+  sharp_image=MorphologyImage(image,ConvolveMorphology,1,kernel_info,
+    exception);
   kernel_info=DestroyKernelInfo(kernel_info);
   return(sharp_image);
 }
@@ -3413,8 +3287,7 @@ MagickExport Image *SpreadImage(const Image *image,const double radius,
 %  The format of the UnsharpMaskImage method is:
 %
 %    Image *UnsharpMaskImage(const Image *image,const double radius,
-%      const double sigma,const double amount,const double threshold,
-%      ExceptionInfo *exception)
+%      const double sigma,const double gain,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -3425,138 +3298,40 @@ MagickExport Image *SpreadImage(const Image *image,const double radius,
 %
 %    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 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,
-  ExceptionInfo *exception)
+  const double sigma,const double gain,ExceptionInfo *exception)
 {
-#define SharpenImageTag  "Sharpen/Image"
+  char
+    geometry[MaxTextExtent];
 
-  CacheView
-    *image_view,
-    *unsharp_view;
+  KernelInfo
+    *kernel_info;
 
   Image
     *unsharp_image;
 
-  MagickBooleanType
-    status;
-
-  MagickOffsetType
-    progress;
-
-  double
-    quantum_threshold;
-
-  ssize_t
-    y;
-
   assert(image != (const Image *) NULL);
   assert(image->signature == MagickSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
   assert(exception != (ExceptionInfo *) NULL);
-  unsharp_image=BlurImage(image,radius,sigma,exception);
-  if (unsharp_image == (Image *) NULL)
-    return((Image *) NULL);
-  quantum_threshold=(double) QuantumRange*threshold;
-  /*
-    Unsharp-mask image.
-  */
-  status=MagickTrue;
-  progress=0;
-  image_view=AcquireVirtualCacheView(image,exception);
-  unsharp_view=AcquireAuthenticCacheView(unsharp_image,exception);
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(static,4) shared(progress,status) \
-    magick_threads(image,unsharp_image,image->rows,1)
-#endif
-  for (y=0; y < (ssize_t) image->rows; y++)
-  {
-    register const Quantum
-      *restrict p;
-
-    register Quantum
-      *restrict q;
-
-    register ssize_t
-      x;
-
-    if (status == MagickFalse)
-      continue;
-    p=GetCacheViewVirtualPixels(image_view,0,y,image->columns,1,exception);
-    q=QueueCacheViewAuthenticPixels(unsharp_view,0,y,unsharp_image->columns,1,
-      exception);
-    if ((p == (const Quantum *) NULL) || (q == (Quantum *) NULL))
-      {
-        status=MagickFalse;
-        continue;
-      }
-    for (x=0; x < (ssize_t) image->columns; x++)
-    {
-      register ssize_t
-        i;
-
-      for (i=0; i < (ssize_t) GetPixelChannels(image); i++)
-      {
-        double
-          pixel;
-
-        PixelChannel
-          channel;
-
-        PixelTrait
-          traits,
-          unsharp_traits;
-
-        channel=GetPixelChannelChannel(image,i);
-        traits=GetPixelChannelTraits(image,channel);
-        unsharp_traits=GetPixelChannelTraits(unsharp_image,channel);
-        if ((traits == UndefinedPixelTrait) ||
-            (unsharp_traits == UndefinedPixelTrait))
-          continue;
-        if (((unsharp_traits & CopyPixelTrait) != 0) ||
-            (GetPixelMask(image,p) == 0))
-          {
-            SetPixelChannel(unsharp_image,channel,p[i],q);
-            continue;
-          }
-        pixel=p[i]-(double) GetPixelChannel(unsharp_image,channel,q);
-        if (fabs(2.0*pixel) < quantum_threshold)
-          pixel=(double) p[i];
-        else
-          pixel=(double) p[i]+amount*pixel;
-        SetPixelChannel(unsharp_image,channel,ClampToQuantum(pixel),q);
-      }
-      p+=GetPixelChannels(image);
-      q+=GetPixelChannels(unsharp_image);
-    }
-    if (SyncCacheViewAuthenticPixels(unsharp_view,exception) == MagickFalse)
-      status=MagickFalse;
-    if (image->progress_monitor != (MagickProgressMonitor) NULL)
-      {
-        MagickBooleanType
-          proceed;
-
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
-        #pragma omp critical (MagickCore_UnsharpMaskImage)
-#endif
-        proceed=SetImageProgress(image,SharpenImageTag,progress++,image->rows);
-        if (proceed == MagickFalse)
-          status=MagickFalse;
-      }
-  }
-  unsharp_image->type=image->type;
-  unsharp_view=DestroyCacheView(unsharp_view);
-  image_view=DestroyCacheView(image_view);
-  if (status == MagickFalse)
-    unsharp_image=DestroyImage(unsharp_image);
+  assert(exception->signature == MagickSignature);
+  (void) FormatLocaleString(geometry,MaxTextExtent,"Blur:%.20gx%.20g>",
+    radius,sigma);
+  kernel_info=AcquireKernelInfo(geometry);
+  if (kernel_info == (KernelInfo *) NULL)
+    ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
+  (void) FormatLocaleString(geometry,MaxTextExtent,"%.20g,%.20g%%",
+    -100.0+gain*100.0,200.0-gain*100.0);
+  ScaleGeometryKernelInfo(kernel_info,geometry);
+  unsharp_image=MorphologyImage(image,ConvolveMorphology,1,kernel_info,
+    exception);
+  kernel_info=DestroyKernelInfo(kernel_info);
   return(unsharp_image);
 }