Assignment#4: NAME: Talha Asim Class: Bscs 6-B Roll No: 160661

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

NAME : Talha Asim

CLASS: BSCS 6-B


Roll No: 160661

ASSIGNMENT#4
1) Take the grey scale image of yourself and that of the face of an animal of your choice.
Apply Fourier transform on both images. Show the results in terms of fourier spectrum
and phase. Create two new images using the phase of one and the spectrum of the other.

i = imread('grayanimal.jpg');
j = imread('grayperson.jpg');
a = .299*i(:,:,1) + .587*i(:,:,2) + .114*i(:,:,3);
b = .299*j(:,:,1) + .587*j(:,:,2) + .114*j(:,:,3);
figure, subplot(3,3,1) , imshow(a)
% spectrum of image1
fft2im = fft2(double(a));
fft2im = log(1+(abs(fft2im)));
spectrum = fftshift(fft2im);
maximum = max(max(spectrum));
spectrum = 255*spectrum/maximum;
spectrum = uint8(spectrum);
subplot(3,3,2), imshow(spectrum) ,title(' spectrum image 1');
% angle of image1
f1=fftshift(fft2(a));
phase1=angle(f1);
subplot(3,3,3);imshow(phase1,[]),title('phase image 1 ');
subplot(3,3,4), imshow(b)
% spectrum of image2
fft2im = fft2(double(b));
fft2im = log(1+(abs(fft2im)));
spectrum = fftshift(fft2im);
maximum = max(max(spectrum));
spectrum = 255*spectrum/maximum;
spectrum = uint8(spectrum);
subplot(3,3,5), imshow(spectrum) ,title(' spectrum image 2');
% phase angle of image2
f1=fftshift(fft2(b));
phase1=angle(f1);
subplot(3,3,6 );imshow(phase1,[]),title('phase image 2');
2) Apply Laplacian filter in frequency domain.

Question 2

clear all; close all ;clc;


f = im2double(imread('grayanimal.jpg'));
%figure,imshow(f),title('Original Image');
PQ = paddedsize(size(f)); % Get the size of the Image
% Pad the image with Zeros
%———————————————

h=[0,1,0;1,-4,1;0,1,0]; % Laplacian Mask


H=ifftshift(freqz2(h,PQ(1),PQ(2))); % Frequency respones of h (Filter)

%——————————————–
F = fft2(f, size(H, 1), size(H, 2)); % Fourier version of Image
g = real(ifft2(H.*F)); %| Multiplying filter Co-efficient with Image
%| then takes the Inverse Fourier of Real Part
g = g(1:size(f,1), 1:size(f,2)); % Make the image in Original Size
%——————————————–
%figure, imshow(g),title('Laplacian Filtered');
%——————————————–
g1= f-g; %| High-boost filtering
%| Highpass = 1-Lowpass;
%| Enhanced Image = bluredImage – Laplacianfiltered Image;
%——————————————–
%figure,imshow(g1),title('Enhanced Image');
subplot(2,3,1);imshow(f);title('Original image');
subplot(2,3,2);imshow(g);title('Laplacian Filtered');
subplot(2,3,3);imshow(g1);title('Enhanced Image');

padded size
function PQ = paddedsize(AB, CD, PARAM)
if nargin == 1
PQ = 2*AB;
elseif nargin == 2 && ~ischar(CD)
PQ =AB + CD - 1;
PQ = 2 * ceil(PQ / 2);
elseif nargin == 2
m = max(AB);
p = 2^nextpow2(2*m);
PQ = [p, p];
elseif nargin == 3
m = max([AB CD]);
p = 2^nextpow2(2*m);
PQ = [p, p];
else
error('Wrong number of inputs.');
end

You might also like