9
$\begingroup$

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:

enter image description here

Any help is appreciated.

Thank you

$\endgroup$
  • 2
    $\begingroup$ 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. $\endgroup$ – Rahul Mar 13 '15 at 4:27
  • 6
    $\begingroup$ In practice, if the image is out of focus, there's nothing you can do. The information is permanently lost. $\endgroup$ – Szabolcs Mar 13 '15 at 4:36
  • 2
    $\begingroup$ 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. $\endgroup$ – Rahul Mar 13 '15 at 4:42
  • 3
    $\begingroup$ Perhaps this should be moved to Signal Processing to determine an optimal approach, then a new question could be posted regarding implementation? $\endgroup$ – Mr.Wizard Mar 13 '15 at 7:36
  • 2
    $\begingroup$ 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. $\endgroup$ – Mr.Wizard Mar 13 '15 at 7:38
15
$\begingroup$

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!

enter image description here

Out-of-focus (clean)

For this image I manually set the focus to infinity.

enter image description here

Out-of-focus (noisy)

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

enter image description here

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

enter image description here


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];
ImageDeconvolve[badfocus, kernel]

enter image description here

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]

enter image description here

"Tikhonov" also performs surprisingly well:

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

enter image description here

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:

enter image description here

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

enter image description here

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.

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Mr.Wizard Jul 15 '16 at 7:30
1
$\begingroup$

Adjust the radius of sharpening:

Sharpen[myImage, 15]

enter image description here

Or try this and play around:

Manipulate[
 Blur[
  Sharpen[
      ImageAdjust[myImage, c], 
        n], 
       m], 
   {c, .1, 2}, {n, 1, 20, 1}, {m, 2, 20, 1}]
$\endgroup$
  • $\begingroup$ I am trying to get the best parameters but still no much luck. $\endgroup$ – Algohi Mar 13 '15 at 4:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.