twitter.com/callmeyvan AYBU EEE4 EE 409 – MINI PROJECT 4
1) (Finding a suitable image file) >> Yvan = imread('C:\Users\pc\Program Files\OneDrive\Documents\0 YBÜ\4th year\matlab\MİNİPROJECTS\miniproject3\Yvan.jpg'); >> whos Yvan Name
Size
Bytes Class Attributes
Yvan
475x552x3
786600 uint8
>> Yvangray = rgb2gray(Yvan); >> imshow (Yvangray)
2) (Distorting image by blurring in spatial domain) grayImage = imread('Yvangray.jpg'); %subplot(2,1,1); %imshow(grayImage); %title('Original Image', 'FontSize', 15); blurredImage = imfilter(grayImage, ones(13)/169, 'symmetric'); %subplot(2,1,2); imshow(blurredImage); title('Blurred Image', 'FontSize', 15);
3) (Distorting image by blurring in frequency domain) clear all; close all; clc; I = double(imread(Yvan))/255; % Divide only if image value in [0-255] range figure,imshow(I);title('Cameraman original') I=rgb2gray(I); sigma=3; [M,N,s]=size(I); f1=-fix(M/2):ceil(M/2)-1;
f2=-fix(N/2):ceil(N/2)-1; [fx,fy]=meshgrid(f1,f2); X=exp(-2*pi*pi*sigma*sigma*((fx/M).^2+(fy/N).^2)); If=fft2(I); If=fftshift(If); If=If.*X; If=ifftshift(If); I=real(ifft2(If)); figure,imshow(I); title('Blurred Image', 'FontSize', 15);
4) (Reconstructing blurred image by inverse filtering) I = im2double(imread('Yvangray.jpg')); imshow(I); title('Original Image (courtesy of MIT)'); % Simulate a motion blur. LEN = 21; THETA = 11;
PSF = fspecial('motion', LEN, THETA); blurred = imfilter(I, PSF, 'conv', 'circular'); % Simulate additive noise. noise_mean = 0; noise_var = 0.0001; blurred_noisy = imnoise(blurred, 'gaussian', ... noise_mean, noise_var); figure, imshow(blurred_noisy) title('Simulate Blur and Noise') % Try restoration assuming no noise. estimated_nsr = 0; wnr2 = deconvwnr(blurred_noisy, PSF, estimated_nsr); figure, imshow(wnr2) title('Restoration of Blurred, Noisy Image Using NSR = 0')
The deblurred image is clearer than the blurred image.
The image borders are smoother. 5) (Adding noise to the blurred image) I = im2double(imread('Yvangray.jpg'));
imshow(I); title('Original Image (courtesy of MIT)'); % Simulate a motion blur. LEN = 21; THETA = 11; PSF = fspecial('motion', LEN, THETA); blurred = imfilter(I, PSF, 'conv', 'circular'); % Simulate additive noise. noise_mean = 0; noise_var = 0.0025; blurred_noisy = imnoise(blurred, 'gaussian', ... noise_mean, noise_var); figure, imshow(blurred_noisy) title('Simulate Blur and Noise')
6) (Reconstructing noisy blurred image by inverse filtering) I = im2double(imread('Yvangray.jpg')); imshow(I);
title('Original Image (courtesy of MIT)'); % Simulate a motion blur. LEN = 21; THETA = 11; PSF = fspecial('motion', LEN, THETA); blurred = imfilter(I, PSF, 'conv', 'circular'); % Simulate additive noise. noise_mean = 0; noise_var = 0.0025; blurred_noisy = imnoise(blurred, 'gaussian', ... noise_mean, noise_var); figure, imshow(blurred_noisy) title('Simulate Blur and Noise') % Try restoration using a better estimate of the noise-to-signalpower
% ratio. estimated_nsr = noise_var / var(I(:)); wnr3 = deconvwnr(blurred_noisy, PSF, estimated_nsr); wnr3 = edgetaper(wnr3,PSF); figure, imshow(wnr3) title('Restoration of Blurred');
The noisy deblurred image has more noise at borders than the deblurring result in question 4.
Comment on the result and its reason.
7(Image compression using fft)
6) %% FFT of a real image and image compression: 7) close all; 8) imorg=imread('Yvangray.jpg'); % Reads image 9) title('Original image'); 10) 11) %im=im2double(imorg); % Converts image to double 12) 13) imfft = fft2(im,256,256); % Taking the fft of the image 14) 15) imfft = fftshift( imfft ); % Take the fftshift to move lower frequency coefficients to the center
16) 17)
mask = zeros( size( imfft ) ); % Prepare an empty mask with all
18)
mask(61:184, 61:184) = 1; % Fill the center of the mask with
zeros ones
19) 20) 21)
% Compression by removing some fft coefficients: imfft = imfft .* mask; % Remove the fft coefficients corresponding to zeros in mask 22) figure; imshow( imfft ); % Display image fft where some of the coefficients are removed 23) title('Image fft where some of the coefficients are removed');
24) 25) 26) 27) 28) 29) 30)
imfft = ifftshift( imfft ); % Take the inverse fftshift imifft = ifft2( imfft ); % Take inverse fft of compressed image figure; imshow( imifft ); % Display compressed image title('Compressed image');
The original image is better than the compressed image. IF WÄ°LL BE 100