I love grain. A little bit of grain is not only pleasant but it helps increase the perceived sharpness.
I also truly love that darktable has a grain module, it makes my workflow easier. If no GIMP retuching is needed I can achieve the final image in a single program, including grain.
The point is that I’m not completely satisfied with the default grain produced by darktable. I never understood completely why. I decided to investigate deeper the problem. I compared darktable grain with other software: GMIC and snapseed (android app from Google). Snapseed probably has the most advanced, but not open-source, implementation of the three.
Let’s see what we can do.
I will use a test image to explain the problem.
A not-very-artistic photo of a puddle, without grain.
I applied grain to this photo using settings that roughly guarantee a similar amount of grain across the different software. The settings are as follow:
- darktable: roughness 6400 iso; intensity 50%.
- GMIC: Kodak TRI-X 1600; grain merge; opacity 0.25; scale 100; other settings as defaults.
- snapseed: grain 50; intesity 0; default preset.
The settings are a little bit extreme to highlight the grain. The comparison discussion doesn’t change much with lighter grain.
Crop of the puddle, with the grain.
In my opionion, the main problem of the darktable output is that the shadows are not so pleasing. It looks like the noise distribution of the grain is clipped and only the whiter part is present: something like salt particles over a black background.
I think that snapseed is giving the most pleasing grain, delivering a more natural and realistic result. GMIC is also doing a good job but I like it a little less.
Here is a crop of the darktable output in order to better understand the salty effect over the black area.
The grain in an analogical photo comes from the irregular structure of the photo-sensible material deposited on the film. When the exposure is transferred to the photographic paper the noise is transferred differently for different lightness level. Approaching black and white the distribution of the noise collapse.
I think this scheme from ref.  is usefull for understanding the problem:
Adapted from ref. . Film grain histogram is amplified by the slope of paper characteristic curve in midtone while severely compressed by the plateau of the curve in the highlight and shadow.
In the cited paper the authors found that two characteristics of the grain are important in order to have a good looking result:
- the distribution of the grain should be wider on the mid-tones and it should became narrower approaching white and black;
- the distribution of the grain should be symmetrical for mid-tones and it should be skewed for highlight and shadows.
Adapted from ref. . The histograms of the noise in the dark regions is skewed so that the right arm of the distribution is broader than the left one. In the highlight regions the opposite.
For example having a skewed histogram in an highlight region means that there are darker spots than what expected for a symmetrical distribution. The grain appears less uniform. This helps with the organic and realistic feel. The next image hopefully should help to clarify the point. If not some trust is needed.
Adapted from ref. .
I created a linear gradient from black to white in order to deal with some numerical results and not only impressions. I applied grain with the same parameters reported above.
Here it is even more evident that snapseed is producing a smoother transition from mid-tones to black and white. Using a parallelism, it resemble a stone column illuminated on one right side with a soft light. It somewhat delivers a three dimensional feel.
GMIC is dealing better than darktable with the shadows but the highlights are still not very natural.
Using 4096x255 (high*width) images, i calculated the standard deviations of the column producing the following plots. They correlate the amount of noise with the input value of the pixels.
From this plots, it emerges that snapseed grain has a very round and symmetric trend. Confirming the preliminary impressions, GMIC output is similar to snapseed but the noise amount does not go to zero at the edges. Darktable has the most peculiar trend, surprisingly showing correlated peaks.
The next plots shows histograms of the noise for given input values, i.e. for given columns of the 4096x255 images.
Histograms are nearly unchanged for all the lightness input values. Near the edges at 0 and 255 the distributions are clipped.
Histograms are more peaked in shadows and highlights but they still looks somewhat clipped.
The histograms are very similar to the paper ones, with smooth transition and skewed peaked distributions.
Now that we know the what are the possible problems of grain we can try to improve. A possible solution could be to use two instances of the grain module. One will deal mainly with the mid-tones, producing symmetrically distributed grain. The second will help with the skewing part modulating the transition towards shadows and highlights.
An example of implementation. Sorry for the foreign language of the interface.
In this example the instance “Grana” is acting on the mid-tones exploiting a parametric mask. The instance “Grana 1” is acting on darker and lighter part of the image.
Gradient with the proposed double-instance grain.
And here are standard deviations of the noise and histograms:
Finally, the grainy puddle.
I think darktable grain can be improved. Exploiting the main properties of a natural and realistic grain, it is possible to get good results using two instances of the grain module.
A more elegant approach would require to work under the hood to refine how grain in produced and added to the image.
 Kurihara T. et al., Journal of Imaging Science and Technology 55(3): 030503-1–030503-9, 2011