The Unsharp Mask filter is a simple method of sharpening a photo. Areas of complexity and fine detail within the image become crisp and better defined. An Unsharp Mask takes longer to perform than a simple Sharpen but gives more control and produces a more natural appearance.

An Unsharp Mask is essentially a Blur in reverse. A Gaussian Blur is applied to a copy of the original image to produce an image with no fine detail. The blurred image is subtracted from the original to extract the fine detail. This fine detail is then added to the original image to highlight complex areas.

The radius parameter determines the radius of the Gaussian Blur in pixels and lets you choose the level of scale of detail that should be enhanced. The difference between color levels on the blurred and original image is determined at each point on the image. If the difference is greater than the Threshold parameter then the Amount percentage of the difference is added back to the original image

Syntax

[C#]

static void UnsharpMask(Bitmap bitmap, Nullable<double> radius, Nullable<double> amount, Nullable<double> threshold);

[Visual Basic]

Shared Sub UnsharpMask(bitmap As Bitmap, radius As Nullable(Of Double), amount As Nullable(Of Double), threshold As Nullable(Of Double))
Params
Name Description
bitmap The bitmap to process
radius Determines the scale of fine detail that will be enhanced. Low values enhance only very fine detail while high values enhance larger levels of detail. If null is provided this defaults to 1.5 pixels.
amount The level of enhancement to be applied to the fine detail. Values greater than 100% will super-enhance any complex areas. If null is provided this defaults to 60%.
threshold If there is little fine detail then you can choose not to enhance it by setting a threshold. Any detail less than the threshold will not be enhanced. If null is provided this defaults to 0%.
Notes

None.

Example

[C#]using (Bitmap bm = (Bitmap)Bitmap.FromFile(Server.MapPath("rez/tim-mossholder-j8F0PDu5d60-unsplash.jpg"))) {
  Effects.GaussianBlur(bm, 2);
  // no unsharp mask - this is the base blurred image
  bm.Save(Server.MapPath("IG8_Effects_UnsharpMask1.png"));
}
using (Bitmap bm = (Bitmap)Bitmap.FromFile(Server.MapPath("rez/tim-mossholder-j8F0PDu5d60-unsplash.jpg"))) {
  Effects.GaussianBlur(bm, 2);
  Effects.UnsharpMask(bm, null, null, null);
  bm.Save(Server.MapPath("IG8_Effects_UnsharpMask2.png"));
}
using (Bitmap bm = (Bitmap)Bitmap.FromFile(Server.MapPath("rez/tim-mossholder-j8F0PDu5d60-unsplash.jpg"))) {
  Effects.GaussianBlur(bm, 2);
  Effects.UnsharpMask(bm, 8, 140, 40);
  bm.Save(Server.MapPath("IG8_Effects_UnsharpMask3.png"));
}


The following example shows the basic effect of Unsharp Mask on a blurred photo and how the parameters can change the effect produced. Ouput files are shown below.


tim-mossholder-j8F0PDu5d60-unsplash.jpg


IG8_Effects_UnsharpMask1.png


IG8_Effects_UnsharpMask2.png


IG8_Effects_UnsharpMask3.png