# Point Spread Function Calculation from known images

163 views (last 30 days)
pb on 28 Aug 2020
Commented: Jignasu Pathak on 19 Mar 2021
Hello, I am brand new - only a few days old - to the idea of PSFs and motion blur in images. It also doesn't help that I don't really remember anything about Fourier transforms - so I don't have the intuition down yet - but I am working on it.
Anyways, here is small piece of code where I am trying to extract the PSF from a known image of an object, and later that object in motion in roughly the same spot (once I get any result, then I suppose I will look into adding noise, etc).
The error I am getting is: "Expected input number 2, PSF, to be finite." for the line that does the deconvolution.
The code is below, and the images are attached. So now, essentially, I need help understanding what is going on under the hood that is resulting in a infinite PSF. Further any other suggestions are welcome as well for how to better the code once I get a result in the first place.
crisp = im2double(crisp);
blurred = im2double(blurred);
crispfft = fft(crisp);
blurredfft = fft(blurred);
PSFfft = blurredfft ./ crispfft;
PSF = ifft(PSFfft);
img = deconvwnr(blurred,PSF);
subplot(1,2,1);
subplot(1,2,2);
imshow(img,[])

Tugce Toprak on 17 Feb 2021
Hi,
I don't know if you solved this problem, but I changed your code that I hope will be useful when dealing with a similar problem.
crisp = rgb2gray(im2double(crisp));
blurred = rgb2gray(im2double(blurred));
crispfft = fft2(crisp);
blurredfft = fft2(blurred);
PSFfft = blurredfft ./ crispfft;
PSF = ifftshift(ifft2(PSFfft));
figure; imshow(PSF,[]);
img = deconvwnr(blurred,PSF);
figure; imshow(img,[])
Jignasu Pathak on 19 Mar 2021
I tried but independent to blurred image output of the code is crisp image.
function f = psfmatlab(sharp, blur, tttitle);
crisp = sharp;
blurred = blur;
crisp = im2double(crisp);
blurred = im2double(blurred);
crispfft = fft2(crisp);
blurredfft = fft2(blurred);
PSFfft = blurredfft ./ crispfft;
PSF = ifftshift(ifft2(PSFfft));
img = deconvwnr(blurred,PSF);
figure;
subplot(1,3,3);imshow(img,[]);title(tttitle);
subplot(1,3,1);imshow(crisp,[]);
subplot(1,3,2);imshow(blur,[]);
Code used for it
clear all
clc
sim6 = imresize(sim5, 0.25);
croppedImage = imresize(sim6, [720, 1280]);
% psfmatlab(sim1,bim1,"sharp1 ==> blur1");
% psfmatlab(sim1,bim2,"sharp1 ==> blur2");
% psfmatlab(sim1,bim3,"sharp1 ==> blur3");
% psfmatlab(sim1,bim3,"sharp1 ==> blur3");
% psfmatlab(sim1,bim4,"sharp1 ==> blur4");
psfmatlab(sim1,sim4,"sharp1 ==> sharp4");
psfmatlab(sim1,croppedImage,"sharp1 ==> sharp5");
Output: