To make image looking more sharp, Graphics Mill for .NET provides two ways: simple sharpen filter and unsharp mask. This article demonstrates how to use both of them.
The common sharpen filter is easy to use. It has the single intuitive parameter - sharpen strength, which varies in range [0,100]. The higher sharpen strength you specify, the more strong sharpness you will get.
In Graphics Mill for .NET this filter is represented by transform Sharpen. The filter stength is specified with the property Strength. For shorter syntax, you can also use Sharpen(Int32) method of the TransformsProvider returned by the Bitmap.
The figures below demonstrate a result of this filter.
Source image:
Sharpened image:
Use this code to get above result:
'Sharpen the image (strongly) bitmap.Transforms.Sharpen(95)
//Sharpen the image (strongly) bitmap.Transforms.Sharpen(95);
The same, but using Sharpen class.
'Sharpen the image (strongly) Dim sharpen As New Aurigma.GraphicsMill.Transforms.Sharpen sharpen.Strength = 95 sharpen.ApplyTransform(bitmap)
//Sharpen the image (strongly) Aurigma.GraphicsMill.Transforms.Sharpen sharpen = new Aurigma.GraphicsMill.Transforms.Sharpen(); sharpen.Strength = 95; sharpen.ApplyTransform(bitmap);
Note, specifying high values of the sharpen strength will produce color distortions (see the figure below).
Sharpen filter is simple to use, but provides too few control. That's why there is an alternative and more advanced sharpening algorithm - unsharp mask.
Unsharp mask is a classic sharpening technique, which was widely used by photographers in precomputer times. The main idea is to blend image with blurred (out-of-focus) version. It will emphasis edges and make the image more sharp.
To apply unsharp mask algorithm, Graphics Mill for .NET provides a transform class UnsharpMask (and appropriate UnsharpMask method of the TransformsProvider returned by the Bitmap). It contains three parameters: the amount of sharpen, the radius of blur and the threshold.
The first parameter specifies how strong to sharpen the image. As mentioned above, algorithm creates blurred version of the image and for each pixel calculate the difference between original and blurred image. After that, it uses this difference to shapen image. Actually, Graphics Mill for .NET adds difference*amount to each pixel of the original image. This parameter is modified with an Amount property.
The second parameter specifies radius of blur effect which creates defocused image. The higher value you specify, the wider will be edges. That's why be carefull when you adjust this parameter - big radius will lead to unnatural effects (false halo around objects of the image). This parameter is modified with a Radius property.
The third parameter specifies a threshold of the effect. If difference between pixels of original and blurred images is less than threshold, difference is discarded. It allow to keep minor details unchanged and apply sharpening only on noticeable details. For example, if you sharpen a photo which contains face, you would like to sharpen facial features (nose, lips, eyes, etc), but do not emphasis pimples, birthmark and other minor details. This parameter is modified with a Threshold property.
As you see, using unsharp mask is harder to use comparing to sharpen filter, but it allows producing much better result. The figure below demonstrates an example of unsharp mask result.
The code below demonstrates how to get this image:
'Sharpen image via unsharp mask bitmap.Transforms.UnsharpMask(1.5, 2.1, 0.04)
//Sharpen image via unsharp mask bitmap.Transforms.UnsharpMask(1.5f, 2.1f, 0.04f);
The same, but using UnsharpMask class.
'Sharpen image via unsharp mask Dim unsharpMask As New Aurigma.GraphicsMill.Transforms.UnsharpMask unsharpMask.Amount = 1.5 unsharpMask.Radius = 2.1 unsharpMask.Threshold = 0.04 unsharpMask.ApplyTransform(bitmap)
//Sharpen image via unsharp mask Aurigma.GraphicsMill.Transforms.UnsharpMask unsharpMask = new Aurigma.GraphicsMill.Transforms.UnsharpMask(); unsharpMask.Amount = 1.5f; unsharpMask.Radius = 2.1f; unsharpMask.Threshold = 0.04f; unsharpMask.ApplyTransform(bitmap);