9

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

Basheer Algohi
  • 19,917
  • 1
  • 31
  • 78
  • Sharpen, perhaps? – bbgodfrey Mar 13 '15 at 02:35
  • Sharpen did not help. Still not good looking image. – Basheer Algohi Mar 13 '15 at 02:43
  • ImageAdjust seems to change coloring and brightness. but again I am not getting better image. I will keep trying. – Basheer Algohi Mar 13 '15 at 02:54
  • 2
    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. –  Mar 13 '15 at 04:27
  • @Rahul I have tried your suggestion now but there is not much effect. I played with GaussianMatrix parameter but for value more than 3 parts of the image start to disappear. – Basheer Algohi Mar 13 '15 at 04:30
  • 6
    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 04:36
  • @Szabolcs That is not good news:(. But how can you tell if the problem is out of focus or something else? – Basheer Algohi Mar 13 '15 at 04:40
  • 2
    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. –  Mar 13 '15 at 04:42
  • @Rahul the first method gives better result compared to the second. – Basheer Algohi Mar 13 '15 at 04:48
  • @Algohi If the image is straight form the camera, I can't imagine what else it could be ... – Szabolcs Mar 13 '15 at 05:06
  • 3
    Perhaps this should be moved to [DSP.SE] to determine an optimal approach, then a new question could be posted regarding implementation? – Mr.Wizard Mar 13 '15 at 07:36
  • 2
    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 07:38
  • @Mr.Wizard, ok I will try to use deconvolution as much as I can to get the best results. – Basheer Algohi Mar 13 '15 at 20:50

2 Answers2

15

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.

2012rcampion
  • 7,851
  • 25
  • 44
  • 1
    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 07:30
1

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}]
David G. Stork
  • 41,180
  • 3
  • 34
  • 96