# How to enhance a fuzzy image

First I am sorry if this question is duplicate. I am not familiar with image processing so I don't know how to search for answer.

I have an images which were taken with good camera but the camera sometimes produce bad images I don't know why.

I want to enhance some of these images but I don't know how.

Here is one of those not good image:

Any help is appreciated.

Thank you

• Blurring is a form of convolution. To undo it, what you want is deconvolution, i.e. ImageDeconvolve. However, your image also has a lot of noise, which makes deconvolution very hard. – user484 Mar 13 '15 at 4:27
• In practice, if the image is out of focus, there's nothing you can do. The information is permanently lost. – Szabolcs Mar 13 '15 at 4:36
• A disk is a better model for defocus blur than a Gaussian function. Set r = 6; k = DiskMatrix[r]/Total[DiskMatrix[r], Infinity]; and try ImageDeconvolve[image, k, Method -> "RichardsonLucy"] or ImageDeconvolve[image, k, Method -> {"TotalVariation", "NoiseModel" -> "Laplacian"}]. The results aren't super fantastic, but they're something. – user484 Mar 13 '15 at 4:42
• Perhaps this should be moved to Signal Processing to determine an optimal approach, then a new question could be posted regarding implementation? – Mr.Wizard Mar 13 '15 at 7:36
• By the way deconvolution can be very effective as seen in the documentation examples, but the starting image must be very clean. As noted by Rahul the noise here is bad; probably fatal as it were in that too much information is lost beyond the noise threshold. – Mr.Wizard Mar 13 '15 at 7:38

I'll use my own pictures as test cases (click on them to get the full images). These pictures were taken with a D3300 and MICRO-NIKKOR 40mm 2.8G; settings were f/3.2, 1/6 and 1/800 shutter, ISO 100 and 12800, auto WB.

## In-focus (desired image)

Autofocus locked on to the surface texture of the laptop here. At this wide aperture the depth-of-field is tiny:you can tell the keys are a little out of focus!

## Out-of-focus (clean)

For this image I manually set the focus to infinity.

## Out-of-focus (noisy)

I set the camera to (almost) maximum ISO for this shot, decreasing the shutter speed accordingly.

The thumbnail doesn't do justice to how noisy this one is; here's a 100% magnification:

I've gone ahead and Imported these images as infocus, badfocus, and noisy, respectively, preprocessing them with:

img = ImageResize[ImageRotate[img, Pi], Scaled[1/10]]


Downscaling will make things go a lot faster as well as save some memory (Mathematica's image-processing functions are extremely memory-intensive).

We can see from the bokeh (blur) from the power button light that the PSF of the unfocused lens is approximately a uniform disk of diameter around 38 pixels.

Thus we can make a first attempt to deconvolve the image:

kernel = DiskMatrix[19];
kernel /= Total[kernel, 2];


This is pretty bad, but there's hope: the text of the Home, PgUp, and PgDn keys are visible.

The "Hybrid" iterative method gives better results:

ImageDeconvolve[badfocus, 2 Normalize[DiskMatrix[19], Total[#, 2] &],
Method -> {"Hybrid", "Preconditioned" -> True}, MaxIterations -> 50]


"Tikhonov" also performs surprisingly well:

ImageDeconvolve[badfocus,
2 Normalize[DiskMatrix[19.1], Total[#, 2] &], Method -> "Tikhonov"]


Neither are what I'd find acceptable, much less good; even though this is pretty much the best possible case:

• A totally flat object parallel to the image plane (so that the degree of blur is the same over the whole image)
• Flat bokeh
• Low-noise
• Bright point-like light sources (allowing good estimation of the PSF)
• High-contrast objects, i.e. the backlit letters (deconvolution can't recover subtle details)

If we add some noise, "Hybrid" fails to resolve any details:

Although "Tikhonov" is a little sharper, it has higher noise:

Your image represents a worst-case scenario for sharpening:

• A 3d object with spatially-varying blurring
• Unknown and inestimable PSF
• Very high noise

Unfortunately every deconvolution method I tried on your image failed completely, severely worsening the image quality in all cases.

In summary, deconvolution can recover information in certain cases, but cannot improve image quality.

Even the most expensive camera will produce crap if not used correctly, and even the cheapest disposable camera can produce sharp images: focus before you hit the shutter.

• A fine answer, but your summary seems prone to misinterpretation. I would actually state it conversely: deconvolution cannot add information to an image, but it can improve the intelligibility of that information. Noise, compression, etc., all cause irrecoverable information loss. – Mr.Wizard Jul 15 '16 at 7:30

Sharpen[myImage, 15]

Or try this and play around:

Manipulate[
Blur[
Sharpen[