If you are in the situation in which you have the original image ( or an image which is very close to the original - for example in successive frames of a video) than you can use this function to get a good estimate of the blur kernel much faster than working with the blurry image only.
there is a simple demo that should work out of the box .
let me know if there is any problems with this :)
% estimate quickly and effectively the kernel that was used to blur img_orig
% into img_blurred.
% This function treats the kernel as the solution to an over-constrained
% problem. In other words :
% 1) blurred image = original image ** blur kernel ; where ** = convolution
% 2) hence for each pixel:
% blurred image(i,j) = original image( neighborhood(i,j) .* blur kernel)
% 3) a set of equations (2) can be set for different i,j's to solve for
% the blur kernel.
% 4) there are many many more equations than needed to solve for the blur
% A variation of the ransac algorithm is implemented in order to
% find a good estimate of the blur kernel.
Dan (2020). calculate blur kernel from original and blurry images (https://www.mathworks.com/matlabcentral/fileexchange/54944-calculate-blur-kernel-from-original-and-blurry-images), MATLAB Central File Exchange. Retrieved .
i apologise but i really don't remember even posting this code, let alone how it works.
in any case . its the deep learning age. you can get much better results with cnns for sure.
Dan, the method is not practical. What if we have a blurred and unblurred image pair without knowing the size of the psf kernel? I think the best way is to convert them to frequency domain and calculate PSF by simple division then convert it back to spatial domain.
nice function !
I figured out, that your calculated kernels will not always sum to 1. So the Image will be manipulated in brightness.
This can easily be corrected by dividing all entrys in k by their sum. k = 1/sum(k(:)).*k;
Thanks for your work!
Hi Dan ,
I have a set of images which are blurred at different extents. Will code work if we want to deblur them ? this is because in the function the image is blurred using known filter parameters . In my case we just have the pair of original image and blurred image?
you are using trained data for blur kernel of the images. how can i determine the blur kernel for my own blurred images
Thanks for your code!
I was wondering about the following.
If the reason for blur is a certain distance from the focus, how one would be able to calculate this distance once the original image has been restored using your code?
small big fix