Site iconJava PDF Blog

Blurring Images in Java: Simple & Gaussian Blur Code Examples

blur image before vs after

Blurring is a fundamental image processing technique used to reduce noise, smooth features, and produce aesthetic effects. In Java, you can easily apply different types of blur using image processing libraries like JDeli.

This post will guide you through basic blurring and Gaussian blurring of images in Java, explaining their differences and practical implementations.

What is Image Blurring?

Blurring involves averaging the colours of neighbouring pixels to produce a softer, smoother appearance. This is often used to de-emphasize background elements, eliminate noise, or prepare images for further processing such as edge detection.

Think of blurring as “softening the hard edges” in a picture. When you blur an image, you’re basically averaging out the colors of neighboring pixels so everything looks a bit smoother and gentler.

Java Code to Blur an Image with JDeli

Let’s jump right in. With JDeli, you can get a basic blur applied in just a few lines of code:

You’ve also got options for working with images from files, streams, or even byte arrays. Here are a few quick examples:

Using Files

Using Streams

Using Files


 

What is a Gaussian Blur?

Instead of just averaging nearby pixels equally, Gaussian blur uses a bell-shaped curve (the famous Gaussian function!) to weigh nearby pixels, ones closer to the centre have a bigger impact on the result.

How to Use Gaussian Blur in Java with JDeli

Doing a Gaussian blur in JDeli is just as simple as the basic blur:


As with the basic blur, you can use this operation on files, streams, or byte arrays. The only real difference in your code is replacing blur() with gaussianBlur().
 

Which Blur Should You Choose?

Blur TypeKey FeaturesIdeal Use Cases
Simple BlurFast and easy, applies a uniform smoothing by averaging neighboring pixels.Basic noise reduction, subtle softening, quick image preprocessing
Gaussian BlurUses weighted averaging based on a Gaussian function for natural, edge-preserving smoothing.Professional photo editing, design enhancements, computer vision preprocessing

JDeli’s API design allows you to experiment with either method easily, so you can choose the result that best fits your needs. It also helps you other ways to manipulate images using a few lines of Java.

If you’d like to explore these techniques further, the JDeli documentation provides more in-depth examples and technical details.