]> granicus.if.org Git - imagemagick/commitdiff
(no commit message)
authorcristy <urban-warrior@git.imagemagick.org>
Fri, 18 Mar 2011 21:29:28 +0000 (21:29 +0000)
committercristy <urban-warrior@git.imagemagick.org>
Fri, 18 Mar 2011 21:29:28 +0000 (21:29 +0000)
15 files changed:
Magick++/lib/Image.cpp
Magick++/lib/Magick++/Include.h
PerlMagick/Magick.xs
coders/msl.c
magick/deprecate.c
magick/deprecate.h
magick/display.c
magick/distort.c
magick/effect.c
magick/effect.h
magick/shear.c
wand/deprecate.c
wand/deprecate.h
wand/magick-image.c
wand/mogrify.c

index a895b9d243cad42fe72c813b2f2f7faa3e3af2e9..b27545ba9c4eac044d570d03c50f33016215a55e 100644 (file)
@@ -1318,7 +1318,7 @@ void Magick::Image::medianFilter ( const double radius_ )
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
   MagickCore::Image* newImage =
-    MedianFilterImage ( image(), radius_, &exceptionInfo );
+    StatisticImage ( image(), MedianStatistic, radius_, &exceptionInfo );
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
@@ -1709,7 +1709,7 @@ void Magick::Image::reduceNoise ( const double order_ )
   ExceptionInfo exceptionInfo;
   GetExceptionInfo( &exceptionInfo );
   MagickCore::Image* newImage =
-    ReduceNoiseImage( image(), order_, &exceptionInfo );
+    StatisticImage( image(), NonpeakStatistic, order_, &exceptionInfo );
   replaceImage( newImage );
   throwException( exceptionInfo );
   (void) DestroyExceptionInfo( &exceptionInfo );
index cd04166579c95d15263256d34a097bf7de6183c0..f7d2e37797cc50e28b7112190b0fafc00dfc378d 100644 (file)
@@ -465,6 +465,10 @@ namespace Magick
   using MagickCore::ShepardsColorInterpolate;
   using MagickCore::VoronoiColorInterpolate;
 
+  // Statistic type
+  using MagickCore::MedianStatistic;
+  using MagickCore::NonpeakStatistic;
+
   // StorageType type
   using MagickCore::StorageType;
   using MagickCore::CharPixel;
@@ -785,7 +789,6 @@ namespace Magick
   using MagickCore::MagickWand;
   using MagickCore::MagnifyImage;
   using MagickCore::MapImage;
-  using MagickCore::MedianFilterImage;
   using MagickCore::MergeImageLayers;
   using MagickCore::MinifyImage;
   using MagickCore::MissingDelegateError;
@@ -834,7 +837,6 @@ namespace Magick
   using MagickCore::ReadImage;
   using MagickCore::RecolorImage;
   using MagickCore::RectangleInfo;
-  using MagickCore::ReduceNoiseImage;
   using MagickCore::RegisterMagickInfo;
   using MagickCore::RegistryError;
   using MagickCore::RegistryFatalError;
@@ -885,6 +887,7 @@ namespace Magick
   using MagickCore::SparseColorImage;
   using MagickCore::SpliceImage;
   using MagickCore::SpreadImage;
+  using MagickCore::StatisticImage;
   using MagickCore::SteganoImage;
   using MagickCore::StereoImage;
   using MagickCore::StreamError;
index 56124ef59642f3677dae21e9ceabf9e088a115e3..ebf3598df52ff17e3f6a8de87f7b3bedcbd07b19 100644 (file)
@@ -241,10 +241,12 @@ static struct
     { "Implode", { {"amount", RealReference},
       {"interpolate", MagickInterpolateOptions} } },
     { "Magnify", },
-    { "MedianFilter", { {"radius", RealReference} } },
+    { "MedianFilter", { {"radius", RealReference}
+       {"channel", MagickChannelOptions} } },
     { "Minify", },
     { "OilPaint", { {"radius", RealReference} } },
-    { "ReduceNoise", { {"radius", RealReference} } },
+    { "ReduceNoise", { {"radius", RealReference},
+      {"channel", MagickChannelOptions} } },
     { "Roll", { {"geometry", StringReference}, {"x", IntegerReference},
       {"y", IntegerReference} } },
     { "Rotate", { {"degrees", RealReference}, {"fill", StringReference},
@@ -532,7 +534,8 @@ static struct
       {"iterations", IntegerReference} } },
     { "ColorMatrix", { {"matrix", ArrayReference} } },
     { "Color", { {"color", StringReference} } },
-    { "Mode", { {"radius", RealReference} } }
+    { "Mode", { {"radius", RealReference},
+      {"channel", MagickChannelOptions} } },
     { "Statistic", { {"radius", RealReference},
       {"channel", MagickChannelOptions}, {"type", MagickStatisticOptions} } }
   };
@@ -7793,8 +7796,10 @@ Mogrify(ref,...)
         {
           if (attribute_flag[0] == 0)
             argument_list[0].real_reference=0.0;
-          image=MedianFilterImage(image,argument_list[0].real_reference,
-            exception);
+          if (attribute_flag[1] != 0)
+            channel=(ChannelType) argument_list[1].integer_reference;
+          image=StatisticImage(image,channel,MedianStatistics,
+            argument_list[0].real_reference,exception);
           break;
         }
         case 19:  /* Minify */
@@ -7816,6 +7821,10 @@ Mogrify(ref,...)
             argument_list[0].real_reference=0.0;
           image=ReduceNoiseImage(image,argument_list[0].real_reference,
             exception);
+          if (attribute_flag[1] != 0)
+            channel=(ChannelType) argument_list[1].integer_reference;
+          image=StatisticImage(image,channel,NonpeakStatistic,
+            argument_list[0].real_reference,exception);
           break;
         }
         case 22:  /* Roll */
@@ -10622,7 +10631,10 @@ Mogrify(ref,...)
         {
           if (attribute_flag[0] == 0)
             argument_list[0].real_reference=0.0;
-          image=ModeImage(image,argument_list[0].real_reference,exception);
+          if (attribute_flag[1] != 0)
+            channel=(ChannelType) argument_list[1].integer_reference;
+          image=StatisticImage(image,channel,ModeStatistic,
+            argument_list[0].real_reference,exception);
           break;
         }
         case 137:  /* Statistic */
index d0a64284f88b907fee54e3bd897a6280dcd58480..9eeca016b23af1a7cf653137bd3cf0c320c72095 100644 (file)
@@ -3815,8 +3815,8 @@ static void MSLStartElement(void *context,const xmlChar *tag,
                 }
               }
             }
-          median_image=MedianFilterImage(msl_info->image[n],geometry_info.rho,
-            &msl_info->image[n]->exception);
+          median_image=StatisticImage(msl_info->image[n],MedianStatistic,
+            geometry_info.rho,&msl_info->image[n]->exception);
           if (median_image == (Image *) NULL)
             break;
           msl_info->image[n]=DestroyImage(msl_info->image[n]);
@@ -5039,8 +5039,8 @@ static void MSLStartElement(void *context,const xmlChar *tag,
                 }
               }
             }
-          paint_image=ReduceNoiseImage(msl_info->image[n],geometry_info.rho,
-            &msl_info->image[n]->exception);
+          paint_image=StatisticImage(msl_info->image[n],NonpeakStatistic,
+            geometry_info.rho,&msl_info->image[n]->exception);
           if (paint_image == (Image *) NULL)
             break;
           msl_info->image[n]=DestroyImage(msl_info->image[n]);
index 456729e58c2be4e488b67d56731c0e648e75e8e0..9d30a58e671bcd119c8868833110e8d915c580f8 100644 (file)
@@ -3455,8 +3455,8 @@ MagickExport MagickPixelPacket InterpolatePixelColor(const Image *image,
         alpha[16],
         gamma;
 
-      p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x)-1,(ssize_t) floor(y)-
-        1,4,4,exception);
+      p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x)-1,(ssize_t)
+        floor(y)-1,4,4,exception);
       if (p == (const PixelPacket *) NULL)
         break;
       indexes=GetCacheViewVirtualIndexQueue(image_view);
@@ -3498,8 +3498,8 @@ MagickExport MagickPixelPacket InterpolatePixelColor(const Image *image,
       PointInfo
         delta;
 
-      p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x)-1,(ssize_t) floor(y)-
-        1,4,4,exception);
+      p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x)-1,(ssize_t)
+        floor(y)-1,4,4,exception);
       if (p == (const PixelPacket *) NULL)
         break;
       indexes=GetCacheViewVirtualIndexQueue(image_view);
@@ -3539,8 +3539,8 @@ MagickExport MagickPixelPacket InterpolatePixelColor(const Image *image,
       PointInfo
         delta;
 
-      p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x),(ssize_t) floor(y),2,
-        2,exception);
+      p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x),(ssize_t)
+        floor(y),2,2,exception);
       if (p == (const PixelPacket *) NULL)
         break;
       indexes=GetCacheViewVirtualIndexQueue(image_view);
@@ -3624,8 +3624,8 @@ MagickExport MagickPixelPacket InterpolatePixelColor(const Image *image,
       MagickPixelPacket
         pixels[1];
 
-      p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x),(ssize_t) floor(y),1,
-        1,exception);
+      p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x),(ssize_t)
+        floor(y),1,1,exception);
       if (p == (const PixelPacket *) NULL)
         break;
       indexes=GetCacheViewVirtualIndexQueue(image_view);
@@ -3646,8 +3646,8 @@ MagickExport MagickPixelPacket InterpolatePixelColor(const Image *image,
         delta,
         luminance;
 
-      p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x),(ssize_t) floor(y),
-        2,2,exception);
+      p=GetCacheViewVirtualPixels(image_view,(ssize_t) floor(x),(ssize_t)
+        floor(y),2,2,exception);
       if (p == (const PixelPacket *) NULL)
         break;
       indexes=GetCacheViewVirtualIndexQueue(image_view);
@@ -4567,6 +4567,88 @@ MagickExport Image *MinimumImages(const Image *images,ExceptionInfo *exception)
 %                                                                             %
 %                                                                             %
 %                                                                             %
+%     M e d i a n F i l t e r I m a g e                                       %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  MedianFilterImage() applies a digital filter that improves the quality
+%  of a noisy image.  Each pixel is replaced by the median in a set of
+%  neighboring pixels as defined by radius.
+%
+%  The algorithm was contributed by Mike Edmonds and implements an insertion
+%  sort for selecting median color-channel values.  For more on this algorithm
+%  see "Skip Lists: A probabilistic Alternative to Balanced Trees" by William
+%  Pugh in the June 1990 of Communications of the ACM.
+%
+%  The format of the MedianFilterImage method is:
+%
+%      Image *MedianFilterImage(const Image *image,const double radius,
+%        ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o image: the image.
+%
+%    o radius: the radius of the pixel neighborhood.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+MagickExport Image *MedianFilterImage(const Image *image,const double radius,
+  ExceptionInfo *exception)
+{
+  Image
+    *median_image;
+
+  median_image=StatisticImage(image,MedianStatistic,radius,exception);
+  return(median_image);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%     M o d e I m a g e                                                       %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  ModeImage() makes each pixel the 'predominate color' of the neighborhood
+%  of the specified radius.
+%
+%  The format of the ModeImage method is:
+%
+%      Image *ModeImage(const Image *image,const double radius,
+%        ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o image: the image.
+%
+%    o radius: the radius of the pixel neighborhood.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+MagickExport Image *ModeImage(const Image *image,const double radius,
+  ExceptionInfo *exception)
+{
+  Image
+    *mode_image;
+
+  mode_image=StatisticImage(image,ModeStatistic,radius,exception);
+  return(mode_image);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
 %     M o s a i c I m a g e s                                                 %
 %                                                                             %
 %                                                                             %
@@ -5572,6 +5654,46 @@ MagickExport Image *RecolorImage(const Image *image,const size_t order,
 %                                                                             %
 %                                                                             %
 %                                                                             %
+%     R e d u c e N o i s e I m a g e                                         %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  ReduceNoiseImage() smooths the contours of an image while still preserving
+%  edge information.  The algorithm works by replacing each pixel with its
+%  neighbor closest in value.  A neighbor is defined by radius.  Use a radius
+%  of 0 and ReduceNoise() selects a suitable radius for you.
+%
+%  The format of the ReduceNoiseImage method is:
+%
+%      Image *ReduceNoiseImage(const Image *image,const double radius,
+%        ExceptionInfo *exception)
+%
+%  A description of each parameter follows:
+%
+%    o image: the image.
+%
+%    o radius: the radius of the pixel neighborhood.
+%
+%    o exception: return any errors or warnings in this structure.
+%
+*/
+MagickExport Image *ReduceNoiseImage(const Image *image,const double radius,
+  ExceptionInfo *exception)
+{
+  Image
+    *reduce_image;
+
+  reduce_image=StatisticImage(image,NonpeakStatistic,radius,exception);
+  return(reduce_image);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
 %   R e s e t I m a g e A t t r i b u t e I t e r a t o r                     %
 %                                                                             %
 %                                                                             %
index bac6db385d47607d9edad45d918105567459bbc9..d8441eb4584265da6191e1070215be42a56dbc2a 100644 (file)
@@ -128,11 +128,14 @@ extern MagickExport Image
   *GetPreviousImage(const Image *) magick_attribute((deprecated)),
   *FlattenImages(Image *,ExceptionInfo *) magick_attribute((deprecated)),
   *MaximumImages(const Image *,ExceptionInfo *),
+  *MedianFilterImage(const Image *,const double,ExceptionInfo *),
+  *ModeImage(const Image *,const double,ExceptionInfo *),
   *MinimumImages(const Image *,ExceptionInfo *),
   *MosaicImages(Image *,ExceptionInfo *) magick_attribute((deprecated)),
   *PopImageList(Image **) magick_attribute((deprecated)),
   *RecolorImage(const Image *,const size_t,const double *,ExceptionInfo *)
     magick_attribute((deprecated)),
+  *ReduceNoiseImage(const Image *,const double,ExceptionInfo *),
   *ShiftImageList(Image **) magick_attribute((deprecated)),
   *SpliceImageList(Image *,const ssize_t,const size_t,const Image *,
     ExceptionInfo *) magick_attribute((deprecated)),
index 67315038cf5629ec1d542b1b80da68d9c54ae473..221cf05b55c52ee8e5d21328f88d249dd593e50f 100644 (file)
@@ -8073,7 +8073,7 @@ static Image *XMagickCommand(Display *display,XResourceInfo *resource_info,
       XSetCursorState(display,windows,MagickTrue);
       XCheckRefreshWindows(display,windows);
       flags=ParseGeometry(radius,&geometry_info);
-      noise_image=ReduceNoiseImage(*image,geometry_info.rho,
+      noise_image=StatisticImage(*image,NonpeakStatistic,geometry_info.rho,
         &(*image)->exception);
       if (noise_image != (Image *) NULL)
         {
index ca8dc29550e132c6ee43b1cae6a79a0877bef1b7..3b73b5daf126071ab9d5809c9f725f220e9f56e3 100644 (file)
@@ -2522,7 +2522,6 @@ MagickExport Image *SparseColorImage(const Image *image,
     }
   { /* ----- MAIN CODE ----- */
     CacheView
-      *image_view,
       *sparse_view;
 
     MagickBooleanType
@@ -2536,7 +2535,6 @@ MagickExport Image *SparseColorImage(const Image *image,
 
     status=MagickTrue;
     progress=0;
-    image_view=AcquireCacheView(image);
     sparse_view=AcquireCacheView(sparse_image);
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
   #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
index 9bc681d2e3ce59be0bd9ca057b305b468f58a440..0bde3c2194b716533cd8c62f18f3686a25a7ce44 100644 (file)
@@ -2530,398 +2530,175 @@ MagickExport Image *GaussianBlurImageChannel(const Image *image,
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%     M e d i a n F i l t e r I m a g e                                       %
+%     M o t i o n B l u r I m a g e                                           %
 %                                                                             %
 %                                                                             %
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  MedianFilterImage() applies a digital filter that improves the quality
-%  of a noisy image.  Each pixel is replaced by the median in a set of
-%  neighboring pixels as defined by radius.
+%  MotionBlurImage() simulates motion blur.  We convolve the image with a
+%  Gaussian operator of the given radius and standard deviation (sigma).
+%  For reasonable results, radius should be larger than sigma.  Use a
+%  radius of 0 and MotionBlurImage() selects a suitable radius for you.
+%  Angle gives the angle of the blurring motion.
 %
-%  The algorithm was contributed by Mike Edmonds and implements an insertion
-%  sort for selecting median color-channel values.  For more on this algorithm
-%  see "Skip Lists: A probabilistic Alternative to Balanced Trees" by William
-%  Pugh in the June 1990 of Communications of the ACM.
+%  Andrew Protano contributed this effect.
 %
-%  The format of the MedianFilterImage method is:
+%  The format of the MotionBlurImage method is:
 %
-%      Image *MedianFilterImage(const Image *image,const double radius,
-%        ExceptionInfo *exception)
+%    Image *MotionBlurImage(const Image *image,const double radius,
+%      const double sigma,const double angle,ExceptionInfo *exception)
+%    Image *MotionBlurImageChannel(const Image *image,const ChannelType channel,
+%      const double radius,const double sigma,const double angle,
+%      ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
 %    o image: the image.
 %
-%    o radius: the radius of the pixel neighborhood.
+%    o channel: the channel type.
+%
+%    o radius: the radius of the Gaussian, in pixels, not counting the center
+%    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 angle: Apply the effect along this angle.
 %
 %    o exception: return any errors or warnings in this structure.
 %
 */
 
-#define ListChannels  5
-
-typedef struct _ListNode
-{
-  size_t
-    next[9],
-    count,
-    signature;
-} ListNode;
-
-typedef struct _SkipList
-{
-  ssize_t
-    level;
-
-  ListNode
-    *nodes;
-} SkipList;
-
-typedef struct _PixelList
+static double *GetMotionBlurKernel(const size_t width,const double sigma)
 {
-  size_t
-    center,
-    seed,
-    signature;
-
-  SkipList
-    lists[ListChannels];
-} PixelList;
+  double
+    *kernel,
+    normalize;
 
-static PixelList *DestroyPixelList(PixelList *pixel_list)
-{
   register ssize_t
     i;
 
-  if (pixel_list == (PixelList *) NULL)
-    return((PixelList *) NULL);
-  for (i=0; i < ListChannels; i++)
-    if (pixel_list->lists[i].nodes != (ListNode *) NULL)
-      pixel_list->lists[i].nodes=(ListNode *) RelinquishMagickMemory(
-        pixel_list->lists[i].nodes);
-  pixel_list=(PixelList *) RelinquishMagickMemory(pixel_list);
-  return(pixel_list);
+  /*
+   Generate a 1-D convolution kernel.
+  */
+  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
+  kernel=(double *) AcquireQuantumMemory((size_t) width,sizeof(*kernel));
+  if (kernel == (double *) NULL)
+    return(kernel);
+  normalize=0.0;
+  for (i=0; i < (ssize_t) width; i++)
+  {
+    kernel[i]=(double) (exp((-((double) i*i)/(double) (2.0*MagickSigma*
+      MagickSigma)))/(MagickSQ2PI*MagickSigma));
+    normalize+=kernel[i];
+  }
+  for (i=0; i < (ssize_t) width; i++)
+    kernel[i]/=normalize;
+  return(kernel);
 }
 
-static PixelList **DestroyPixelListThreadSet(PixelList **pixel_list)
+MagickExport Image *MotionBlurImage(const Image *image,const double radius,
+  const double sigma,const double angle,ExceptionInfo *exception)
 {
-  register ssize_t
-    i;
+  Image
+    *motion_blur;
 
-  assert(pixel_list != (PixelList **) NULL);
-  for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
-    if (pixel_list[i] != (PixelList *) NULL)
-      pixel_list[i]=DestroyPixelList(pixel_list[i]);
-  pixel_list=(PixelList **) RelinquishMagickMemory(pixel_list);
-  return(pixel_list);
+  motion_blur=MotionBlurImageChannel(image,DefaultChannels,radius,sigma,angle,
+    exception);
+  return(motion_blur);
 }
 
-static PixelList *AcquirePixelList(const size_t width)
+MagickExport Image *MotionBlurImageChannel(const Image *image,
+  const ChannelType channel,const double radius,const double sigma,
+  const double angle,ExceptionInfo *exception)
 {
-  PixelList
-    *pixel_list;
+  CacheView
+    *blur_view,
+    *image_view;
 
-  register ssize_t
-    i;
+  double
+    *kernel;
 
-  pixel_list=(PixelList *) AcquireMagickMemory(sizeof(*pixel_list));
-  if (pixel_list == (PixelList *) NULL)
-    return(pixel_list);
-  (void) ResetMagickMemory((void *) pixel_list,0,sizeof(*pixel_list));
-  pixel_list->center=width*width/2;
-  for (i=0; i < ListChannels; i++)
-  {
-    pixel_list->lists[i].nodes=(ListNode *) AcquireQuantumMemory(65537UL,
-      sizeof(*pixel_list->lists[i].nodes));
-    if (pixel_list->lists[i].nodes == (ListNode *) NULL)
-      return(DestroyPixelList(pixel_list));
-    (void) ResetMagickMemory(pixel_list->lists[i].nodes,0,65537UL*
-      sizeof(*pixel_list->lists[i].nodes));
-  }
-  pixel_list->signature=MagickSignature;
-  return(pixel_list);
-}
+  Image
+    *blur_image;
 
-static PixelList **AcquirePixelListThreadSet(const size_t width)
-{
-  PixelList
-    **pixel_list;
+  MagickBooleanType
+    status;
 
-  register ssize_t
-    i;
+  MagickOffsetType
+    progress;
 
-  size_t
-    number_threads;
+  MagickPixelPacket
+    bias;
 
-  number_threads=GetOpenMPMaximumThreads();
-  pixel_list=(PixelList **) AcquireQuantumMemory(number_threads,
-    sizeof(*pixel_list));
-  if (pixel_list == (PixelList **) NULL)
-    return((PixelList **) NULL);
-  (void) ResetMagickMemory(pixel_list,0,number_threads*sizeof(*pixel_list));
-  for (i=0; i < (ssize_t) number_threads; i++)
-  {
-    pixel_list[i]=AcquirePixelList(width);
-    if (pixel_list[i] == (PixelList *) NULL)
-      return(DestroyPixelListThreadSet(pixel_list));
-  }
-  return(pixel_list);
-}
+  OffsetInfo
+    *offset;
 
-static void AddNodePixelList(PixelList *pixel_list,const ssize_t channel,
-  const size_t color)
-{
-  register SkipList
-    *list;
+  PointInfo
+    point;
 
   register ssize_t
-    level;
+    i;
 
   size_t
-    search,
-    update[9];
+    width;
 
-  /*
-    Initialize the node.
-  */
-  list=pixel_list->lists+channel;
-  list->nodes[color].signature=pixel_list->signature;
-  list->nodes[color].count=1;
-  /*
-    Determine where it belongs in the list.
-  */
-  search=65536UL;
-  for (level=list->level; level >= 0; level--)
-  {
-    while (list->nodes[search].next[level] < color)
-      search=list->nodes[search].next[level];
-    update[level]=search;
-  }
-  /*
-    Generate a pseudo-random level for this node.
-  */
-  for (level=0; ; level++)
+  ssize_t
+    y;
+
+  assert(image != (Image *) NULL);
+  assert(image->signature == MagickSignature);
+  if (image->debug != MagickFalse)
+    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
+  assert(exception != (ExceptionInfo *) NULL);
+  width=GetOptimalKernelWidth1D(radius,sigma);
+  kernel=GetMotionBlurKernel(width,sigma);
+  if (kernel == (double *) NULL)
+    ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
+  offset=(OffsetInfo *) AcquireQuantumMemory(width,sizeof(*offset));
+  if (offset == (OffsetInfo *) NULL)
+    {
+      kernel=(double *) RelinquishMagickMemory(kernel);
+      ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
+    }
+  blur_image=CloneImage(image,0,0,MagickTrue,exception);
+  if (blur_image == (Image *) NULL)
+    {
+      kernel=(double *) RelinquishMagickMemory(kernel);
+      offset=(OffsetInfo *) RelinquishMagickMemory(offset);
+      return((Image *) NULL);
+    }
+  if (SetImageStorageClass(blur_image,DirectClass) == MagickFalse)
+    {
+      kernel=(double *) RelinquishMagickMemory(kernel);
+      offset=(OffsetInfo *) RelinquishMagickMemory(offset);
+      InheritException(exception,&blur_image->exception);
+      blur_image=DestroyImage(blur_image);
+      return((Image *) NULL);
+    }
+  point.x=(double) width*sin(DegreesToRadians(angle));
+  point.y=(double) width*cos(DegreesToRadians(angle));
+  for (i=0; i < (ssize_t) width; i++)
   {
-    pixel_list->seed=(pixel_list->seed*42893621L)+1L;
-    if ((pixel_list->seed & 0x300) != 0x300)
-      break;
+    offset[i].x=(ssize_t) ceil((double) (i*point.y)/hypot(point.x,point.y)-0.5);
+    offset[i].y=(ssize_t) ceil((double) (i*point.x)/hypot(point.x,point.y)-0.5);
   }
-  if (level > 8)
-    level=8;
-  if (level > (list->level+2))
-    level=list->level+2;
   /*
-    If we're raising the list's level, link back to the root node.
+    Motion blur image.
   */
-  while (level > list->level)
+  status=MagickTrue;
+  progress=0;
+  GetMagickPixelPacket(image,&bias);
+  image_view=AcquireCacheView(image);
+  blur_view=AcquireCacheView(blur_image);
+#if defined(MAGICKCORE_OPENMP_SUPPORT)
+  #pragma omp parallel for schedule(dynamic,4) shared(progress,status) omp_throttle(1)
+#endif
+  for (y=0; y < (ssize_t) image->rows; y++)
   {
-    list->level++;
-    update[list->level]=65536UL;
-  }
-  /*
-    Link the node into the skip-list.
-  */
-  do
-  {
-    list->nodes[color].next[level]=list->nodes[update[level]].next[level];
-    list->nodes[update[level]].next[level]=color;
-  }
-  while (level-- > 0);
-}
-
-static MagickPixelPacket GetMedianPixelList(PixelList *pixel_list)
-{
-  MagickPixelPacket
-    pixel;
-
-  register SkipList
-    *list;
-
-  register ssize_t
-    channel;
-
-  size_t
-    center,
-    color,
-    count;
-
-  unsigned short
-    channels[ListChannels];
-
-  /*
-    Find the median value for each of the color.
-  */
-  center=pixel_list->center;
-  for (channel=0; channel < 5; channel++)
-  {
-    list=pixel_list->lists+channel;
-    color=65536UL;
-    count=0;
-    do
-    {
-      color=list->nodes[color].next[0];
-      count+=list->nodes[color].count;
-    }
-    while (count <= center);
-    channels[channel]=(unsigned short) color;
-  }
-  GetMagickPixelPacket((const Image *) NULL,&pixel);
-  pixel.red=(MagickRealType) ScaleShortToQuantum(channels[0]);
-  pixel.green=(MagickRealType) ScaleShortToQuantum(channels[1]);
-  pixel.blue=(MagickRealType) ScaleShortToQuantum(channels[2]);
-  pixel.opacity=(MagickRealType) ScaleShortToQuantum(channels[3]);
-  pixel.index=(MagickRealType) ScaleShortToQuantum(channels[4]);
-  return(pixel);
-}
-
-static inline void InsertPixelList(const Image *image,const PixelPacket *pixel,
-  const IndexPacket *indexes,PixelList *pixel_list)
-{
-  size_t
-    signature;
-
-  unsigned short
-    index;
-
-  index=ScaleQuantumToShort(pixel->red);
-  signature=pixel_list->lists[0].nodes[index].signature;
-  if (signature == pixel_list->signature)
-    pixel_list->lists[0].nodes[index].count++;
-  else
-    AddNodePixelList(pixel_list,0,index);
-  index=ScaleQuantumToShort(pixel->green);
-  signature=pixel_list->lists[1].nodes[index].signature;
-  if (signature == pixel_list->signature)
-    pixel_list->lists[1].nodes[index].count++;
-  else
-    AddNodePixelList(pixel_list,1,index);
-  index=ScaleQuantumToShort(pixel->blue);
-  signature=pixel_list->lists[2].nodes[index].signature;
-  if (signature == pixel_list->signature)
-    pixel_list->lists[2].nodes[index].count++;
-  else
-    AddNodePixelList(pixel_list,2,index);
-  index=ScaleQuantumToShort(pixel->opacity);
-  signature=pixel_list->lists[3].nodes[index].signature;
-  if (signature == pixel_list->signature)
-    pixel_list->lists[3].nodes[index].count++;
-  else
-    AddNodePixelList(pixel_list,3,index);
-  if (image->colorspace == CMYKColorspace)
-    index=ScaleQuantumToShort(*indexes);
-  signature=pixel_list->lists[4].nodes[index].signature;
-  if (signature == pixel_list->signature)
-    pixel_list->lists[4].nodes[index].count++;
-  else
-    AddNodePixelList(pixel_list,4,index);
-}
-
-static void ResetPixelList(PixelList *pixel_list)
-{
-  int
-    level;
-
-  register ListNode
-    *root;
-
-  register SkipList
-    *list;
-
-  register ssize_t
-    channel;
-
-  /*
-    Reset the skip-list.
-  */
-  for (channel=0; channel < 5; channel++)
-  {
-    list=pixel_list->lists+channel;
-    root=list->nodes+65536UL;
-    list->level=0;
-    for (level=0; level < 9; level++)
-      root->next[level]=65536UL;
-  }
-  pixel_list->seed=pixel_list->signature++;
-}
-
-MagickExport Image *MedianFilterImage(const Image *image,const double radius,
-  ExceptionInfo *exception)
-{
-#define MedianFilterImageTag  "MedianFilter/Image"
-
-  CacheView
-    *image_view,
-    *median_view;
-
-  Image
-    *median_image;
-
-  MagickBooleanType
-    status;
-
-  MagickOffsetType
-    progress;
-
-  PixelList
-    **restrict pixel_list;
-
-  size_t
-    width;
-
-  ssize_t
-    y;
-
-  /*
-    Initialize median image attributes.
-  */
-  assert(image != (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=GetOptimalKernelWidth2D(radius,0.5);
-  median_image=CloneImage(image,image->columns,image->rows,MagickTrue,
-    exception);
-  if (median_image == (Image *) NULL)
-    return((Image *) NULL);
-  if (SetImageStorageClass(median_image,DirectClass) == MagickFalse)
-    {
-      InheritException(exception,&median_image->exception);
-      median_image=DestroyImage(median_image);
-      return((Image *) NULL);
-    }
-  pixel_list=AcquirePixelListThreadSet(width);
-  if (pixel_list == (PixelList **) NULL)
-    {
-      median_image=DestroyImage(median_image);
-      ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
-    }
-  /*
-    Median filter each image row.
-  */
-  status=MagickTrue;
-  progress=0;
-  image_view=AcquireCacheView(image);
-  median_view=AcquireCacheView(median_image);
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
-#endif
-  for (y=0; y < (ssize_t) median_image->rows; y++)
-  {
-    const int
-      id = GetOpenMPThreadId();
-
-    register const IndexPacket
-      *restrict indexes;
-
-    register const PixelPacket
-      *restrict p;
-
     register IndexPacket
-      *restrict median_indexes;
+      *restrict blur_indexes;
 
     register PixelPacket
       *restrict q;
@@ -2931,279 +2708,104 @@ MagickExport Image *MedianFilterImage(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);
-    q=QueueCacheViewAuthenticPixels(median_view,0,y,median_image->columns,1,
+    q=GetCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
       exception);
-    if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
+    if (q == (PixelPacket *) NULL)
       {
         status=MagickFalse;
         continue;
       }
-    indexes=GetCacheViewVirtualIndexQueue(image_view);
-    median_indexes=GetCacheViewAuthenticIndexQueue(median_view);
-    for (x=0; x < (ssize_t) median_image->columns; x++)
+    blur_indexes=GetCacheViewAuthenticIndexQueue(blur_view);
+    for (x=0; x < (ssize_t) image->columns; x++)
     {
       MagickPixelPacket
+        qixel;
+
+      PixelPacket
         pixel;
 
       register const IndexPacket
-        *restrict s;
+        *restrict indexes;
 
-      register const PixelPacket
-        *restrict r;
+      register double
+        *restrict k;
 
       register ssize_t
-        u,
-        v;
-
-      r=p;
-      s=indexes+x;
-      ResetPixelList(pixel_list[id]);
-      for (v=0; v < (ssize_t) width; v++)
-      {
-        for (u=0; u < (ssize_t) width; u++)
-          InsertPixelList(image,r+u,s+u,pixel_list[id]);
-        r+=image->columns+width;
-        s+=image->columns+width;
-      }
-      pixel=GetMedianPixelList(pixel_list[id]);
-      SetPixelPacket(median_image,&pixel,q,median_indexes+x);
-      p++;
-      q++;
-    }
-    if (SyncCacheViewAuthenticPixels(median_view,exception) == MagickFalse)
-      status=MagickFalse;
-    if (image->progress_monitor != (MagickProgressMonitor) NULL)
-      {
-        MagickBooleanType
-          proceed;
+        i;
 
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp critical (MagickCore_MedianFilterImage)
-#endif
-        proceed=SetImageProgress(image,MedianFilterImageTag,progress++,
-          image->rows);
-        if (proceed == MagickFalse)
-          status=MagickFalse;
-      }
-  }
-  median_view=DestroyCacheView(median_view);
-  image_view=DestroyCacheView(image_view);
-  pixel_list=DestroyPixelListThreadSet(pixel_list);
-  return(median_image);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%     M o d e I m a g e                                                       %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  ModeImage() makes each pixel the 'predominate color' of the neighborhood
-%  of the specified radius.
-%
-%  The format of the ModeImage method is:
-%
-%      Image *ModeImage(const Image *image,const double radius,
-%        ExceptionInfo *exception)
-%
-%  A description of each parameter follows:
-%
-%    o image: the image.
-%
-%    o radius: the radius of the pixel neighborhood.
-%
-%    o exception: return any errors or warnings in this structure.
-%
-*/
-
-static MagickPixelPacket GetModePixelList(PixelList *pixel_list)
-{
-  MagickPixelPacket
-    pixel;
-
-  register SkipList
-    *list;
-
-  register ssize_t
-    channel;
-
-  size_t
-    color,
-    count,
-    max_count,
-    mode,
-    width;
-
-  unsigned short
-    channels[5];
-
-  /*
-    Make each pixel the 'predominate color' of the specified neighborhood.
-  */
-  width=pixel_list->center << 1;
-  for (channel=0; channel < 5; channel++)
-  {
-    list=pixel_list->lists+channel;
-    color=65536UL;
-    mode=color;
-    max_count=list->nodes[mode].count;
-    count=0;
-    do
-    {
-      color=list->nodes[color].next[0];
-      if (list->nodes[color].count > max_count)
+      k=kernel;
+      qixel=bias;
+      if (((channel & OpacityChannel) == 0) || (image->matte == MagickFalse))
         {
-          mode=color;
-          max_count=list->nodes[mode].count;
+          for (i=0; i < (ssize_t) width; i++)
+          {
+            (void) GetOneCacheViewVirtualPixel(image_view,x+offset[i].x,y+
+              offset[i].y,&pixel,exception);
+            qixel.red+=(*k)*pixel.red;
+            qixel.green+=(*k)*pixel.green;
+            qixel.blue+=(*k)*pixel.blue;
+            qixel.opacity+=(*k)*pixel.opacity;
+            if (image->colorspace == CMYKColorspace)
+              {
+                indexes=GetCacheViewVirtualIndexQueue(image_view);
+                qixel.index+=(*k)*(*indexes);
+              }
+            k++;
+          }
+          if ((channel & RedChannel) != 0)
+            q->red=ClampToQuantum(qixel.red);
+          if ((channel & GreenChannel) != 0)
+            q->green=ClampToQuantum(qixel.green);
+          if ((channel & BlueChannel) != 0)
+            q->blue=ClampToQuantum(qixel.blue);
+          if ((channel & OpacityChannel) != 0)
+            q->opacity=ClampToQuantum(qixel.opacity);
+          if (((channel & IndexChannel) != 0) &&
+              (image->colorspace == CMYKColorspace))
+            blur_indexes[x]=(IndexPacket) ClampToQuantum(qixel.index);
         }
-      count+=list->nodes[color].count;
-    }
-    while (count <= width);
-    channels[channel]=(unsigned short) mode;
-  }
-  GetMagickPixelPacket((const Image *) NULL,&pixel);
-  pixel.red=(MagickRealType) ScaleShortToQuantum(channels[0]);
-  pixel.green=(MagickRealType) ScaleShortToQuantum(channels[1]);
-  pixel.blue=(MagickRealType) ScaleShortToQuantum(channels[2]);
-  pixel.opacity=(MagickRealType) ScaleShortToQuantum(channels[3]);
-  pixel.index=(MagickRealType) ScaleShortToQuantum(channels[4]);
-  return(pixel);
-}
-
-MagickExport Image *ModeImage(const Image *image,const double radius,
-  ExceptionInfo *exception)
-{
-#define ModeImageTag  "Mode/Image"
-
-  CacheView
-    *image_view,
-    *mode_view;
-
-  Image
-    *mode_image;
-
-  MagickBooleanType
-    status;
-
-  MagickOffsetType
-    progress;
-
-  PixelList
-    **restrict pixel_list;
-
-  size_t
-    width;
-
-  ssize_t
-    y;
-
-  /*
-    Initialize mode image attributes.
-  */
-  assert(image != (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=GetOptimalKernelWidth2D(radius,0.5);
-  mode_image=CloneImage(image,image->columns,image->rows,MagickTrue,
-    exception);
-  if (mode_image == (Image *) NULL)
-    return((Image *) NULL);
-  if (SetImageStorageClass(mode_image,DirectClass) == MagickFalse)
-    {
-      InheritException(exception,&mode_image->exception);
-      mode_image=DestroyImage(mode_image);
-      return((Image *) NULL);
-    }
-  pixel_list=AcquirePixelListThreadSet(width);
-  if (pixel_list == (PixelList **) NULL)
-    {
-      mode_image=DestroyImage(mode_image);
-      ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
-    }
-  /*
-    Reduce mode image.
-  */
-  status=MagickTrue;
-  progress=0;
-  image_view=AcquireCacheView(image);
-  mode_view=AcquireCacheView(mode_image);
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
-#endif
-  for (y=0; y < (ssize_t) mode_image->rows; y++)
-  {
-    const int
-      id = GetOpenMPThreadId();
-
-    register const IndexPacket
-      *restrict indexes;
-
-    register const PixelPacket
-      *restrict p;
-
-    register IndexPacket
-      *restrict mode_indexes;
-
-    register PixelPacket
-      *restrict q;
-
-    register ssize_t
-      x;
-
-    if (status == MagickFalse)
-      continue;
-    p=GetCacheViewVirtualPixels(image_view,-((ssize_t) width/2L),y-(ssize_t)
-      (width/2L),image->columns+width,width,exception);
-    q=QueueCacheViewAuthenticPixels(mode_view,0,y,mode_image->columns,1,
-      exception);
-    if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
-      {
-        status=MagickFalse;
-        continue;
-      }
-    indexes=GetCacheViewVirtualIndexQueue(image_view);
-    mode_indexes=GetCacheViewAuthenticIndexQueue(mode_view);
-    for (x=0; x < (ssize_t) mode_image->columns; x++)
-    {
-      MagickPixelPacket
-        pixel;
-
-      register const PixelPacket
-        *restrict r;
-
-      register const IndexPacket
-        *restrict s;
-
-      register ssize_t
-        u,
-        v;
+      else
+        {
+          MagickRealType
+            alpha,
+            gamma;
 
-      r=p;
-      s=indexes+x;
-      ResetPixelList(pixel_list[id]);
-      for (v=0; v < (ssize_t) width; v++)
-      {
-        for (u=0; u < (ssize_t) width; u++)
-          InsertPixelList(image,r+u,s+u,pixel_list[id]);
-        r+=image->columns+width;
-        s+=image->columns+width;
-      }
-      pixel=GetModePixelList(pixel_list[id]);
-      SetPixelPacket(mode_image,&pixel,q,mode_indexes+x);
-      p++;
+          alpha=0.0;
+          gamma=0.0;
+          for (i=0; i < (ssize_t) width; i++)
+          {
+            (void) GetOneCacheViewVirtualPixel(image_view,x+offset[i].x,y+
+              offset[i].y,&pixel,exception);
+            alpha=(MagickRealType) (QuantumScale*
+              GetAlphaPixelComponent(&pixel));
+            qixel.red+=(*k)*alpha*pixel.red;
+            qixel.green+=(*k)*alpha*pixel.green;
+            qixel.blue+=(*k)*alpha*pixel.blue;
+            qixel.opacity+=(*k)*pixel.opacity;
+            if (image->colorspace == CMYKColorspace)
+              {
+                indexes=GetCacheViewVirtualIndexQueue(image_view);
+                qixel.index+=(*k)*alpha*(*indexes);
+              }
+            gamma+=(*k)*alpha;
+            k++;
+          }
+          gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
+          if ((channel & RedChannel) != 0)
+            q->red=ClampToQuantum(gamma*qixel.red);
+          if ((channel & GreenChannel) != 0)
+            q->green=ClampToQuantum(gamma*qixel.green);
+          if ((channel & BlueChannel) != 0)
+            q->blue=ClampToQuantum(gamma*qixel.blue);
+          if ((channel & OpacityChannel) != 0)
+            q->opacity=ClampToQuantum(qixel.opacity);
+          if (((channel & IndexChannel) != 0) &&
+              (image->colorspace == CMYKColorspace))
+            blur_indexes[x]=(IndexPacket) ClampToQuantum(gamma*qixel.index);
+        }
       q++;
     }
-    if (SyncCacheViewAuthenticPixels(mode_view,exception) == MagickFalse)
+    if (SyncCacheViewAuthenticPixels(blur_view,exception) == MagickFalse)
       status=MagickFalse;
     if (image->progress_monitor != (MagickProgressMonitor) NULL)
       {
@@ -3211,17 +2813,20 @@ MagickExport Image *ModeImage(const Image *image,const double radius,
           proceed;
 
 #if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp critical (MagickCore_ModeImage)
+  #pragma omp critical (MagickCore_MotionBlurImageChannel)
 #endif
-        proceed=SetImageProgress(image,ModeImageTag,progress++,image->rows);
+        proceed=SetImageProgress(image,BlurImageTag,progress++,image->rows);
         if (proceed == MagickFalse)
           status=MagickFalse;
       }
   }
-  mode_view=DestroyCacheView(mode_view);
+  blur_view=DestroyCacheView(blur_view);
   image_view=DestroyCacheView(image_view);
-  pixel_list=DestroyPixelListThreadSet(pixel_list);
-  return(mode_image);
+  kernel=(double *) RelinquishMagickMemory(kernel);
+  offset=(OffsetInfo *) RelinquishMagickMemory(offset);
+  if (status == MagickFalse)
+    blur_image=DestroyImage(blur_image);
+  return(blur_image);
 }
 \f
 /*
@@ -3229,422 +2834,118 @@ MagickExport Image *ModeImage(const Image *image,const double radius,
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%     M o t i o n B l u r I m a g e                                           %
+%     P r e v i e w I m a g e                                                 %
 %                                                                             %
 %                                                                             %
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  MotionBlurImage() simulates motion blur.  We convolve the image with a
-%  Gaussian operator of the given radius and standard deviation (sigma).
-%  For reasonable results, radius should be larger than sigma.  Use a
-%  radius of 0 and MotionBlurImage() selects a suitable radius for you.
-%  Angle gives the angle of the blurring motion.
-%
-%  Andrew Protano contributed this effect.
+%  PreviewImage() tiles 9 thumbnails of the specified image with an image
+%  processing operation applied with varying parameters.  This may be helpful
+%  pin-pointing an appropriate parameter for a particular image processing
+%  operation.
 %
-%  The format of the MotionBlurImage method is:
+%  The format of the PreviewImages method is:
 %
-%    Image *MotionBlurImage(const Image *image,const double radius,
-%      const double sigma,const double angle,ExceptionInfo *exception)
-%    Image *MotionBlurImageChannel(const Image *image,const ChannelType channel,
-%      const double radius,const double sigma,const double angle,
-%      ExceptionInfo *exception)
+%      Image *PreviewImages(const Image *image,const PreviewType preview,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
 %    o image: the image.
 %
-%    o channel: the channel type.
-%
-%    o radius: the radius of the Gaussian, in pixels, not counting the center
-%    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 angle: Apply the effect along this angle.
+%    o preview: the image processing operation.
 %
 %    o exception: return any errors or warnings in this structure.
 %
 */
-
-static double *GetMotionBlurKernel(const size_t width,const double sigma)
-{
-  double
-    *kernel,
-    normalize;
-
-  register ssize_t
-    i;
-
-  /*
-   Generate a 1-D convolution kernel.
-  */
-  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
-  kernel=(double *) AcquireQuantumMemory((size_t) width,sizeof(*kernel));
-  if (kernel == (double *) NULL)
-    return(kernel);
-  normalize=0.0;
-  for (i=0; i < (ssize_t) width; i++)
-  {
-    kernel[i]=(double) (exp((-((double) i*i)/(double) (2.0*MagickSigma*
-      MagickSigma)))/(MagickSQ2PI*MagickSigma));
-    normalize+=kernel[i];
-  }
-  for (i=0; i < (ssize_t) width; i++)
-    kernel[i]/=normalize;
-  return(kernel);
-}
-
-MagickExport Image *MotionBlurImage(const Image *image,const double radius,
-  const double sigma,const double angle,ExceptionInfo *exception)
+MagickExport Image *PreviewImage(const Image *image,const PreviewType preview,
+  ExceptionInfo *exception)
 {
-  Image
-    *motion_blur;
-
-  motion_blur=MotionBlurImageChannel(image,DefaultChannels,radius,sigma,angle,
-    exception);
-  return(motion_blur);
-}
+#define NumberTiles  9
+#define PreviewImageTag  "Preview/Image"
+#define DefaultPreviewGeometry  "204x204+10+10"
 
-MagickExport Image *MotionBlurImageChannel(const Image *image,
-  const ChannelType channel,const double radius,const double sigma,
-  const double angle,ExceptionInfo *exception)
-{
-  CacheView
-    *blur_view,
-    *image_view;
+  char
+    factor[MaxTextExtent],
+    label[MaxTextExtent];
 
   double
-    *kernel;
+    degrees,
+    gamma,
+    percentage,
+    radius,
+    sigma,
+    threshold;
 
   Image
-    *blur_image;
+    *images,
+    *montage_image,
+    *preview_image,
+    *thumbnail;
 
-  MagickBooleanType
-    status;
+  ImageInfo
+    *preview_info;
 
-  MagickOffsetType
-    progress;
+  MagickBooleanType
+    proceed;
 
-  MagickPixelPacket
-    bias;
+  MontageInfo
+    *montage_info;
 
-  OffsetInfo
-    *offset;
+  QuantizeInfo
+    quantize_info;
 
-  PointInfo
-    point;
+  RectangleInfo
+    geometry;
 
   register ssize_t
-    i;
+    i,
+    x;
 
   size_t
-    width;
+    colors;
 
   ssize_t
     y;
 
+  /*
+    Open output image file.
+  */
   assert(image != (Image *) NULL);
   assert(image->signature == MagickSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
-  assert(exception != (ExceptionInfo *) NULL);
-  width=GetOptimalKernelWidth1D(radius,sigma);
-  kernel=GetMotionBlurKernel(width,sigma);
-  if (kernel == (double *) NULL)
-    ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
-  offset=(OffsetInfo *) AcquireQuantumMemory(width,sizeof(*offset));
-  if (offset == (OffsetInfo *) NULL)
-    {
-      kernel=(double *) RelinquishMagickMemory(kernel);
-      ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
-    }
-  blur_image=CloneImage(image,0,0,MagickTrue,exception);
-  if (blur_image == (Image *) NULL)
-    {
-      kernel=(double *) RelinquishMagickMemory(kernel);
-      offset=(OffsetInfo *) RelinquishMagickMemory(offset);
-      return((Image *) NULL);
-    }
-  if (SetImageStorageClass(blur_image,DirectClass) == MagickFalse)
-    {
-      kernel=(double *) RelinquishMagickMemory(kernel);
-      offset=(OffsetInfo *) RelinquishMagickMemory(offset);
-      InheritException(exception,&blur_image->exception);
-      blur_image=DestroyImage(blur_image);
-      return((Image *) NULL);
-    }
-  point.x=(double) width*sin(DegreesToRadians(angle));
-  point.y=(double) width*cos(DegreesToRadians(angle));
-  for (i=0; i < (ssize_t) width; i++)
-  {
-    offset[i].x=(ssize_t) ceil((double) (i*point.y)/hypot(point.x,point.y)-0.5);
-    offset[i].y=(ssize_t) ceil((double) (i*point.x)/hypot(point.x,point.y)-0.5);
-  }
-  /*
-    Motion blur image.
-  */
-  status=MagickTrue;
-  progress=0;
-  GetMagickPixelPacket(image,&bias);
-  image_view=AcquireCacheView(image);
-  blur_view=AcquireCacheView(blur_image);
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(dynamic,4) shared(progress,status) omp_throttle(1)
-#endif
-  for (y=0; y < (ssize_t) image->rows; y++)
+  colors=2;
+  degrees=0.0;
+  gamma=(-0.2f);
+  preview_info=AcquireImageInfo();
+  SetGeometry(image,&geometry);
+  (void) ParseMetaGeometry(DefaultPreviewGeometry,&geometry.x,&geometry.y,
+    &geometry.width,&geometry.height);
+  images=NewImageList();
+  percentage=12.5;
+  GetQuantizeInfo(&quantize_info);
+  radius=0.0;
+  sigma=1.0;
+  threshold=0.0;
+  x=0;
+  y=0;
+  for (i=0; i < NumberTiles; i++)
   {
-    register IndexPacket
-      *restrict blur_indexes;
-
-    register PixelPacket
-      *restrict q;
-
-    register ssize_t
-      x;
-
-    if (status == MagickFalse)
-      continue;
-    q=GetCacheViewAuthenticPixels(blur_view,0,y,blur_image->columns,1,
-      exception);
-    if (q == (PixelPacket *) NULL)
+    thumbnail=ThumbnailImage(image,geometry.width,geometry.height,exception);
+    if (thumbnail == (Image *) NULL)
+      break;
+    (void) SetImageProgressMonitor(thumbnail,(MagickProgressMonitor) NULL,
+      (void *) NULL);
+    (void) SetImageProperty(thumbnail,"label",DefaultTileLabel);
+    if (i == (NumberTiles/2))
       {
-        status=MagickFalse;
+        (void) QueryColorDatabase("#dfdfdf",&thumbnail->matte_color,exception);
+        AppendImageToList(&images,thumbnail);
         continue;
       }
-    blur_indexes=GetCacheViewAuthenticIndexQueue(blur_view);
-    for (x=0; x < (ssize_t) image->columns; x++)
-    {
-      MagickPixelPacket
-        qixel;
-
-      PixelPacket
-        pixel;
-
-      register const IndexPacket
-        *restrict indexes;
-
-      register double
-        *restrict k;
-
-      register ssize_t
-        i;
-
-      k=kernel;
-      qixel=bias;
-      if (((channel & OpacityChannel) == 0) || (image->matte == MagickFalse))
-        {
-          for (i=0; i < (ssize_t) width; i++)
-          {
-            (void) GetOneCacheViewVirtualPixel(image_view,x+offset[i].x,y+
-              offset[i].y,&pixel,exception);
-            qixel.red+=(*k)*pixel.red;
-            qixel.green+=(*k)*pixel.green;
-            qixel.blue+=(*k)*pixel.blue;
-            qixel.opacity+=(*k)*pixel.opacity;
-            if (image->colorspace == CMYKColorspace)
-              {
-                indexes=GetCacheViewVirtualIndexQueue(image_view);
-                qixel.index+=(*k)*(*indexes);
-              }
-            k++;
-          }
-          if ((channel & RedChannel) != 0)
-            q->red=ClampToQuantum(qixel.red);
-          if ((channel & GreenChannel) != 0)
-            q->green=ClampToQuantum(qixel.green);
-          if ((channel & BlueChannel) != 0)
-            q->blue=ClampToQuantum(qixel.blue);
-          if ((channel & OpacityChannel) != 0)
-            q->opacity=ClampToQuantum(qixel.opacity);
-          if (((channel & IndexChannel) != 0) &&
-              (image->colorspace == CMYKColorspace))
-            blur_indexes[x]=(IndexPacket) ClampToQuantum(qixel.index);
-        }
-      else
-        {
-          MagickRealType
-            alpha,
-            gamma;
-
-          alpha=0.0;
-          gamma=0.0;
-          for (i=0; i < (ssize_t) width; i++)
-          {
-            (void) GetOneCacheViewVirtualPixel(image_view,x+offset[i].x,y+
-              offset[i].y,&pixel,exception);
-            alpha=(MagickRealType) (QuantumScale*
-              GetAlphaPixelComponent(&pixel));
-            qixel.red+=(*k)*alpha*pixel.red;
-            qixel.green+=(*k)*alpha*pixel.green;
-            qixel.blue+=(*k)*alpha*pixel.blue;
-            qixel.opacity+=(*k)*pixel.opacity;
-            if (image->colorspace == CMYKColorspace)
-              {
-                indexes=GetCacheViewVirtualIndexQueue(image_view);
-                qixel.index+=(*k)*alpha*(*indexes);
-              }
-            gamma+=(*k)*alpha;
-            k++;
-          }
-          gamma=1.0/(fabs((double) gamma) <= MagickEpsilon ? 1.0 : gamma);
-          if ((channel & RedChannel) != 0)
-            q->red=ClampToQuantum(gamma*qixel.red);
-          if ((channel & GreenChannel) != 0)
-            q->green=ClampToQuantum(gamma*qixel.green);
-          if ((channel & BlueChannel) != 0)
-            q->blue=ClampToQuantum(gamma*qixel.blue);
-          if ((channel & OpacityChannel) != 0)
-            q->opacity=ClampToQuantum(qixel.opacity);
-          if (((channel & IndexChannel) != 0) &&
-              (image->colorspace == CMYKColorspace))
-            blur_indexes[x]=(IndexPacket) ClampToQuantum(gamma*qixel.index);
-        }
-      q++;
-    }
-    if (SyncCacheViewAuthenticPixels(blur_view,exception) == MagickFalse)
-      status=MagickFalse;
-    if (image->progress_monitor != (MagickProgressMonitor) NULL)
-      {
-        MagickBooleanType
-          proceed;
-
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp critical (MagickCore_MotionBlurImageChannel)
-#endif
-        proceed=SetImageProgress(image,BlurImageTag,progress++,image->rows);
-        if (proceed == MagickFalse)
-          status=MagickFalse;
-      }
-  }
-  blur_view=DestroyCacheView(blur_view);
-  image_view=DestroyCacheView(image_view);
-  kernel=(double *) RelinquishMagickMemory(kernel);
-  offset=(OffsetInfo *) RelinquishMagickMemory(offset);
-  if (status == MagickFalse)
-    blur_image=DestroyImage(blur_image);
-  return(blur_image);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%     P r e v i e w I m a g e                                                 %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  PreviewImage() tiles 9 thumbnails of the specified image with an image
-%  processing operation applied with varying parameters.  This may be helpful
-%  pin-pointing an appropriate parameter for a particular image processing
-%  operation.
-%
-%  The format of the PreviewImages method is:
-%
-%      Image *PreviewImages(const Image *image,const PreviewType preview,
-%        ExceptionInfo *exception)
-%
-%  A description of each parameter follows:
-%
-%    o image: the image.
-%
-%    o preview: the image processing operation.
-%
-%    o exception: return any errors or warnings in this structure.
-%
-*/
-MagickExport Image *PreviewImage(const Image *image,const PreviewType preview,
-  ExceptionInfo *exception)
-{
-#define NumberTiles  9
-#define PreviewImageTag  "Preview/Image"
-#define DefaultPreviewGeometry  "204x204+10+10"
-
-  char
-    factor[MaxTextExtent],
-    label[MaxTextExtent];
-
-  double
-    degrees,
-    gamma,
-    percentage,
-    radius,
-    sigma,
-    threshold;
-
-  Image
-    *images,
-    *montage_image,
-    *preview_image,
-    *thumbnail;
-
-  ImageInfo
-    *preview_info;
-
-  MagickBooleanType
-    proceed;
-
-  MontageInfo
-    *montage_info;
-
-  QuantizeInfo
-    quantize_info;
-
-  RectangleInfo
-    geometry;
-
-  register ssize_t
-    i,
-    x;
-
-  size_t
-    colors;
-
-  ssize_t
-    y;
-
-  /*
-    Open output image file.
-  */
-  assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
-  if (image->debug != MagickFalse)
-    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
-  colors=2;
-  degrees=0.0;
-  gamma=(-0.2f);
-  preview_info=AcquireImageInfo();
-  SetGeometry(image,&geometry);
-  (void) ParseMetaGeometry(DefaultPreviewGeometry,&geometry.x,&geometry.y,
-    &geometry.width,&geometry.height);
-  images=NewImageList();
-  percentage=12.5;
-  GetQuantizeInfo(&quantize_info);
-  radius=0.0;
-  sigma=1.0;
-  threshold=0.0;
-  x=0;
-  y=0;
-  for (i=0; i < NumberTiles; i++)
-  {
-    thumbnail=ThumbnailImage(image,geometry.width,geometry.height,exception);
-    if (thumbnail == (Image *) NULL)
-      break;
-    (void) SetImageProgressMonitor(thumbnail,(MagickProgressMonitor) NULL,
-      (void *) NULL);
-    (void) SetImageProperty(thumbnail,"label",DefaultTileLabel);
-    if (i == (NumberTiles/2))
-      {
-        (void) QueryColorDatabase("#dfdfdf",&thumbnail->matte_color,exception);
-        AppendImageToList(&images,thumbnail);
-        continue;
-      }
-    switch (preview)
+    switch (preview)
     {
       case RotatePreview:
       {
@@ -3778,7 +3079,8 @@ MagickExport Image *PreviewImage(const Image *image,const PreviewType preview,
       }
       case ReduceNoisePreview:
       {
-        preview_image=ReduceNoiseImage(thumbnail,radius,exception);
+        preview_image=StatisticImage(thumbnail,NonpeakStatistic,radius,
+          exception);
         (void) FormatMagickString(label,MaxTextExtent,"noise %g",radius);
         break;
       }
@@ -3822,7 +3124,8 @@ MagickExport Image *PreviewImage(const Image *image,const PreviewType preview,
             break;
           }
         }
-        preview_image=ReduceNoiseImage(thumbnail,(double) i,exception);
+        preview_image=StatisticImage(thumbnail,NonpeakStatistic,(double) i,
+          exception);
         (void) FormatMagickString(label,MaxTextExtent,"+noise %s",factor);
         break;
       }
@@ -4348,334 +3651,100 @@ MagickExport Image *RadialBlurImageChannel(const Image *image,
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%     R e d u c e N o i s e I m a g e                                         %
+%     S e l e c t i v e B l u r I m a g e                                     %
 %                                                                             %
 %                                                                             %
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  ReduceNoiseImage() smooths the contours of an image while still preserving
-%  edge information.  The algorithm works by replacing each pixel with its
-%  neighbor closest in value.  A neighbor is defined by radius.  Use a radius
-%  of 0 and ReduceNoise() selects a suitable radius for you.
+%  SelectiveBlurImage() selectively blur pixels within a contrast threshold.
+%  It is similar to the unsharpen mask that sharpens everything with contrast
+%  above a certain threshold.
 %
-%  The format of the ReduceNoiseImage method is:
+%  The format of the SelectiveBlurImage method is:
 %
-%      Image *ReduceNoiseImage(const Image *image,const double radius,
-%        ExceptionInfo *exception)
+%      Image *SelectiveBlurImage(const Image *image,const double radius,
+%        const double sigma,const double threshold,ExceptionInfo *exception)
+%      Image *SelectiveBlurImageChannel(const Image *image,
+%        const ChannelType channel,const double radius,const double sigma,
+%        const double threshold,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
 %    o image: the image.
 %
-%    o radius: the radius of the pixel neighborhood.
+%    o channel: the channel type.
+%
+%    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 threshold: only pixels within this contrast threshold are included
+%      in the blur operation.
 %
 %    o exception: return any errors or warnings in this structure.
 %
 */
 
-static MagickPixelPacket GetNonpeakPixelList(PixelList *pixel_list)
+static inline MagickBooleanType SelectiveContrast(const PixelPacket *p,
+  const PixelPacket *q,const double threshold)
 {
-  MagickPixelPacket
-    pixel;
+  if (fabs(PixelIntensity(p)-PixelIntensity(q)) < threshold)
+    return(MagickTrue);
+  return(MagickFalse);
+}
 
-  register SkipList
-    *list;
+MagickExport Image *SelectiveBlurImage(const Image *image,const double radius,
+  const double sigma,const double threshold,ExceptionInfo *exception)
+{
+  Image
+    *blur_image;
+
+  blur_image=SelectiveBlurImageChannel(image,DefaultChannels,radius,sigma,
+    threshold,exception);
+  return(blur_image);
+}
+
+MagickExport Image *SelectiveBlurImageChannel(const Image *image,
+  const ChannelType channel,const double radius,const double sigma,
+  const double threshold,ExceptionInfo *exception)
+{
+#define SelectiveBlurImageTag  "SelectiveBlur/Image"
+
+  CacheView
+    *blur_view,
+    *image_view;
+
+  double
+    *kernel;
+
+  Image
+    *blur_image;
+
+  MagickBooleanType
+    status;
+
+  MagickOffsetType
+    progress;
+
+  MagickPixelPacket
+    bias;
 
   register ssize_t
-    channel;
+    i;
 
   size_t
-    center,
-    color,
-    count,
-    next,
-    previous;
+    width;
 
-  unsigned short
-    channels[5];
+  ssize_t
+    j,
+    u,
+    v,
+    y;
 
   /*
-    Finds the median value for each of the color.
-  */
-  center=pixel_list->center;
-  for (channel=0; channel < 5; channel++)
-  {
-    list=pixel_list->lists+channel;
-    color=65536UL;
-    next=list->nodes[color].next[0];
-    count=0;
-    do
-    {
-      previous=color;
-      color=next;
-      next=list->nodes[color].next[0];
-      count+=list->nodes[color].count;
-    }
-    while (count <= center);
-    if ((previous == 65536UL) && (next != 65536UL))
-      color=next;
-    else
-      if ((previous != 65536UL) && (next == 65536UL))
-        color=previous;
-    channels[channel]=(unsigned short) color;
-  }
-  GetMagickPixelPacket((const Image *) NULL,&pixel);
-  pixel.red=(MagickRealType) ScaleShortToQuantum(channels[0]);
-  pixel.green=(MagickRealType) ScaleShortToQuantum(channels[1]);
-  pixel.blue=(MagickRealType) ScaleShortToQuantum(channels[2]);
-  pixel.opacity=(MagickRealType) ScaleShortToQuantum(channels[3]);
-  pixel.index=(MagickRealType) ScaleShortToQuantum(channels[4]);
-  return(pixel);
-}
-
-MagickExport Image *ReduceNoiseImage(const Image *image,const double radius,
-  ExceptionInfo *exception)
-{
-#define ReduceNoiseImageTag  "ReduceNoise/Image"
-
-  CacheView
-    *image_view,
-    *noise_view;
-
-  Image
-    *noise_image;
-
-  MagickBooleanType
-    status;
-
-  MagickOffsetType
-    progress;
-
-  PixelList
-    **restrict pixel_list;
-
-  size_t
-    width;
-
-  ssize_t
-    y;
-
-  /*
-    Initialize noise image attributes.
-  */
-  assert(image != (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=GetOptimalKernelWidth2D(radius,0.5);
-  noise_image=CloneImage(image,image->columns,image->rows,MagickTrue,
-    exception);
-  if (noise_image == (Image *) NULL)
-    return((Image *) NULL);
-  if (SetImageStorageClass(noise_image,DirectClass) == MagickFalse)
-    {
-      InheritException(exception,&noise_image->exception);
-      noise_image=DestroyImage(noise_image);
-      return((Image *) NULL);
-    }
-  pixel_list=AcquirePixelListThreadSet(width);
-  if (pixel_list == (PixelList **) NULL)
-    {
-      noise_image=DestroyImage(noise_image);
-      ThrowImageException(ResourceLimitError,"MemoryAllocationFailed");
-    }
-  /*
-    Reduce noise image.
-  */
-  status=MagickTrue;
-  progress=0;
-  image_view=AcquireCacheView(image);
-  noise_view=AcquireCacheView(noise_image);
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp parallel for schedule(dynamic,4) shared(progress,status)
-#endif
-  for (y=0; y < (ssize_t) noise_image->rows; y++)
-  {
-    const int
-      id = GetOpenMPThreadId();
-
-    register const IndexPacket
-      *restrict indexes;
-
-    register const PixelPacket
-      *restrict p;
-
-    register IndexPacket
-      *restrict noise_indexes;
-
-    register PixelPacket
-      *restrict q;
-
-    register ssize_t
-      x;
-
-    if (status == MagickFalse)
-      continue;
-    p=GetCacheViewVirtualPixels(image_view,-((ssize_t) width/2L),y-(ssize_t)
-      (width/2L),image->columns+width,width,exception);
-    q=QueueCacheViewAuthenticPixels(noise_view,0,y,noise_image->columns,1,
-      exception);
-    if ((p == (const PixelPacket *) NULL) || (q == (PixelPacket *) NULL))
-      {
-        status=MagickFalse;
-        continue;
-      }
-    indexes=GetCacheViewVirtualIndexQueue(image_view);
-    noise_indexes=GetCacheViewAuthenticIndexQueue(noise_view);
-    for (x=0; x < (ssize_t) noise_image->columns; x++)
-    {
-      MagickPixelPacket
-        pixel;
-
-      register const PixelPacket
-        *restrict r;
-
-      register const IndexPacket
-        *restrict s;
-
-      register ssize_t
-        u,
-        v;
-
-      r=p;
-      s=indexes+x;
-      ResetPixelList(pixel_list[id]);
-      for (v=0; v < (ssize_t) width; v++)
-      {
-        for (u=0; u < (ssize_t) width; u++)
-          InsertPixelList(image,r+u,s+u,pixel_list[id]);
-        r+=image->columns+width;
-        s+=image->columns+width;
-      }
-      pixel=GetNonpeakPixelList(pixel_list[id]);
-      SetPixelPacket(noise_image,&pixel,q,noise_indexes+x);
-      p++;
-      q++;
-    }
-    if (SyncCacheViewAuthenticPixels(noise_view,exception) == MagickFalse)
-      status=MagickFalse;
-    if (image->progress_monitor != (MagickProgressMonitor) NULL)
-      {
-        MagickBooleanType
-          proceed;
-
-#if defined(MAGICKCORE_OPENMP_SUPPORT)
-  #pragma omp critical (MagickCore_ReduceNoiseImage)
-#endif
-        proceed=SetImageProgress(image,ReduceNoiseImageTag,progress++,
-          image->rows);
-        if (proceed == MagickFalse)
-          status=MagickFalse;
-      }
-  }
-  noise_view=DestroyCacheView(noise_view);
-  image_view=DestroyCacheView(image_view);
-  pixel_list=DestroyPixelListThreadSet(pixel_list);
-  return(noise_image);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%     S e l e c t i v e B l u r I m a g e                                     %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  SelectiveBlurImage() selectively blur pixels within a contrast threshold.
-%  It is similar to the unsharpen mask that sharpens everything with contrast
-%  above a certain threshold.
-%
-%  The format of the SelectiveBlurImage method is:
-%
-%      Image *SelectiveBlurImage(const Image *image,const double radius,
-%        const double sigma,const double threshold,ExceptionInfo *exception)
-%      Image *SelectiveBlurImageChannel(const Image *image,
-%        const ChannelType channel,const double radius,const double sigma,
-%        const double 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, in pixels, not counting the center
-%      pixel.
-%
-%    o sigma: the standard deviation of the Gaussian, in pixels.
-%
-%    o threshold: only pixels within this contrast threshold are included
-%      in the blur operation.
-%
-%    o exception: return any errors or warnings in this structure.
-%
-*/
-
-static inline MagickBooleanType SelectiveContrast(const PixelPacket *p,
-  const PixelPacket *q,const double threshold)
-{
-  if (fabs(PixelIntensity(p)-PixelIntensity(q)) < threshold)
-    return(MagickTrue);
-  return(MagickFalse);
-}
-
-MagickExport Image *SelectiveBlurImage(const Image *image,const double radius,
-  const double sigma,const double threshold,ExceptionInfo *exception)
-{
-  Image
-    *blur_image;
-
-  blur_image=SelectiveBlurImageChannel(image,DefaultChannels,radius,sigma,
-    threshold,exception);
-  return(blur_image);
-}
-
-MagickExport Image *SelectiveBlurImageChannel(const Image *image,
-  const ChannelType channel,const double radius,const double sigma,
-  const double threshold,ExceptionInfo *exception)
-{
-#define SelectiveBlurImageTag  "SelectiveBlur/Image"
-
-  CacheView
-    *blur_view,
-    *image_view;
-
-  double
-    *kernel;
-
-  Image
-    *blur_image;
-
-  MagickBooleanType
-    status;
-
-  MagickOffsetType
-    progress;
-
-  MagickPixelPacket
-    bias;
-
-  register ssize_t
-    i;
-
-  size_t
-    width;
-
-  ssize_t
-    j,
-    u,
-    v,
-    y;
-
-  /*
-    Initialize blur image attributes.
+    Initialize blur image attributes.
   */
   assert(image != (Image *) NULL);
   assert(image->signature == MagickSignature);
@@ -5484,6 +4553,401 @@ MagickExport Image *SpreadImage(const Image *image,const double radius,
 %
 */
 
+#define ListChannels  5
+
+typedef struct _ListNode
+{
+  size_t
+    next[9],
+    count,
+    signature;
+} ListNode;
+
+typedef struct _SkipList
+{
+  ssize_t
+    level;
+
+  ListNode
+    *nodes;
+} SkipList;
+
+typedef struct _PixelList
+{
+  size_t
+    center,
+    seed,
+    signature;
+
+  SkipList
+    lists[ListChannels];
+} PixelList;
+
+static PixelList *DestroyPixelList(PixelList *pixel_list)
+{
+  register ssize_t
+    i;
+
+  if (pixel_list == (PixelList *) NULL)
+    return((PixelList *) NULL);
+  for (i=0; i < ListChannels; i++)
+    if (pixel_list->lists[i].nodes != (ListNode *) NULL)
+      pixel_list->lists[i].nodes=(ListNode *) RelinquishMagickMemory(
+        pixel_list->lists[i].nodes);
+  pixel_list=(PixelList *) RelinquishMagickMemory(pixel_list);
+  return(pixel_list);
+}
+
+static PixelList **DestroyPixelListThreadSet(PixelList **pixel_list)
+{
+  register ssize_t
+    i;
+
+  assert(pixel_list != (PixelList **) NULL);
+  for (i=0; i < (ssize_t) GetOpenMPMaximumThreads(); i++)
+    if (pixel_list[i] != (PixelList *) NULL)
+      pixel_list[i]=DestroyPixelList(pixel_list[i]);
+  pixel_list=(PixelList **) RelinquishMagickMemory(pixel_list);
+  return(pixel_list);
+}
+
+static PixelList *AcquirePixelList(const size_t width)
+{
+  PixelList
+    *pixel_list;
+
+  register ssize_t
+    i;
+
+  pixel_list=(PixelList *) AcquireMagickMemory(sizeof(*pixel_list));
+  if (pixel_list == (PixelList *) NULL)
+    return(pixel_list);
+  (void) ResetMagickMemory((void *) pixel_list,0,sizeof(*pixel_list));
+  pixel_list->center=width*width/2;
+  for (i=0; i < ListChannels; i++)
+  {
+    pixel_list->lists[i].nodes=(ListNode *) AcquireQuantumMemory(65537UL,
+      sizeof(*pixel_list->lists[i].nodes));
+    if (pixel_list->lists[i].nodes == (ListNode *) NULL)
+      return(DestroyPixelList(pixel_list));
+    (void) ResetMagickMemory(pixel_list->lists[i].nodes,0,65537UL*
+      sizeof(*pixel_list->lists[i].nodes));
+  }
+  pixel_list->signature=MagickSignature;
+  return(pixel_list);
+}
+
+static PixelList **AcquirePixelListThreadSet(const size_t width)
+{
+  PixelList
+    **pixel_list;
+
+  register ssize_t
+    i;
+
+  size_t
+    number_threads;
+
+  number_threads=GetOpenMPMaximumThreads();
+  pixel_list=(PixelList **) AcquireQuantumMemory(number_threads,
+    sizeof(*pixel_list));
+  if (pixel_list == (PixelList **) NULL)
+    return((PixelList **) NULL);
+  (void) ResetMagickMemory(pixel_list,0,number_threads*sizeof(*pixel_list));
+  for (i=0; i < (ssize_t) number_threads; i++)
+  {
+    pixel_list[i]=AcquirePixelList(width);
+    if (pixel_list[i] == (PixelList *) NULL)
+      return(DestroyPixelListThreadSet(pixel_list));
+  }
+  return(pixel_list);
+}
+
+static void AddNodePixelList(PixelList *pixel_list,const ssize_t channel,
+  const size_t color)
+{
+  register SkipList
+    *list;
+
+  register ssize_t
+    level;
+
+  size_t
+    search,
+    update[9];
+
+  /*
+    Initialize the node.
+  */
+  list=pixel_list->lists+channel;
+  list->nodes[color].signature=pixel_list->signature;
+  list->nodes[color].count=1;
+  /*
+    Determine where it belongs in the list.
+  */
+  search=65536UL;
+  for (level=list->level; level >= 0; level--)
+  {
+    while (list->nodes[search].next[level] < color)
+      search=list->nodes[search].next[level];
+    update[level]=search;
+  }
+  /*
+    Generate a pseudo-random level for this node.
+  */
+  for (level=0; ; level++)
+  {
+    pixel_list->seed=(pixel_list->seed*42893621L)+1L;
+    if ((pixel_list->seed & 0x300) != 0x300)
+      break;
+  }
+  if (level > 8)
+    level=8;
+  if (level > (list->level+2))
+    level=list->level+2;
+  /*
+    If we're raising the list's level, link back to the root node.
+  */
+  while (level > list->level)
+  {
+    list->level++;
+    update[list->level]=65536UL;
+  }
+  /*
+    Link the node into the skip-list.
+  */
+  do
+  {
+    list->nodes[color].next[level]=list->nodes[update[level]].next[level];
+    list->nodes[update[level]].next[level]=color;
+  }
+  while (level-- > 0);
+}
+
+static MagickPixelPacket GetMedianPixelList(PixelList *pixel_list)
+{
+  MagickPixelPacket
+    pixel;
+
+  register SkipList
+    *list;
+
+  register ssize_t
+    channel;
+
+  size_t
+    center,
+    color,
+    count;
+
+  unsigned short
+    channels[ListChannels];
+
+  /*
+    Find the median value for each of the color.
+  */
+  center=pixel_list->center;
+  for (channel=0; channel < 5; channel++)
+  {
+    list=pixel_list->lists+channel;
+    color=65536UL;
+    count=0;
+    do
+    {
+      color=list->nodes[color].next[0];
+      count+=list->nodes[color].count;
+    }
+    while (count <= center);
+    channels[channel]=(unsigned short) color;
+  }
+  GetMagickPixelPacket((const Image *) NULL,&pixel);
+  pixel.red=(MagickRealType) ScaleShortToQuantum(channels[0]);
+  pixel.green=(MagickRealType) ScaleShortToQuantum(channels[1]);
+  pixel.blue=(MagickRealType) ScaleShortToQuantum(channels[2]);
+  pixel.opacity=(MagickRealType) ScaleShortToQuantum(channels[3]);
+  pixel.index=(MagickRealType) ScaleShortToQuantum(channels[4]);
+  return(pixel);
+}
+
+static MagickPixelPacket GetModePixelList(PixelList *pixel_list)
+{
+  MagickPixelPacket
+    pixel;
+
+  register SkipList
+    *list;
+
+  register ssize_t
+    channel;
+
+  size_t
+    color,
+    count,
+    max_count,
+    mode,
+    width;
+
+  unsigned short
+    channels[5];
+
+  /*
+    Make each pixel the 'predominate color' of the specified neighborhood.
+  */
+  width=pixel_list->center << 1;
+  for (channel=0; channel < 5; channel++)
+  {
+    list=pixel_list->lists+channel;
+    color=65536UL;
+    mode=color;
+    max_count=list->nodes[mode].count;
+    count=0;
+    do
+    {
+      color=list->nodes[color].next[0];
+      if (list->nodes[color].count > max_count)
+        {
+          mode=color;
+          max_count=list->nodes[mode].count;
+        }
+      count+=list->nodes[color].count;
+    }
+    while (count <= width);
+    channels[channel]=(unsigned short) mode;
+  }
+  GetMagickPixelPacket((const Image *) NULL,&pixel);
+  pixel.red=(MagickRealType) ScaleShortToQuantum(channels[0]);
+  pixel.green=(MagickRealType) ScaleShortToQuantum(channels[1]);
+  pixel.blue=(MagickRealType) ScaleShortToQuantum(channels[2]);
+  pixel.opacity=(MagickRealType) ScaleShortToQuantum(channels[3]);
+  pixel.index=(MagickRealType) ScaleShortToQuantum(channels[4]);
+  return(pixel);
+}
+
+static MagickPixelPacket GetNonpeakPixelList(PixelList *pixel_list)
+{
+  MagickPixelPacket
+    pixel;
+
+  register SkipList
+    *list;
+
+  register ssize_t
+    channel;
+
+  size_t
+    center,
+    color,
+    count,
+    next,
+    previous;
+
+  unsigned short
+    channels[5];
+
+  /*
+    Finds the median value for each of the color.
+  */
+  center=pixel_list->center;
+  for (channel=0; channel < 5; channel++)
+  {
+    list=pixel_list->lists+channel;
+    color=65536UL;
+    next=list->nodes[color].next[0];
+    count=0;
+    do
+    {
+      previous=color;
+      color=next;
+      next=list->nodes[color].next[0];
+      count+=list->nodes[color].count;
+    }
+    while (count <= center);
+    if ((previous == 65536UL) && (next != 65536UL))
+      color=next;
+    else
+      if ((previous != 65536UL) && (next == 65536UL))
+        color=previous;
+    channels[channel]=(unsigned short) color;
+  }
+  GetMagickPixelPacket((const Image *) NULL,&pixel);
+  pixel.red=(MagickRealType) ScaleShortToQuantum(channels[0]);
+  pixel.green=(MagickRealType) ScaleShortToQuantum(channels[1]);
+  pixel.blue=(MagickRealType) ScaleShortToQuantum(channels[2]);
+  pixel.opacity=(MagickRealType) ScaleShortToQuantum(channels[3]);
+  pixel.index=(MagickRealType) ScaleShortToQuantum(channels[4]);
+  return(pixel);
+}
+
+static inline void InsertPixelList(const Image *image,const PixelPacket *pixel,
+  const IndexPacket *indexes,PixelList *pixel_list)
+{
+  size_t
+    signature;
+
+  unsigned short
+    index;
+
+  index=ScaleQuantumToShort(pixel->red);
+  signature=pixel_list->lists[0].nodes[index].signature;
+  if (signature == pixel_list->signature)
+    pixel_list->lists[0].nodes[index].count++;
+  else
+    AddNodePixelList(pixel_list,0,index);
+  index=ScaleQuantumToShort(pixel->green);
+  signature=pixel_list->lists[1].nodes[index].signature;
+  if (signature == pixel_list->signature)
+    pixel_list->lists[1].nodes[index].count++;
+  else
+    AddNodePixelList(pixel_list,1,index);
+  index=ScaleQuantumToShort(pixel->blue);
+  signature=pixel_list->lists[2].nodes[index].signature;
+  if (signature == pixel_list->signature)
+    pixel_list->lists[2].nodes[index].count++;
+  else
+    AddNodePixelList(pixel_list,2,index);
+  index=ScaleQuantumToShort(pixel->opacity);
+  signature=pixel_list->lists[3].nodes[index].signature;
+  if (signature == pixel_list->signature)
+    pixel_list->lists[3].nodes[index].count++;
+  else
+    AddNodePixelList(pixel_list,3,index);
+  if (image->colorspace == CMYKColorspace)
+    index=ScaleQuantumToShort(*indexes);
+  signature=pixel_list->lists[4].nodes[index].signature;
+  if (signature == pixel_list->signature)
+    pixel_list->lists[4].nodes[index].count++;
+  else
+    AddNodePixelList(pixel_list,4,index);
+}
+
+static void ResetPixelList(PixelList *pixel_list)
+{
+  int
+    level;
+
+  register ListNode
+    *root;
+
+  register SkipList
+    *list;
+
+  register ssize_t
+    channel;
+
+  /*
+    Reset the skip-list.
+  */
+  for (channel=0; channel < 5; channel++)
+  {
+    list=pixel_list->lists+channel;
+    root=list->nodes+65536UL;
+    list->level=0;
+    for (level=0; level < 9; level++)
+      root->next[level]=65536UL;
+  }
+  pixel_list->seed=pixel_list->signature++;
+}
+
 MagickExport Image *StatisticImage(const Image *image,const StatisticType type,
   const double radius,ExceptionInfo *exception)
 {
index 4b7a586c2471394db3f29f3b25ca4e5e36705e96..0c5f8f227a4230188b136729f102331f63d7e3b8 100644 (file)
@@ -92,8 +92,6 @@ extern MagickExport Image
   *GaussianBlurImage(const Image *,const double,const double,ExceptionInfo *),
   *GaussianBlurImageChannel(const Image *,const ChannelType,const double,
     const double,ExceptionInfo *),
-  *MedianFilterImage(const Image *,const double,ExceptionInfo *),
-  *ModeImage(const Image *,const double,ExceptionInfo *),
   *MotionBlurImage(const Image *,const double,const double,const double,
     ExceptionInfo *),
   *MotionBlurImageChannel(const Image *,const ChannelType,const double,
@@ -102,7 +100,6 @@ extern MagickExport Image
   *RadialBlurImage(const Image *,const double,ExceptionInfo *),
   *RadialBlurImageChannel(const Image *,const ChannelType,const double,
     ExceptionInfo *),
-  *ReduceNoiseImage(const Image *,const double,ExceptionInfo *),
   *SelectiveBlurImage(const Image *,const double,const double,const double,
     ExceptionInfo *),
   *SelectiveBlurImageChannel(const Image *,const ChannelType,const double,
index c8c14416d1d5213b99efbb383d207c5ddc16759c..abfe231ac8dc5cf521bc25f347f6c684e3457e3e 100644 (file)
@@ -968,7 +968,7 @@ MagickExport Image *DeskewImage(const Image *image,const double threshold,
   clone_image=DestroyImage(clone_image);
   if (deskew_image == (Image *) NULL)
     return((Image *) NULL);
-  median_image=MedianFilterImage(deskew_image,0.0,exception);
+  median_image=StatisticImage(deskew_image,MedianStatistic,0.0,exception);
   if (median_image == (Image *) NULL)
     {
       deskew_image=DestroyImage(deskew_image);
index 3927d1cb0693528bc5a07237f37b45013ea1aeb7..37279dca3799f366d3ae732223deaa75220f61bf 100644 (file)
@@ -1646,39 +1646,45 @@ WandExport MagickBooleanType MagickMatteFloodfillImage(MagickWand *wand,
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%   M a g i c k M a x i m u m I m a g e s                                     %
+%   M a g i c k M e d i a n F i l t e r I m a g e                             %
 %                                                                             %
 %                                                                             %
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  MagickMaximumImages() returns the maximum intensity of an image sequence.
+%  MagickMedianFilterImage() applies a digital filter that improves the quality
+%  of a noisy image.  Each pixel is replaced by the median in a set of
+%  neighboring pixels as defined by radius.
 %
-%  The format of the MagickMaximumImages method is:
+%  The format of the MagickMedianFilterImage method is:
 %
-%      MagickWand *MagickMaximumImages(MagickWand *wand)
+%      MagickBooleanType MagickMedianFilterImage(MagickWand *wand,
+%        const double radius)
 %
 %  A description of each parameter follows:
 %
 %    o wand: the magick wand.
 %
+%    o radius: the radius of the pixel neighborhood.
+%
 */
-WandExport MagickWand *MagickMaximumImages(MagickWand *wand)
+WandExport MagickBooleanType MagickMedianFilterImage(MagickWand *wand,
+  const double radius)
 {
   Image
-    *maximum_image;
+    *median_image;
 
   assert(wand != (MagickWand *) NULL);
   assert(wand->signature == WandSignature);
   if (wand->debug != MagickFalse)
     (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
   if (wand->images == (Image *) NULL)
-    return((MagickWand *) NULL);
-  maximum_image=EvaluateImages(wand->images,MaxEvaluateOperator,
-    wand->exception);
-  if (maximum_image == (Image *) NULL)
-    return((MagickWand *) NULL);
-  return(CloneMagickWandFromImages(wand,maximum_image));
+    ThrowWandException(WandError,"ContainsNoImages",wand->name);
+  median_image=MedianFilterImage(wand->images,radius,wand->exception);
+  if (median_image == (Image *) NULL)
+    return(MagickFalse);
+  ReplaceImageInList(&wand->images,median_image);
+  return(MagickTrue);
 }
 \f
 /*
@@ -1726,6 +1732,51 @@ WandExport MagickWand *MagickMinimumImages(MagickWand *wand)
 %                                                                             %
 %                                                                             %
 %                                                                             %
+%   M a g i c k M o d e I m a g e                                             %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  MagickModeImage() makes each pixel the 'predominate color' of the
+%  neighborhood of the specified radius.
+%
+%  The format of the MagickModeImage method is:
+%
+%      MagickBooleanType MagickModeImage(MagickWand *wand,
+%        const double radius)
+%
+%  A description of each parameter follows:
+%
+%    o wand: the magick wand.
+%
+%    o radius: the radius of the pixel neighborhood.
+%
+*/
+WandExport MagickBooleanType MagickModeImage(MagickWand *wand,
+  const double radius)
+{
+  Image
+    *mode_image;
+
+  assert(wand != (MagickWand *) NULL);
+  assert(wand->signature == WandSignature);
+  if (wand->debug != MagickFalse)
+    (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
+  if (wand->images == (Image *) NULL)
+    ThrowWandException(WandError,"ContainsNoImages",wand->name);
+  mode_image=ModeImage(wand->images,radius,wand->exception);
+  if (mode_image == (Image *) NULL)
+    return(MagickFalse);
+  ReplaceImageInList(&wand->images,mode_image);
+  return(MagickTrue);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
 %   M a g i c k M o s a i c I m a g e s                                       %
 %                                                                             %
 %                                                                             %
@@ -2021,6 +2072,93 @@ WandExport MagickBooleanType MagickRecolorImage(MagickWand *wand,
 %                                                                             %
 %                                                                             %
 %                                                                             %
+%     M a g i c k R e d u c e N o i s e I m a g e                             %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  MagickReduceNoiseImage() smooths the contours of an image while still
+%  preserving edge information.  The algorithm works by replacing each pixel
+%  with its neighbor closest in value.  A neighbor is defined by radius.  Use
+%  a radius of 0 and ReduceNoise() selects a suitable radius for you.
+%
+%  The format of the MagickReduceNoiseImage method is:
+%
+%      MagickBooleanType MagickReduceNoiseImage(MagickWand *wand,
+%        const double radius)
+%
+%  A description of each parameter follows:
+%
+%    o wand: the magick wand.
+%
+%    o radius: the radius of the pixel neighborhood.
+%
+*/
+WandExport MagickBooleanType MagickReduceNoiseImage(MagickWand *wand,
+  const double radius)
+{
+  Image
+    *noise_image;
+
+  assert(wand != (MagickWand *) NULL);
+  assert(wand->signature == WandSignature);
+  if (wand->debug != MagickFalse)
+    (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
+  if (wand->images == (Image *) NULL)
+    ThrowWandException(WandError,"ContainsNoImages",wand->name);
+  noise_image=ReduceNoiseImage(wand->images,radius,wand->exception);
+  if (noise_image == (Image *) NULL)
+    return(MagickFalse);
+  ReplaceImageInList(&wand->images,noise_image);
+  return(MagickTrue);
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%   M a g i c k M a x i m u m I m a g e s                                     %
+%                                                                             %
+%                                                                             %
+%                                                                             %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%
+%  MagickMaximumImages() returns the maximum intensity of an image sequence.
+%
+%  The format of the MagickMaximumImages method is:
+%
+%      MagickWand *MagickMaximumImages(MagickWand *wand)
+%
+%  A description of each parameter follows:
+%
+%    o wand: the magick wand.
+%
+*/
+WandExport MagickWand *MagickMaximumImages(MagickWand *wand)
+{
+  Image
+    *maximum_image;
+
+  assert(wand != (MagickWand *) NULL);
+  assert(wand->signature == WandSignature);
+  if (wand->debug != MagickFalse)
+    (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
+  if (wand->images == (Image *) NULL)
+    return((MagickWand *) NULL);
+  maximum_image=EvaluateImages(wand->images,MaxEvaluateOperator,
+    wand->exception);
+  if (maximum_image == (Image *) NULL)
+    return((MagickWand *) NULL);
+  return(CloneMagickWandFromImages(wand,maximum_image));
+}
+\f
+/*
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%                                                                             %
+%                                                                             %
+%                                                                             %
 %   M a g i c k S e t I m a g e A t t r i b u t e                             %
 %                                                                             %
 %                                                                             %
@@ -2065,7 +2203,8 @@ WandExport MagickBooleanType MagickSetImageAttribute(MagickWand *wand,
 %
 %  The format of the MagickSetImageIndex method is:
 %
-%      MagickBooleanType MagickSetImageIndex(MagickWand *wand,const ssize_t index)
+%      MagickBooleanType MagickSetImageIndex(MagickWand *wand,
+%        const ssize_t index)
 %
 %  A description of each parameter follows:
 %
index 2be2b9c94609339f28c772d2ba9e9a88f7525508..8e9131149238de537de53adb4b22f39a744b5ecb 100644 (file)
@@ -88,6 +88,12 @@ extern WandExport MagickBooleanType
   MagickMatteFloodfillImage(MagickWand *,const double,const double,
     const PixelWand *,const ssize_t,const ssize_t)
     magick_attribute((deprecated)),
+  MagickMedianFilterImage(MagickWand *,const double)
+    magick_attribute((deprecated)),
+  MagickModeImage(MagickWand *,const double) magick_attribute((deprecated)),
+  MagickReduceNoiseImage(MagickWand *,const double)
+    magick_attribute((deprecated)),
+  MagickRemapImage(MagickWand *,const MagickWand *,const DitherMethod),
   MagickOpaqueImage(MagickWand *,const PixelWand *,const PixelWand *,
     const double) magick_attribute((deprecated)),
   MagickPaintFloodfillImage(MagickWand *,const ChannelType,const PixelWand *,
index c5ed43981b20c37d7515062fbe6feb0058c74661..6053f795dc22539a698bfb18c395502a26fa0538 100644 (file)
@@ -6812,60 +6812,14 @@ WandExport MagickBooleanType MagickMagnifyImage(MagickWand *wand)
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%   M a g i c k M e d i a n F i l t e r I m a g e                             %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  MagickMedianFilterImage() applies a digital filter that improves the quality
-%  of a noisy image.  Each pixel is replaced by the median in a set of
-%  neighboring pixels as defined by radius.
-%
-%  The format of the MagickMedianFilterImage method is:
-%
-%      MagickBooleanType MagickMedianFilterImage(MagickWand *wand,
-%        const double radius)
-%
-%  A description of each parameter follows:
-%
-%    o wand: the magick wand.
-%
-%    o radius: the radius of the pixel neighborhood.
-%
-*/
-WandExport MagickBooleanType MagickMedianFilterImage(MagickWand *wand,
-  const double radius)
-{
-  Image
-    *median_image;
-
-  assert(wand != (MagickWand *) NULL);
-  assert(wand->signature == WandSignature);
-  if (wand->debug != MagickFalse)
-    (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
-  if (wand->images == (Image *) NULL)
-    ThrowWandException(WandError,"ContainsNoImages",wand->name);
-  median_image=MedianFilterImage(wand->images,radius,wand->exception);
-  if (median_image == (Image *) NULL)
-    return(MagickFalse);
-  ReplaceImageInList(&wand->images,median_image);
-  return(MagickTrue);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
 %   M a g i c k M e r g e I m a g e L a y e r s                               %
 %                                                                             %
 %                                                                             %
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  MagickMergeImageLayers() composes all the image layers from the current given
-%  image onward to produce a single image of the merged layers.
+%  MagickMergeImageLayers() composes all the image layers from the current
+%  given image onward to produce a single image of the merged layers.
 %
 %  The inital canvas's size depends on the given ImageLayerMethod, and is
 %  initialized using the first images background color.  The images
@@ -6960,51 +6914,6 @@ WandExport MagickBooleanType MagickMinifyImage(MagickWand *wand)
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%   M a g i c k M o d e I m a g e                                             %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  MagickModeImage() makes each pixel the 'predominate color' of the
-%  neighborhood if the specified radius.
-%
-%  The format of the MagickModeImage method is:
-%
-%      MagickBooleanType MagickModeImage(MagickWand *wand,
-%        const double radius)
-%
-%  A description of each parameter follows:
-%
-%    o wand: the magick wand.
-%
-%    o radius: the radius of the pixel neighborhood.
-%
-*/
-WandExport MagickBooleanType MagickModeImage(MagickWand *wand,
-  const double radius)
-{
-  Image
-    *mode_image;
-
-  assert(wand != (MagickWand *) NULL);
-  assert(wand->signature == WandSignature);
-  if (wand->debug != MagickFalse)
-    (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
-  if (wand->images == (Image *) NULL)
-    ThrowWandException(WandError,"ContainsNoImages",wand->name);
-  mode_image=ModeImage(wand->images,radius,wand->exception);
-  if (mode_image == (Image *) NULL)
-    return(MagickFalse);
-  ReplaceImageInList(&wand->images,mode_image);
-  return(MagickTrue);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
 %   M a g i c k M o d u l a t e I m a g e                                     %
 %                                                                             %
 %                                                                             %
@@ -8656,53 +8565,6 @@ WandExport MagickBooleanType MagickReadImageFile(MagickWand *wand,FILE *file)
 %                                                                             %
 %                                                                             %
 %                                                                             %
-%     M a g i c k R e d u c e N o i s e I m a g e                             %
-%                                                                             %
-%                                                                             %
-%                                                                             %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-%  MagickReduceNoiseImage() smooths the contours of an image while still
-%  preserving edge information.  The algorithm works by replacing each pixel
-%  with its neighbor closest in value.  A neighbor is defined by radius.  Use
-%  a radius of 0 and ReduceNoise() selects a suitable radius for you.
-%
-%  The format of the MagickReduceNoiseImage method is:
-%
-%      MagickBooleanType MagickReduceNoiseImage(MagickWand *wand,
-%        const double radius)
-%
-%  A description of each parameter follows:
-%
-%    o wand: the magick wand.
-%
-%    o radius: the radius of the pixel neighborhood.
-%
-*/
-WandExport MagickBooleanType MagickReduceNoiseImage(MagickWand *wand,
-  const double radius)
-{
-  Image
-    *noise_image;
-
-  assert(wand != (MagickWand *) NULL);
-  assert(wand->signature == WandSignature);
-  if (wand->debug != MagickFalse)
-    (void) LogMagickEvent(WandEvent,GetMagickModule(),"%s",wand->name);
-  if (wand->images == (Image *) NULL)
-    ThrowWandException(WandError,"ContainsNoImages",wand->name);
-  noise_image=ReduceNoiseImage(wand->images,radius,wand->exception);
-  if (noise_image == (Image *) NULL)
-    return(MagickFalse);
-  ReplaceImageInList(&wand->images,noise_image);
-  return(MagickTrue);
-}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%                                                                             %
-%                                                                             %
-%                                                                             %
 %   M a g i c k R e m a p I m a g e                                           %
 %                                                                             %
 %                                                                             %
index 40d037d6877108ebf3ecfde280b016dea6ccd714..dbad01e058241d482adfbbf66e993f94b3b24243 100644 (file)
@@ -2190,7 +2190,8 @@ WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
             */
             (void) SyncImageSettings(mogrify_info,*image);
             (void) ParseGeometry(argv[i+1],&geometry_info);
-            median_image=MedianFilterImage(*image,geometry_info.rho,exception);
+            median_image=StatisticImageChannel(*image,channel,MedianStatistic,
+              geometry_info.rho,exception);
             if (median_image == (Image *) NULL)
               break;
             *image=DestroyImage(*image);
@@ -2207,7 +2208,8 @@ WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
             */
             (void) SyncImageSettings(mogrify_info,*image);
             (void) ParseGeometry(argv[i+1],&geometry_info);
-            mode_image=ModeImage(*image,geometry_info.rho,exception);
+            mode_image=StatisticImageChannel(*image,channel,ModeStatistic,
+              geometry_info.rho,exception);
             if (mode_image == (Image *) NULL)
               break;
             *image=DestroyImage(*image);
@@ -2332,8 +2334,8 @@ WandExport MagickBooleanType MogrifyImage(ImageInfo *image_info,const int argc,
             if (*option == '-')
               {
                 (void) ParseGeometry(argv[i+1],&geometry_info);
-                noisy_image=ReduceNoiseImage(*image,geometry_info.rho,
-                  exception);
+                noisy_image=StatisticImageChannel(*image,channel,
+                  NonpeakStatistic,geometry_info.rho,exception);
               }
             else
               {