File Exchange

image thumbnail

calculate blur kernel from original and blurry images

version 1.0 (1010 KB) by Dan
deconvolution, deblur, fast, ransac, blur kernel


Updated 16 Jan 2016

View License

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.
% method:
% 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
% kernel
% A variation of the ransac algorithm is implemented in order to
% find a good estimate of the blur kernel.
kind regards,

Cite As

Dan (2020). calculate blur kernel from original and blurry images (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (6)


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.

Jihang Wang

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.

Hi Dan,
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!

ahmad hussain

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

Karl M

Hi Dan

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?
Any idea?




small big fix


MATLAB Release Compatibility
Created with R2015a
Compatible with any release
Platform Compatibility
Windows macOS Linux