Point Spread Function Calculation from known images
60 views (last 30 days)
Show older comments
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 = imread('crisp1.jpg');
blurred = imread('blurred1.jpg');
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);
imshow(imadjust(img,[]))
subplot(1,2,2);
imshow(img,[])
0 Comments
Answers (1)
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 = imread('crisp1.jpg');
blurred = imread('blurred1.jpg');
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,[])
1 Comment
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
sim1 = imread('sharp1.bmp');
sim3 = imread('sharp3.bmp');
sim4 = imread('sharp4.bmp');
sim5 = imread('sharp5.bmp');
sim6 = imresize(sim5, 0.25);
croppedImage = imresize(sim6, [720, 1280]);
bim1 = imread('blur1.bmp');
bim2 = imread('blur2.bmp');
bim3 = imread('blur3.bmp');
bim4 = imread('blur4.bmp');
% 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:
See Also
Categories
Find more on Splines in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!