From noise to grain

While watching the DCRaw (web, wiki) presentation from the last Linux Graphic Meeting in Poland, Dave Coffin mentioned that DCRaw offers denoising before RAW demosaicing, which is the best way to deal with noise – ie as early in the process as possible. The “Treshold” slider in UFRaw allows for an easy control of this parameter.

Since I have already blogged about noise, talked about GREYCstoration and even interviewed David (the author), I decided to have a go at comparing the output of UFRaw vs GREYCstoration on one image.

And this made me think some more about noise and how to treat it.

The base picture

Sorry for the subject (a ficus). It is taken at ISO 3200 (Pentax *istDS maximum ISO) and in dim light. There are some dark areas that make noise pop up. This is what we need for this experiment – note that scaling down the image for the web makes the noise much less disturbing than when viewed at 100%:

But when viewed at 100%, we see that the noise is very present and very colored – not pretty:

UFRaw

The base picture is a RAW file which I developed to my taste in UFRaw as a 16 bits TIFF, keeping noise reduction threshold to 0. This TIFF file is the basic input I will use for GREYCstoration. I then reloaded the Ufraw profile and applied noise reduction without changing any other parameters.

As David mentioned, noise very much boils down to personal taste so you may not share my tastes. I decided to go for a strong reduction (since I had a few ideas about further treatment), so set the cursor to 450. Here is what it looks at 100%:

A typical noise reducted picture: many details have disappeared with the typical water colored overall look and there is still a bit of noise here and there… My goal was to remove colored noise and that was the price to pay for it.

GREYCstoration

At the moment, GREYCstoration is not very easy to use. My way is to load the Gimp plug-in, find the best possible parameters, take a screenshot (don’t laugh) and then apply GREYCstoration from the command line (keeping 16 bits channel quality).

I didn’t use the new patch based algorithm, since I wasn’t able to get a better output with it than with the normal one – maybe due to the pixel nature of the *istDS noise. So I applied GREYCstoration to my TIFF file with parameters giving an ouput close to that of UFRaw. If you are curious here are my parameters:

./GREYCstoration_26 \
-restore ficus_noisy.tif -bits 16 -o ficus_grey.tif \
-dt 100 -p 0.7 -a 0.05 -alpha 1 -sigma 1.78 -dl 0.8 \
-da 30 -fast true -iter 2 -interp 2 -sdt 0

Here is the result at 100%:

A couple of comments here:

  • GREYCstoration is very slow. Don’t start a batch from the command line for 20 16bits TIFF files, you’ll need 3 days of processing. Use GREYCstoration for the image worth high quality printing…
  • The output is very close to UFRaw which is impressive since denoising prior to demosaicing should give better results than afterwards.
  • There is an ugly artifact that shows around the strong image variation (leaves) – which probably can be corrected with choosing better values but I didn’t had the patience to restart the processing all over again…

The great advantage of GREYCstoration is that it can be used in other file types than RAW and gives the best possible result. Unfortunately, the process time and difficulty to find the right settings make GREYCstoration a “use once” tool rather than an “easy to add to your batch” tool.

Noisy frustration

When trying to find the right settings for noise reduction, I was frustrated that there is no way to just “suppress noise”: if you denoise too much, your images looses a lot of detail, if not enough it keeps these ugly color points everywhere. In both cases, you won’t be able to apply as much unsharp mask as normal. Sorry for stating the obvious, but noise is an image degradation and no matter how much software treatment you apply to it, it is just that: a degradation.

So instead of trying to suppress noise (which doesn’t work at least in such an extreme case), I went back to my previous experiments at working with noise (vs suppressing it). Even if we live in the era of super sharp, super saturated and super digital-looking images, I appreciate a grainy picture a lot, especially in Black & White – although color can be very nice too. The problem is that when scaled down for screen viewing, the grain isn’t rendered to its advantage – but a good print from a grainy image is beautiful.

The principle

Although I have touched the subject beforehand, I intend to be a bit more systematic here and give a workable how to. Basically, to go from noise to grain we need to

  • suppress color noise but keep (re-add) b&w noise.
  • re-add noise in the highlights: digital noise is more present in the darker areas than in the highlight (unlike grain which is present equally everywhere).

Re-adding B&W noise

The noise reduction we inflicted to our ficus got rid of noise all together – giving the image this water colored, detail washed look. To re-add noise, simply open the noisy image in Gimp, convert it to B&W, chose “image / color to alpha…” and pick white. You will end up with black grains on a transparent background, which you can save as PNG (here is how the layer looks like on a white background, which makes it more readable):

In Cinepaint (for 16bits), load the PNG on top of your denoised image (as a second layer) – detail (or at least the impression of detail) is back but the image is a lot darker. Add 5 points of saturation to the denoised image (touching up the curves will loose a bit of saturation) and set the noise layer to a transparency of about 60. Flatten the image and add some light via the curves. Here is the global output:

and viewed at 100%:

Don’t do that yet if you plan to go on with the next step, this is just an example of where we are so far.

Adding noise in the light areas

In order to re-add noise in the light areas of the image, we need to start with a noisy uniform image: take a shot of your white ceiling (or wall) as equally lit as possible, with the same ISO setting as your base image (3200 here).

In my case, the image still showed vignetting – to correct it, open the image with Gimp, add a layer, draw a circular gradient on it, add a layer mask and chose mask to selection. Go back to your first layer (white noisy image) and tweak the brightness to correct vignetting as much as possible. Don’t worry about noise appearing in the process🙂 Afterwards, convert the image to B&W and save it – you can reuse this image as “noise frame” for any other noise processing you want to do.

From there, we need to select the light areas from our ficus and apply the selection to our noise frame. Just open the previous PNG file as a second layer on top of our noise frame. From the PNG, add layer mask and mask to selection (using transparency), invert selection (it is the highlight we are interested in) and apply the selection to the noisy frame. Copy and paste as a new layer. This is how it looks like – on a white background:

Indeed, the light areas are the one where we will add noise – it looks like a negative, if anyone still remembers… Save it (with a transparent background) as a second PNG.

In Cinepaint (again), load the denoised version of the image and the two PNG (B&W noise and highlight noise). Add 5 points of saturation to the denoised image, bring down the transparency of the B&W noise and hightlight noise to 60%. Flatten the image and touch up the curves a bit. Here is the output:

And a 100% view:

There isn’t a lot of difference with the previous one (to the point that I wonder if it is worth the trouble) but if you look at the leaves (very light) sides they don’t stand out as much as before. So even if the improvement is tiny, it is there – it would be interesting to test the procedure on a washed out sky…

Ufraw or GREYCstoration?

Just for info, I have used the UFRaw image for my procedure so far. But here is the 100% output starting from the GREYCstoration image:

Not a lot of difference, if you ask me. What makes this image interesting is more the noise treatment than which software was used to process it.

Conclusion

I think that trying to “denoise” images reaches its limits quickly. Rather than hoping for the magical software that removes noise (and doesn’t exists AFAIK), a much better approach is to work around noise to make it as pleasant as possible, ie looking like film grain.

And indeed, we have ways to do just that – although it requires a bit of handy work. I guess most of it could be handled by a script – a nice little project to put in the pile somewhere. And when checking the output from NoiseNinja in a previous post, the output looks very much like what we have here – we must be onto something🙂 .

12 Responses to From noise to grain

  1. n8 says:

    Interesting article. It would be nice to have all the final outcomes side by side for comparison.

  2. Daniel says:

    I enjoyed your article as well, and I want to thank you for continuing to put out quality material for us linux users with photographic interests. Please don’t stop!

    After reading your article I wonder: is denoising of color data theoretically possible with raw images prior to demosaicing? In UFRaw I only see the one threshold control instead of seeing independent thresholds for luminosity and color noise.

  3. Janne says:

    A few points:

    UFRaw has a color (chroma) noise suppression function distinct from the noise removal. If you use that you need much less (or none at all) noise removal to get rid of the color noise. I don’t really understand why you did not use it here?

    Re-adding noise and so on is not the best way to go about things. As you observe, darker areas have more noise (since the signal is closer to the noise floor). So we want to suppress mostly the dark area noise, but not so much (or at all) in the bright areas. And we might want to not suppress any noise in some areas like people’s hair; it look a lot better noisy but with detail than smoothed out an plastic.

    This is how I do it:

    1. Develop the image in UFRaw, with chroma noise removal but no noise removal (noise slider at 0). Save the image, making sure you save the settings file along with it. If you use UFRaw from F-spot it will automatically do so.

    2. Open the raw file again in UFRaw, with the same parameter file (again, from F-spot this is automagic). This time crank up the noise slider until the noise in the mid-to-dark areas is just gone. Ignore the black areas; there’s no detail there anyway. Save it.

    3. Open both images in Gimp as layers (or just open both images then copy and paste the noise-removed one as a second layer over the normal one). Make sure the noise-free image is over the noisy one.

    4. Add a layer mask to the noise-free image. Select “gray scale copy of layer”, and check the “invert layer” at the bottom. The darker the mask, the more the noisy layer below will shine through, and the lighter the mask, the more you will see only the noise-free upper layer. We inverted the mask, so the bright areas in the image will have noise (and detail) while the dark areas – where noise is much more visible – will be noise free.

    5. Use the Curves tool on the layer mask to adjust the level of noise suppression for different brightesses. I usually look for the darkest area in the image where I still want to see clear detail, and make a somewhat steep ‘S’-curve with that area brightess somewhere on the upper flank of the S.

    6. You probably do want a little bit of noise even in the darkest areas or it will look unnatural. Either use the curves tool for it, or adjust the overall opacity of the upper area a bit – set it at, say, 70-80% and you’ll keep a bit of noise structure without any of it becoming too noticeable.

    7. Merge layers and you’re done.

  4. michele says:

    Jeanne, where is the chroma noise removal in ufraw? I must be blind or something because I’ve been looking for it for months…

  5. Janne says:

    It’s “Janne”. And yes, it’s kind of easy to miss – Rudi should make it more prominent:

    In the color balance screen, just above the noise removal slider, to the right of the pop-down menu for the different interpolation methods there is a toggle-button with a brush icon. That’s the one. Toggle it and it’s active.

    Note too, that the preview doesn’t actually show the chroma noise removal effect; you need to convert the image “for real” and look at the end result to see the difference.

  6. michele says:

    Thank you Janne!

    And please forgive me about your name, mine is also prone to misspellings and I know how it feels🙂

  7. jcornuz says:

    Hi there,

    Janne, I have missed the color denoising in UFRaw too. Great comment, maybe better than my entry🙂 Thanks a lot for sharing – more things to try !!

    Take care,

    Joel

  8. Daniel says:

    I just took a look at the “color denoising” that Janne was talking about. It does not really appear to be what you’d expect. In fact it used to be available in old versions of UFRaw as “EAHD Interpolation”. This is not exactly denoising but color smoothing during interpolation, and while this might help, I’m not seeing the kind of denoising I’d expect.

    Here’s what I would expect: an additional threshold slider that will allow a variable amount of denoising based upon chroma, but otherwise just like the wavelet denoising threshold slider that we see now.

    Furthermore, it would be cool to have some sort of ability to perform all of the steps that Janne suggested from within the raw converter, but that’s probably me just being idealistic.

  9. jcornuz says:

    Hi Daniel,

    There is a way to do only chroma denoising with GREYCstoration, but the “grain” ends up less fine than what you can do with converting to B&W. I plan to test Janne’s method and do a side by side to mine.

    Take care,

    Joel

  10. dhill says:

    I just looked over (I didn’t read in depth) in search for some faster way to do colour noise removal in Linux. This is rather not it. But I will my two cents here. I did a different trick in GIMP, decompose image to LAB colourspace, run selective gaussian blur on A and B and compose it back. I think the result should be better, as you don’t loose detail in luminance except for conversion, which should be small. If GIMP had wavelet denoising it would be even better, but at the time I did those it didn’t have.

  11. vitko says:

    As for wavelet denoise for Gimp, have a look at this:

    http://registry.gimp.org/node/4235 (Wavelet denoise plug-in)

  12. Stephen says:

    I found wavelet denoising in ufraw was good, it just needs a little experimentation and tuning. My (new) website has an example and comparison at http://www.tuftumas.com/denoise.html

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: