Image editing is used in various applications to manipulate images for further processing. We have written a series of blogs, i.e. cropping, rotating, blurring, etc., which are useful for you to implement image editing features in your applications. In this article, we are going to show you how to apply median and wiener filters, which are commonly used to denoise and smoothen images. So let’s see how to apply median and wiener filers to an image programmatically in C#.
- C# API to Apply Median and Wiener Image Filters
- Apply Median Filter to an Image in C#
- Apply Gauss Wiener Filter to an Image
- Motion Wiener Filtering of an Image
C# API to Apply Median and Wiener Image Filters - Free Download
Aspose.Imaging for .NET is an amazing API to implement image editing features in .NET applications. We will use this API for applying median and wiener filters on images. You can either download the API or install it from NuGet.
PM> Install-Package Aspose.Imaging
Apply Median Filter to an Image in C#
The median filter is a nonlinear digital filtering technique, which is used to reduce noise from the images. The following are the steps to apply a median filter to an image in C#.
- First, load the image using Image.Load() method.
- Then, cast image to RasterImage type.
- Create an instance of MedianFilterOptions class and initialize it with the size of the rectangle.
- Apply the median filter using RasterImage.Filter(Rectangle, MedianFilterOptions) method.
- Finally, save the resultant image using RasterImage.Save() method.
The following code sample shows how to apply a median filter to an image in C#.
Below is the image before and after applying the median filter.
Apply Gauss Wiener Filter to an Image in C#
Another commonly used method for minimizing additive noise and blurring in the images is gauss wiener. The following are the steps to apply the gauss wiener filter to an image in C#.
- First, load the image using Image.Load() method.
- Then, cast image to RasterImage type.
- Create an instance of GaussWienerFilterOptions class and initialize it with radius size and smooth value.
- (Optional) To get a grayscale image, set GaussWienerFilterOptions.Grayscale property to true.
- Apply gauss wiener filter using RasterImage.Filter(Rectangle, GaussWienerFilterOptions) method.
- Finally, save the resultant image using RasterImage.Save() method.
The following code sample shows how to apply a gauss wiener filter to an image in C#.
Below is the image before and after applying the gauss wiener filter with the greyscale option.
The following is the image before and after applying the gauss wiener filter without greyscaling.
Apply Motion Wiener Filter to an Image in C#
Motion wiener filter is used to remove blurring of an image that is produced because of the moving objects. The following are the steps to apply the motion wiener filter to an image in C#.
- First, load the image using Image.Load() method.
- Then, cast image to RasterImage type.
- Create an instance of MotionWienerFilterOptions class and initialize it with length, smooth value and angle.
- Apply motion wiener filter using RasterImage.Filter(Rectangle, MotionWienerFilterOptions) method.
- Finally, save the resultant image using RasterImage.Save() method.
The following code sample shows how to apply a motion wiener filter to an image in C#.
C# Median and Wiener Image Filtering API - Get a Free License
You can get a free temporary license and apply median and wiener filters to images without evaluation limitations.
Conclusion
In this article, you have learned how to apply median and wiener filters to images in C#. Furthermore, we have covered how to reduce the noise of moving objects in an image. You can easily use these features in your C# application to integrate image editing capabilities.
Read More
You can explore more about the .NET image processing API using documentation. Also, you can share your queries with us via our forum.