The Despeckle filter removes noise from images without blurring edges. It attempts to detect complex areas and leave these intact while smoothing areas where noise will be noticeable.

The Despeckle filter smooths areas in which noise is noticeable while leaving complex areas untouched. The effect is that grain or other noise is reduced without severely affecting edges.

The standard deviation of each pixel and its neighbors is calculated to determine if the area is one of high complexity or low complexity. If the complexity is lower than the threshold then the area is smoothed using a simple mean filter.

Syntax

[C#]

static void Despeckle(Bitmap bitmap, Nullable<double> threshold);

[Visual Basic]

Shared Sub Despeckle(bitmap As Bitmap, threshold As Nullable(Of Double))
Params
Name Description
bitmap The bitmap to process
threshold Threshold of complexity above which the image should not be smoothed. If null is provided this defaults to 20.
Notes

None.

See Also

Median

Example

[C#]

using (Bitmap bm = (Bitmap)Bitmap.FromFile(Server.MapPath("rez/sam-schooler-E9aetBe2w40-unsplash.jpg"))) {
  using (BitmapData data = bm.LockBits(ImageLockMode.ReadWrite, bm.Bounds, bm.PixelFormat)) {
    var rnd = new Random(42);
    for (int i = 0; i < 1000; i++) {
      Point p = new Point(rnd.Next(bm.Width), rnd.Next(bm.Height));
      Color c = data.GetPixel(p.X, p.Y);
      c.R -= Math.Min(c.R, (byte)70);
      c.G -= Math.Min(c.G, (byte)70);
      c.B -= Math.Min(c.B, (byte)70);
      data.SetPixel(p.X, p.Y, c);
    }
  }
  bm.Save(Server.MapPath("IG8_Effects_Despeckle1.jpg"));
  Effects.Despeckle(bm, 50);
  bm.Save(Server.MapPath("IG8_Effects_Despeckle2.jpg"));
}


Here we apply a despeckle effect with different threshold levels. First we apply some speckles to our image, then we try and remove them. Ouput files are shown below.


sam-schooler-E9aetBe2w40-unsplash.jpg


IG8_Effects_Despeckle1.jpg


IG8_Effects_Despeckle2.jpg