motion blur without fspecial (real vs theory)

9 views (last 30 days)
dao
dao on 3 Oct 2016
Commented: Image Analyst on 3 Oct 2016
I am writing a simple program to simulate motion blur by using convolution matrix and try to deblur it. Here is my code. the requirement is to blur a picture 3 pixel with horizontal direction.
if true
% code
function Blur (im)
%Read in the image and convert to gray
orig = imread ('dot3.jpg');
grayscale = rgb2gray(orig);
M2 = grayscale;
% Display the original and gray image
figure (1);
imshow (grayscale);
%figure (2);
%imshow (orig);
% Define the Blur kernels
% Blur picture 3 pixel
k_b = [0 0 0
1 1 1
0 0 0];
%Convolve the gray image with Blur Kernels, store result in M1
M1 = conv2(double(grayscale),double(k_b2));
%Display the blur image
figure (2);
imshow ((M1.^2).^0.5, []);
[x y] = size(M2);
% Using FFT to deblur picture
f_blurred = fft2(M2);
f_kernel = fft2(k_b2,x,y);
f_unblurred = f_blurred ./ (f_kernel + eps);
ret = ifft2(f_unblurred);
figure (3);
imshow ((ret.^2).^0.5,[]);
end
end
Is this code true following requirement above ? I made an real experiment by shooting a picture with 3 pixel blur by my camera. But when I input the blur picture to my code, the program cannot deblur it as the picture created by conv2. Please tell me where I am wrong ?
English is not my mother tongue; please excuse any errors on my part Thanks.
  1 Comment
Image Analyst
Image Analyst on 3 Oct 2016
How do you know the motion blur from your camera was exactly 3 pixels horizontally?

Sign in to comment.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!