Friday, 16 March 2012

AA filters, RL-deconvolution sharpening and optimal raw conversion

When I measured the MTF of the D40 AA filter, I speculated that the "optimal" radius (standard deviation, really) for RL-deconvolution sharpening for the D40 would be 0.57. (See Measuring D40 AA filter MTF)
We can perform an experiment to see what "optimal" sharpening looks like, and what happens when we sharpen more than that. First, generate a synthetic image with a known MTF50 value, say, about 0.38 cycles per pixel. Here it is:
This image has an exact Gaussian point spread function, i.e., it does not include the effects of diffraction. I added realistic sensor noise (based on actual measured D7000 sensor parameters), so this image could just as well have come straight from a D7000 (barring Bayer filters, and assuming the AA filter is slightly less blurry). This image is then sharpened with the default settings of the RL-deconvolution sharpening found in RawTherapee. In short, the RL-deconvolution algorithm will undo the effects of a known low pass filter very well. Here is the sharpened version of the above image:
Notice how there is a white halo around the black rectangle (click to view full image). The default radius for the RL-deconvolution sharpening algorithm in RawTherapee is 0.75. This is too large a radius, and over-sharpens the image a bit, causing the appearance of haloes. The haloes I can live with, but notice how much more pronounced the noise in the white parts of the image has become. Looks familiar, doesn't it ... ? If I process the same image (two up, MTF50 of 0.38) with the "optimal" parameters for the D40, i.e., radius set to 0.57, I get the following image:
This image looks a little bit sharper than the input image, but the noise certainly does not appear as pronounced as in the over-sharpened image (radius 0.75). So here is the summary of the MTF50 values:
Original image                        -> MTF50 = 0.38
Over-sharpened image           -> MTF50 = 0.6
Optimally sharpened image   -> MTF50 = 0.45

Typically, we would consider an MTF50 value of 0.5 to be the upper limit before severe aliasing sets in. Take a close look at the edges of the over-sharpened image: observe the "waves" along the edges of the black rectangle. These are textbook examples of aliasing: frequencies that are too high to be represented in the target resolution will masquerade as lower frequency components. An MTF50 value of 0.6 is definitely too high, and sharpening artefacts are evident. (Note: frequencies above Nyquist are measured here, but this is OK because the slanted edge method produces a over-sampled edge spread function at a much higher sampling rate than the pixel pitch)

The optimally sharpened image has no "waves" on its edges, i.e., it does not suffer from aliasing. Because the sharpening is less severe, and has less impact on high frequencies, the noise is also amplified less than in the over-sharpened image.

So that leaves an important question: Why is the default in RawTherapee to use a radius of 0.75? Adobe LightRoom appears to use a default radius of 1.0 (I have heard that LightRoom uses RL-deconvolution to perform sharpening, but do not quote me as a source on this). Surely this will lead to aliasing, as could be seen in the over-sharpened image above?

Well, the "original" synthetic image above already had a very good MTF50 value, higher than what I believe is possible with a Nikon (non D800E) camera. But more importantly, this synthetic image only modelled two aspects: the low-pass filter effect of the AA filter, and sensor noise. If one throws in a diffraction MTF and a defocus MTF (maybe in a next post?) then the overall sharpness, and the MTF50, will decrease quite a bit. In other words, real images can probably tolerate sharpening by a radius of 0.75, and maybe even 1.0, because they are not perfectly focused, and typically do not contain perfect razor blade edges.

But the noise component remains because this happens at the sensor level, after all the other resolution-robbing distortions (lens MTF, sensor AA MTF, defocus). So even if you can justify sharpening with a radius of 1.0 because of these other factors, you still end up with significant noise magnification.

So here is the bottom line: In theory, you can perform sharpening with RL-deconvolution to mostly reverse the blurring effects of the lens and sensor AA filter --- but because the noise is not affected by any of those distortions, you end up sharpening the noise too, i.e., rather than getting a more faithful representation of the noise (not that you would want that in the first place), you are magnifying the effects of noise from the first time you apply any kind of sharpening.

One possible solution is to improve the raw converter directly, which may be what converters such as ACR / LR do in any case. My proposed strategy would be as follows:
  1. Subtract a dark frame from the raw image
  2. Perform flat-field correction to remove the PRNU effects (Pixel Response Non-Uniformity)
  3. Perform noise suppression on the raw Bayer channels (before Bayer demosaicing) to yield image I1
  4. Perform sharpening using RL-deconvolution on I1 to yield I2
  5. Perform Bayer demosaicing using both I1 and I2
  6. Profit!
There are some potential problems. For example, if you perform sharpening before Bayer demosaicing, you are effectively removing the AA filter, hence you will increase colour Moire artefacts. This is why I propose to use both the sharpened and the unsharpened image during Bayer demosaicing, hopefully getting the best of both worlds in the process.

No comments:

Post a Comment