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

Assignment#4: 'Grayanimal - JPG' 'Grayperson - JPG'

The document describes applying Fourier transforms and filters to images: 1) It takes a grayscale image of a person and animal, applies the Fourier transform to get the spectrum and phase, and creates new images using the phase of one and spectrum of the other. 2) It applies a Laplacian filter in the frequency domain to a grayscale animal image. It enhances the image by subtracting the Laplacian filtered image from the blurred original. 3) It defines a paddedsize function to get the padded size of images for Fourier transforms.

Uploaded by

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

Assignment#4: 'Grayanimal - JPG' 'Grayperson - JPG'

The document describes applying Fourier transforms and filters to images: 1) It takes a grayscale image of a person and animal, applies the Fourier transform to get the spectrum and phase, and creates new images using the phase of one and spectrum of the other. 2) It applies a Laplacian filter in the frequency domain to a grayscale animal image. It enhances the image by subtracting the Laplacian filtered image from the blurred original. 3) It defines a paddedsize function to get the padded size of images for Fourier transforms.

Uploaded by

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

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