In MATLAB, write codes of following steps please 2. Load moon.tif and try to sha
ID: 3704400 • Letter: I
Question
In MATLAB, write codes of following steps please 2. Load moon.tif and try to sharpen the image using a. 'Unsharp' filter using fspecial function in spatial domain. b. Calculate and display Fourier Transform of the image. c. Gaussian high-pass filter by giving different radiuses in frequency domain and compare the results of different radiuses that you applied d. Ideal high-pass filter in frequency domain, e. Display filtered images both in frequency and in time domain. f. Compare the results of a,c and d. Write your comments.Explanation / Answer
a.
I = imread('moon.tif');
H = fspecial('unsharp');
sharpened = imfilter(I,H);imshow(sharpened);title('Sharpened Image');
b.
I = imread('moon.tif');
fft=fft2(double(I));
imshow(fft);
c.
clear;
image = imread('moon.tiff');
image = double(image);
[nx ny] = size(image);
u = image;
image = uint8(u);
fftu = fft2(u,2*nx-1,2*ny-1);
fftu = fftshift(fftu);
subplot(1,2,1)
mesh(log(1+(abs(fftu))));
% Use Gaussian high pass filter.
filter = ones(2*nx-1,2*ny-1);
d0 = 100;
n = 4;
for i = 1:2*nx-1
for j =1:2*ny-1
dist = ((i-(nx+1))^2 + (j-(ny+1))^2)^.5;
% Use Gaussian high pass filter.
filter(i,j) = exp(-dist^2/(2*d0^2));
filter(i,j) = 1.0 - filter(i,j);
end
end
% Updating image with high frequencies.
fil_image = fftu + filter.*fftu;
subplot(1,2,2)
mesh(log(1+abs(fil_image-fftu)));
fil_image = ifftshift(fil_image);
fil_image = ifft2(fil_image,2*nx-1,2*ny-1);
fil_image = real(fil_image(1:nx,1:ny));
fil_image = uint8(fil_image);
imwrite(fil_image, 'image_fil.jpg');
d.
%Pass the fourier transform to this function
function result = highPass(image,thresh,n)
% inputs
% image is the fourier transform of the image
% thresh is the cutoff circle radius
%outputs
% result is the filtered image
[r,c]=size(image);
d0=thresh;
d=zeros(r,c);
h=zeros(r,c);
A=1.75; % boost factor or coefficient
for i=1:r
for j=1:c
d(i,j)= sqrt( (i-(r/2))^2 + (j-(c/2))^2);
end
end
for i=1:r
for j=1:c
h(i,j)= 1 / (1+ (d0/d(i,j))^(2*n) ) ;
h(i,j)=(A-1)+h(i,j);
end
end
for i=1:r
for j=1:c
result(i,j)=(h(i,j))*image(i,j);
end
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.