0% found this document useful (0 votes)
22 views6 pages

NM Week3 Final

The document outlines an experiment focused on image filtering and restoration techniques, including histogram equalization, smoothing and sharpening filters, and frequency domain filtering using Fourier Transform. It details procedures for applying homomorphic filtering and simulating motion blur, followed by restoration techniques such as inverse and Wiener filtering. Results demonstrate enhanced image clarity and detail through various filtering methods.

Uploaded by

22l121
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views6 pages

NM Week3 Final

The document outlines an experiment focused on image filtering and restoration techniques, including histogram equalization, smoothing and sharpening filters, and frequency domain filtering using Fourier Transform. It details procedures for applying homomorphic filtering and simulating motion blur, followed by restoration techniques such as inverse and Wiener filtering. Results demonstrate enhanced image clarity and detail through various filtering methods.

Uploaded by

22l121
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Exp 3 Image Filtering and Restoration

OBJECTIVE:

1. To understand gray level transformations and enhance image contrast using


histogram equalization.
2. To apply smoothing and sharpening filters in the spatial domain for detail
enhancement and noise reduction.
3. To design and implement low-pass filters using the Fourier Transform in the
frequency domain.
4. To perform homomorphic filtering to simultaneously enhance contrast and
compress dynamic range.
5. To simulate motion blur and apply restoration techniques such as inverse
filtering and Wiener filtering.

PROCEDURE:

• Convert input images to grayscale using rgb2gray.


• Enhance contrast with histogram equalization using histeq.
• Apply smoothing filters like averaging using fspecial and imfilter. •
Sharpen images using imsharpen or Laplacian filters.
• Use FFT (fft2) and IFFT (ifft2) for frequency domain filtering.
• Create custom frequency masks (e.g., Ideal Low Pass, High Pass) using
distance functions.
• Implement homomorphic filtering by applying logarithmic transforms and
high-pass filters in the frequency domain.
• Simulate motion blur using fspecial and restore using deconvwnr
(Wiener/inverse filtering).
• Visualize results using imshow and subplot for comparative display.
1. Gray Level Transformations & Histogram Processing
CODE:
% Load image and convert to grayscale
img = imread('img1.png');
gray_img = rgb2gray(img);

% Histogram Equalization
eq_img = histeq(gray_img);

% Display original and equalized images


figure;
subplot(1,2,1); imshow(gray_img); title('Original Grayscale');
subplot(1,2,2); imshow(eq_img); title('Histogram Equalized');

2. Smoothing & Sharpening – Spatial Domain


CODE:
% Load image and convert to grayscale
img = imread('img1.png');
gray_img = rgb2gray(img);

% Smoothing using averaging filter


h = fspecial('average', [5 5]);
smoothed_img = imfilter(gray_img, h);

% Sharpening using Laplacian filter


sharpened_img = imsharpen(gray_img);

% Display results
figure;
subplot(1,3,1); imshow(gray_img); title('Original');
subplot(1,3,2); imshow(smoothed_img); title('Smoothed');
subplot(1,3,3); imshow(sharpened_img); title('Sharpened');

3. Frequency Domain – Fourier Transform Filters


CODE:
% Load grayscale image
img = imread('img1.png');
gray_img = rgb2gray(img);

% Apply FFT
fft_img = fft2(double(gray_img));
1.

2.

3.
fft_shifted = fftshift(fft_img);

% Create Ideal Low Pass Filter


[M, N] = size(gray_img);
[u, v] = meshgrid(1:N, 1:M);
D0 = 50;
D = sqrt((u - N/2).^2 + (v - M/2).^2);
H = double(D <= D0);

% Apply filter and inverse FFT


G = H .* fft_shifted;
ifft_img = real(ifft2(ifftshift(G)));

% Display result
figure;
imshow(uint8(ifft_img)); title('Low Pass Filtered Image');

4. Homomorphic Filtering
CODE:
% Load image and convert to grayscale
img = imread('img1.png');
gray_img = im2double(rgb2gray(img));

% Apply logarithmic transform


log_img = log1p(gray_img);

% FFT
fft_img = fft2(log_img);
fft_img = fftshift(fft_img);

% Create a high-pass filter


[M, N] = size(gray_img);
[u, v] = meshgrid(1:N, 1:M);
D = sqrt((u - N/2).^2 + (v - M/2).^2);
H = 1 - exp(-(D.^2) / (2 * (30^2)));

% Apply filter and inverse FFT


filtered = H .* fft_img;
filtered = real(ifft2(ifftshift(filtered)));
filtered = exp(filtered) - 1;

% Display result
figure;
imshow(filtered, []); title('Homomorphic Filtered Image');
4.

5.
5. Image Restoration with Filters (Wiener, Inverse)
CODE:
% Load image and simulate motion blur
img = imread('img1.png');
gray_img = rgb2gray(img);
PSF = fspecial('motion', 20, 45);
blurred = imfilter(gray_img, PSF, 'conv', 'circular');

% Inverse Filtering
inverse_restored = deconvwnr(blurred, PSF);

% Wiener Filtering
wiener_restored = deconvwnr(blurred, PSF);

% Display results
figure;
subplot(1,3,1); imshow(blurred); title('Blurred');
subplot(1,3,2); imshow(inverse_restored); title('Inverse Filter');
subplot(1,3,3); imshow(wiener_restored); title('Wiener Filter');

RESULT:
Spatial and frequency domain filters enhanced and restored images. Motion blur
simulation and filtering showed practical restoration techniques. Filtering improved
image clarity and detail.

You might also like