You are on page 1of 10

DSP-LAB MINI PROJECT

FINAL REPORT
DONE BY- FACULTY
HASHIL MUHAMMED (B210047EC) DR. SUDEEP PV
G. SAGAR (B210660EC)
EC 02 B8 Batch

OBJECTIVE
i) To perform uniform and gaussian blurring on images.
ii) Demonstrate the difference between uniform and gaussian blurring.
iii) Recover original image from the blurred image using the Wiener filter.
iv) Study the effects of changing the filter size on blurring and deblurring the images.
v) Study the effects of changing NSR on deblurring images.

THEORETICAL BACKGROUND

KERNEL (FILTER) AND CONVOLUTION


Blurring of Images is done by convolving certain filters with
images. When we convolve square kernels with images,
we apply filtering operations by multiplying corresponding
pixel values and kernel coefficients, then summing them up
to obtain new pixel values. Square kernels, represented by
small matrices, determine the effects of convolution such
as blurring or edge detection.

UNIFORM BLURRING
Uniform blurring, also known as box blurring, is a technique in image processing where each
pixel in the output image is computed as the average of the neighbourhood. It effectively
reduces noise and smooths images but may lead to a loss of fine details and edges. It's
implemented using a kernel or filter applied to each pixel using a sliding window approach.
Uniform blurring is commonly used for noise reduction and overall image smoothing.

eg: Uniform (Box) filter

This filter on convolving with the image basically replaces every pixel
with the average value of it’s neighboring pixels. This process often
results in the attenuation of edge pixels, those with significantly different
values compared to their neighboring pixels, leading to a blurred effect.
GAUSSIAN BLURRING

Gaussian blurring is a common technique used in image processing to reduce noise and
smooth images. Unlike uniform blurring, which applies a simple averaging operation over a
neighborhood, Gaussian blurring applies a weighted average using a Gaussian-shaped kernel.
This means that pixels closer to the center of the kernel have more influence on the result than
those farther away, resulting in a smoother and more natural-looking blur. Gaussian blurring
effectively preserves edges and fine details better than uniform blurring. It is widely used in
various image processing tasks, including noise reduction, image smoothing, and
pre-processing for feature extraction and object recognition algorithms.

WIENER FILTER

The Wiener filter is a widely used signal processing technique employed for image
deconvolution, specifically in the context of restoring images degraded by linear and stationary
processes. Named after Norbert Wiener, the filter aims to recover the original, unblurred image
from the observed, degraded image by estimating the inverse filter. It operates by balancing
between noise suppression and signal amplification, leveraging knowledge of the signal and
noise characteristics along with a user-defined noise-to-signal ratio. It looks at the blur and
guesses what the original picture looked like. Then, it uses special math to sharpen the picture
back up, while also getting rid of any unwanted noise. In the end, you get a clearer picture that
looks a lot like the original. The Wiener filter is particularly effective in scenarios where the
degradation process is known or can be accurately modeled, making it a valuable tool in image
restoration, deblurring, and enhancement applications.

NOISE TO SIGNAL RATIO (NSR)


In the Wiener filter algorithm the Noise to Signal Ratio (NSR) is used to control the trade off
between deblurring and noise amplification. Natural images contain some noise in them (eg :
due to low light conditions ) . If the NSR is high the algorithm prioritizes preserving image details
over noise reduction and might enhance the noise in the original image. On the other hand,
setting a low NSR will suppress the noise , but may also result in loss of fine details and
textures in the image. We divide the NSR with the image variance so that it is normalized and
makes sense for the given image.

BLOCK DIAGRAM

EXPLANATION

CONSTRUCTION OF FILTERS
Filters are constructed using fspecial function in MATLAB
uniform_filter = fspecial('average', filter_size);
The uniform filter is constructed by using the ‘average’ option.
gaussian_filter = fspecial('gaussian',filter_size,sigma);
The gaussian filter is constructed using ‘gaussian’ option. The filter size and standard deviation
are also given as inputs.

CONVOLVING THE FILTER WITH IMAGES


The image is convolved with the filters using the imfilter function which takes the image and the
kernel as inputs. The ‘replicate’ option is used to mirror the border pixels to get accurate
convolution even for boundary pixels.
uni_blur = imfilter(A,uniform_filter,'conv','replicate');
gauss_blur = imfilter(A, gaussian_filter,'conv','replicate');

DEBLURRING USING WIENER FILTER


We deblur the images using the deconvwnr function in MATLAB. It takes as input the
corresponding kernel used for blurring, the estimated NSR and the image as inputs. It
reconstructs the original image using the Wiener filter algorithm
deblurred_uniform = deconvwnr(uni_blur, uniform_filter,estimated_nsr);
deblurred_gaussian = deconvwnr(gauss_blur,gaussian_filter,estimated_nsr);

EFFECT OF FILTER SIZE


The filter size is given as an input to the fspecial function and we try to see the effects of
increasing it.
filter_size = [7 7];

EFFECT OF NSR
The NSR is initially set to 0.001 and normalized by dividing with image variance. We try to see
the effect of NSR on deblurred images by changing the value.
estimated_nsr = 0.01/var(A(:));

RESULTS
Here we have convolved the original image with 7x7 filters and standard deviation 2 ( for
gaussian filter) with the original image and produced the blurring effect. It is noticeable that there
are blocking artifacts ( large pixel blocks) in the case of uniform
blurring whereas gaussian blurring produces a more smooth image.
This happens due to averaging effect of uniform blurring where
image is smoothed out too much causing sharp details to become
less distinct and resulting in noticeable artifacts along edges and
boundaries. On the other hand gaussian blur gradually smooths the
image by giving more weight to pixels closer to the center of the filter
kernel and less weight to pixels farther away, applying less blurring
near edges compared to uniform blur. It avoids abrupt changes,
reducing visible artifacts along edges and boundaries.
We note that the wiener filter is able to reconstruct the gaussian blur image better than the
uniform blurred. This is because uniform blurring doesn't match the Wiener filter's expectations
since it creates a more abrupt change in pixel values, whereas the Wiener filter is designed to
work well with smooth, predictable blurring patterns like those produced by Gaussian blurring.
We also notice some lines near the boundaries of the images which might be due to not padding
the images before the deconvolution.
REPEATING THE PROCESS WITH INCREASED FILTER SIZE AND STANDARD DEVIATION

We increased the kernel size to 15x15 and standard deviation to 4 and note that the blurring has
increased as expected. We also note that the deblurring performance is poorer since more
image details are now lost during the blurring process. It is also visible that gaussian blurring still
outperforms uniform blurring
IMPORTANCE OF NSR
Decreasing the NSR

Decreasing the NSR to 0.0001 from 0.001 causes the Wiener filter to give more priority to signal
preservation than noise suppression. Hence we see finer details but with more noise as lines in
the deblurred image.
Increasing the NSR
When we increase the NSR to 0.01 the overall image becomes darker since the algorithm is
now more focused on suppressing the noise by reducing its pixel values, even though it means
the original detail (brightness) of the image is lost. We can also see that the difference between
uniform and gaussian blur decreases since the blocking artifacts are now suppressed more.

CONCLUSION

● Blurring of Images is done by convolving images with certain filters


● The blocking artifacts caused by uniform blur is due to the averaging of sharp edges,
causing abrupt transitions between neighboring pixels
● The gaussian filter avoids this by applying a weighted average that smoothly blends
neighboring pixel values, resulting in a more gradual transition and reduced visibility of
abrupt changes in the image.
● Restoration of gaussian blurred images give better results since Gaussian blurred
images have smoother transitions and follow a more predictable distribution, aligning
better with the assumptions of the Wiener filter, making their restoration easier compared
to uniform blurred images.
● The filter size and standard deviation plays an important role in the amount of blurring of
the images.
● Highly Blurred Images gives poorer results on reconstruction since much of the image
information is lost
● Wiener filter operates by looking at the blurred image, the filter used for blurring and tries
to reconstruct the image by computing a statistical estimate.
● Lesser NSR correlates to more priority to reconstructing the original image, even if it give
rise to noise amplification
● A higher NSR corresponds to further suppression of noise even if the overall quality of
the image is compromised.

REFERENCES

Wikipedia

https://en.wikipedia.org/wiki/Wiener_filter#:~:text=In%20signal%20processing%2C%20the%20
Wiener,noise%20spectra%2C%20and%20additive%20noise.

https://en.wikipedia.org/wiki/Box_blur

https://en.wikipedia.org/wiki/Gaussian_blur

https://en.wikipedia.org/wiki/Wiener_filter

Carnegie Mellon University- CV Course

http://16385.courses.cs.cmu.edu/spring2024/lecture/filtering
Matlab Documentation

https://in.mathworks.com/help/images/ref/deconvwnr.html

https://in.mathworks.com/help/images/ref/fspecial.html

CODE
% Close all figures, clear workspace, and command window
close all;
clc;
clear;
% Read the image and convert it to double precision
A = im2double(imread('building.png'));
% Define filter parameters
filter_size = [7 7];
sigma = 2;
% Create uniform blur filter
uniform_filter = fspecial('average', filter_size);
% Create Gaussian blur filter
gaussian_filter = fspecial('gaussian',filter_size,sigma);
% Apply uniform blur and Gaussian blur to the image
uni_blur = imfilter(A,uniform_filter,'conv','replicate');
gauss_blur = imfilter(A, gaussian_filter,'conv','replicate');
% Display original image and blurred images
figure;
imshow(A)
title('Original Image');
figure
imshow(uni_blur);
title('Uniform blur');
figure
imshow( gauss_blur);
title('Gaussian Blur');
% Estimate noise-to-signal ratio (NSR) for Wiener filter
estimated_nsr = 0.01/var(A(:)); % Estimated noise-to-signal ratio
% Deblur the uniformly blurred and Gaussian blurred images using Wiener
filter
deblurred_uniform = deconvwnr(uni_blur, uniform_filter,estimated_nsr);
deblurred_gaussian = deconvwnr(gauss_blur,gaussian_filter,estimated_nsr);
% Display deblurred images
figure;
imshow(deblurred_uniform);
title('Deblurred Uniform');
figure;
imshow(deblurred_gaussian);
title('Deblurred Gaussian');

You might also like