Skip to content
首页 » 博客 » Apply Median and Wiener Filters to Images in Java

Apply Median and Wiener Filters to Images in Java

Apply Median and Wiener Filters to Images in Java

In the previous blog post, we demonstrated how to add the blur effect to the images. Today, we are going to show you how to apply median and wiener filters, which are commonly used to denoise and smoothen the images. So let’s see how to apply median and wiener filers to an image programmatically in Java.

  • Java API to Apply Median and Wiener Image Filters
  • Apply Median Filter to an Image in Java
  • Apply Gauss Wiener Filter to an Image
  • Motion Wiener Filtering of an Image

Apply Median and Wiener Image Filters in Java – API Installation#

To apply the median and wiener filters on images, we will use Aspose.Imaging for Java. It is a powerful image editing API to manipulate the images from within the Java applications. You can either download the API or install it using the following Maven configurations.

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
</repository> 

<dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-imaging</artifactId>
    <version>22.9</version>
</dependency>

Apply Median Filter to an Image in Java#

The median filter is a nonlinear digital filtering technique, which is a popular way to denoise the images. The following are the steps to apply a median filter to an image in Java.

  • 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 Java.

Below is the image before and after applying the median filter.

Apply Median and Wiener Filters to Images in Java

Apply Gauss Wiener Filter to an Image in Java#

Gauss wiener is another commonly used method for image grading by minimizing additive noise and blurring. The following are the steps to apply the gauss wiener filter to an image in Java.

  • 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, use GaussWienerFilterOptions.setGrayscale(true) method.
  • 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 Java.

Below is the image before and after applying the gauss wiener filter with the greyscale option.

Apply Median and Wiener Filters to Images in Java

The following is the image before and after applying the gauss wiener filter without greyscaling.

Apply Median and Wiener Filters to Images in Java

Use Motion Wiener Filter for an Image in Java#

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 Java.

  • 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 Java.

Apply Median and Wiener Filters to Images in Java

Java 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 Java. Furthermore, we have covered how to reduce the noise of moving objects in an image. You can easily use these features in your Java application to integrate image editing capabilities.

Read More#

You can explore more about the Java image processing API using documentation. Also, you can share your queries with us via our forum.

See Also#

  • Convert Images to Grayscale in C#
  • Add Watermark to Images using C#
  • Compress PNG, JPEG, and TIFF Images using C#
  • Image Cropping in C#