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 Import
ed 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];
ImageDeconvolve[badfocus, kernel]
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.
ImageDeconvolve
. However, your image also has a lot of noise, which makes deconvolution very hard. $\endgroup$r = 6; k = DiskMatrix[r]/Total[DiskMatrix[r], Infinity];
and tryImageDeconvolve[image, k, Method -> "RichardsonLucy"]
orImageDeconvolve[image, k, Method -> {"TotalVariation", "NoiseModel" -> "Laplacian"}]
. The results aren't super fantastic, but they're something. $\endgroup$