0% found this document useful (0 votes)
2 views

exp_5

The document outlines a program that uses Fourier Transform to process an image by applying low-pass and high-pass filters. It includes steps for reading an image, converting it to grayscale, performing the Fourier Transform, and applying filters in the frequency domain. Finally, it displays the original image, Fourier spectrum, and the results of the filtering processes.
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)
2 views

exp_5

The document outlines a program that uses Fourier Transform to process an image by applying low-pass and high-pass filters. It includes steps for reading an image, converting it to grayscale, performing the Fourier Transform, and applying filters in the frequency domain. Finally, it displays the original image, Fourier spectrum, and the results of the filtering processes.
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/ 2

Programme #5

Use Fourier Transform to switch to frequency domain, apply low-pass and high-pass filters, and
then convert back to spatial domain.

clc;
clear;
close all;
% Read the image
img = imread('image.jpg'); % Replace 'image.jpg' with your image file
if size(img, 3) == 3
img_gray = rgb2gray(img); % Convert to grayscale if RGB
else
img_gray = img;
end
% Fourier Transform
F = fft2(double(img_gray));
Fshift = fftshift(F); % Shift zero frequency component to the center
% Get image size
[M, N] = size(img_gray);
[u, v] = meshgrid(-N/2:N/2-1, -M/2:M/2-1);
D = sqrt(u.^2 + v.^2); % Distance matrix
% Low-pass filter (Ideal)
D0 = 30; % Cutoff frequency
LPF = double(D <= D0);
F_low = Fshift .* LPF;
img_low = real(ifft2(ifftshift(F_low))); % Inverse FFT
% High-pass filter (Ideal)
HPF = double(D > D0);
F_high = Fshift .* HPF;
img_high = real(ifft2(ifftshift(F_high))); % Inverse FFT
% Display results
figure;
subplot(2,3,1); imshow(img_gray); title('Original Image');
subplot(2,3,2); imshow(log(1 + abs(Fshift)), []); title('Fourier Spectrum');
subplot(2,3,3); imshow(LPF, []); title('Low-pass Filter');
subplot(2,3,4); imshow(img_low, []); title('Low-pass Filtered Image');
subplot(2,3,5); imshow(HPF, []); title('High-pass Filter');
subplot(2,3,6); imshow(img_high, []); title('High-pass Filtered Image');

You might also like