# Challenge: deblurring images [duplicate]

My friend came back from holidays, where he took lots of pictures. Unfortunately, the camera was set on manual focus and most pictures are blurry. It got me thinking that mathematica showed how to deblur the images ImageDeconvolve[] documentation and remembered how the original image can be reconstructed. In principle we only need to find the kernel for the lens.

So the challenge: can we find kernel guessing method that produces sharpest images? I am providing 3 images to play with.

1) Perfect image with GaussianMatrix[] blur (I'm not telling you the parameters) (high resolution link)

2) Perfect image with unknown kernel blur (high resolution link)

3) An actual picture from my friend's holidays (high resolution link, raw)

Also there was an old discussion on this thread that did not get anywhere.

• You will be better off, and get it done more easily, using software that is designed for this purpose (e.g. smartdeblur) - some are (or have earlier versions) free/open source. Don't expect miracles whatever the means - were it that simple, they'd never have needed to fit the Hubble with contacts.... – ciao Sep 21 '15 at 21:51
• Also previously: How to enhance a fuzzy image – user484 Sep 21 '15 at 21:54
• You can "improve" the blurred Lena image — call it lenablurred — with something as simple as Manipulate[Sharpen[lenablurred, r], {r, Range[1, 20], ControlType -> Slider}]. – Stephen Luttrell Sep 21 '15 at 22:56
• This problem is called "blind deconvolution", and there is an entire literature about it, which I recommend you read. It is too much to expect an answer in this forum to conclusively solve a problem to which extensive research effort has been dedicated over many years. – Oleksandr R. Sep 21 '15 at 23:27
• Note the Wolfram Blog post on astronomy deconvolution, which does a little bit of kernel estimation. – dr.blochwave Sep 22 '15 at 7:56

As mentioned in a comment by ciao, blind deconvolution is no easy task.

However, here are some pointers for estimating the kernel parameters. These can equally be applied to denoising an image rather than deblurring.

I am assuming that the form of the kernel is known here, rather than blind deconvolution (Wikipedia) methods such as Maximum A Posteriori (MAP). For that scenario, here's a neat paper on the use of blind deconvolution in astronomy for further interest.

Anyway, in order to estimate the best deconvolution parameters, you need to have a metric that defines how close the result is to the original. A common choice is to minimize the mean-squared error (MSE),

$$\underset{\theta}{\min} \enspace \frac{1}{N}\left \| X - f_{\theta }\left ( X \right ) \right \|_{2}^{2}$$

where $X$ is your original image and $f_{\theta }\left ( X \right )$ is your deconvolution function with parameter(s) $\theta$.

The MSE is useful because you can replace it with an estimator such as Stein's unbiased risk estimate (SURE), which means you no longer need to know the original image in order to estimate the convolution parameters.

I'll leave the implementation of SURE as an exercise for now as I'm rather busy, but a very good starting point is this paper on deconvolution in 3D fluorescence microscopy, which uses Tikhonov regularization.

Now as an example using ImageDeconvolve[] in Mathematica, apply a Gaussian blur and see how the MSE between the original and the deconvolved image changes with the deconvolution parameter, in this case simply the width of the Gaussian kernel.

image = ImageAdjust@ImageResize[ExampleData[{"TestImage", "Man"}], 256];
blurredImage = ImageConvolve[image, GaussianMatrix[5]];

imageBlurMSE[im1_, im2_, ker_] := ImageDistance[

Incidentally, here is the MSE result when the image is convolved/deconvolved with a kernel of DiskMatrix[5] rather than a Gaussian kernel as above. Again the parameter estimation is decent, giving an estimate of 4.9 compared to the original value of 5, but the end image doesn't look any good.