Instructions
Requirements and Specifications
Source Code
DEBLUR
function im2 = deblur(im, h)
% First, calculate the inverse values of h
h = 1./h; % We compute the inverse of the values of H since we want to deblur, not blur
[Nf,Mf] = size(h); % size of kernel
n = floor(Nf/2); % half-length of the number of rows of the kernel's matrix
m = floor(Mf/2); % half-length of the number of columns of the kernel's matrix
% Convert the rest of values to -1
hnew = -1*ones(size(h));
hnew(ceil(end/2), ceil(end/2)) = h(ceil(end/2), ceil(end/2)); % keep the original value at the mid-val of the kernel
h = hnew; % Update h
im2 = im; % Store the image in the variable im2
[N,M] = size(im); % Size of the image
for ii = 1+n:N-n % iterate through the rows of the Matrix containing the image
for jj = 1+m:M-m % iterate through the columns of the Matrix containing the image
subim = double(im(ii-n:ii+n, jj-m:jj+m)); % Extract the portion of the image (pixels) to apply the kernel
filtered = subim.*h; % apply kernel
im2(ii,jj) = sum(filtered(:)); % update pixel value
end
end
end
MAIN
clc
clear all
close all
I = imread('corn.tif');
h = ones(1,11)/11; % kernel
% Blur
blurred = uint8(round(filter2(h, I, 'valid')));
% Deblur
im3 = deblur(double(blurred), h);
figure
subplot(1,3,1)
imshow(I, []);
title('Original')
subplot(1,3,2)
imshow(blurred, []);
title('Blurred')
subplot(1,3,3)
imshow(im3, []);
title('Restored')