How to create camera noise profiles for darktable


(system) #1

How to create camera noise profiles for darktable

An easy way to create correct profiling pictures

Noise in digital images is similar to film grain in analogue photography. In digital cameras, noise is either created by the amplification of digital signals or heat produced by the sensor. It appears as random, colored speckles on an otherwise smooth surface and can significantly degrade image quality.

Noise is always present, and if it gets too pronounced, it detracts from the image and needs to be mitigated. Removing noise can decrease image quality or sharpness. There are different algorithms to reduce noise, but the best option is if having profiles for a camera to understand the noise patterns a camera model produces.

Noise reduction is an image restoration process. You want to remove the digital artefacts from the image in such a way that the original image is discernible. These artefacts can be just some kind of grain (luminance noise) or colorful, disturbing dots (chroma noise). It can either add to a picture or detract from it. If the noise is disturbing, we want to remove it. The following pictures show a picture with noise and a denoised version:

To get the best noise reduction, we need to generate noise profiles for each ISO value for a camera.

Creating the pictures for noise profling

For every ISO value your camera has, you have to take a picture. The pictures need to be exposed a particular way to gather the information correctly. The photos need to be out of focus with a widespread histogram like in the following image:

Histogram

We need overexposed and underexposed areas, but mostly particularly the grey areas in between. These areas contain the information we are looking for.

Let’s go through the noise profile generation step by step. For easier creation of the required pictures, we will create a stencil which will make it easier to capture the photos.

Stencil for DSLM/DSLR lenses

You need to get some thicker black paper or cardboard. No light should shine through it! First we need to use the lens hood to get the size. The lens hood helps to move the paper away from the lens a bit and the lens hood gives us something to attach it to. Then we need to create a punch card. For wide angle lenses you need a close raster and for longer focal lengths, a wider raster. It is harder to create it for compact cameras with small lenses (check below).

Find the middle and mark the size of the lens hood:

If you have the size, draw a grid on the paper:

Once you have done that you need to choose a punch card raster for your focal length. I use a 16mm wide angle lens on a full frame body, so I choose a raster with a lot of holes:

Untested: For a 50mm or 85mm lens I think you should start with 5 holes in the middle created just with a needle. Put your stencil on the lens hood and check. Then you know if you need bigger holes and maybe how much. Please share your findings in the comments below!

Stencil for compact cameras

I guess you would create a stencil, like for bigger lenses, but create a funnel to the camera. Contributions and ideas are welcome!

Taking the pictures

Wait for a cloudy day with thick clouds and no sun to take the pictures. The problem is the shutter speed and it is likely that you’ll hit the limit. My camera has 37 ISO values (including extended iso), so I need to start with 0.6 seconds exposure time to take the last picture with the limit of my camera, 1/8000 of a second exposure time. So a darker day helps to start with a slow shutter speed.

Use a tripod and point the camera to the sky, attach the lens hood and put the punch card on it. Better make sure that all filters are removed, so we don’t get any strange artefacts. In the end the setup should look like this:

Punch card on camera

Choose the fastest aperture available on your lens (e.g. f/2.8 or even faster), change the camera to manual focus, and focus on infinity. Take the shot! The result should look like this:

The holes will overexpose the picture, but you also need an underexposed area. So start to put most of my dark areas in the middle of the histogram and moved it to the black (left) side of the histogram until the first values start to clip. It is important to not to clip to much, as we are mostly interested the grey values between the overexposed and underexposed areas.

Once you’re done taking the pictures it is time to move to the computer.

Creating the noise profiles

STEP 1

Run

/usr/lib/darktable/tools/darktable-gen-noiseprofile --help

If this gives you the help of the tool, continue with STEP 2 othersise go to STEP 1a

STEP 1a

Your darktable installation doesn’t offer the noise tools so you need to compile it yourself. Before you start make sure that you have the following dependencies installed on your system:

  • git
  • gcc
  • make
  • gnuplot
  • convert (ImageMagick)
  • darktable-cli

Get the darktable source code using git:

git clone https://github.com/darktable-org/darktable.git

Now change to the source and build the tools for creating noise profiles using:

mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=/opt/darktable -DBUILD_NOISE_TOOLS=ON ..
cd tools/noise
make
sudo make install

STEP 2

Download the pictures from your camera and change to the directory on the commandline:

cd /path/to/noise_pictures

and run the following command:

/usr/lib/darktable/tools/darktable-gen-noiseprofile -d $(pwd)

or if you had to download and build the source, run:

/opt/darktable_source/lib/tools/darktable-gen-noiseprofile -d $(pwd)

This will automatically do everything for you. Note that this can take quite some time to finish. I think it took 15 to 20 minutes on my machine. If a picture is not shot correctly, the tool will tell you the image name and you have to recapture the picture with that ISO.

The tool will tell you, once completed, how to test and verify the noise profiles you created.

Once the tool finished, you end up with a tarball you can send to darktable for inclusion. You can open a bug at:

https://redmine.darktable.org/

The interesting files are the presets.json file (darktable input) and, for the developers, the noise_result.pdf file. You can find an example PDF here. It is a collection of diagrams showing the histogram for each picture and the results of the calculations.

A detailed explanation of the diagrams and the math behind it can be found in the original noise profile tutorial by Johannes Hanika.

For discussion

I’ve created the stencil above to make it easier to create noise profiles. However I’ve tried different ways to create the profiles and here is one which was a good idea but failed for low ISO values (ISO <= 320). We are in the open source world, and I think it is important to share failures too. Others may have an idea to improve it or at least learn from it.

For a simpler approach than the one described above, I’ve created a gradient from black to white. Then I used some black cardboard to attached it to the monitor to get some real black. Remember you need an underexposed area and the monitor is not able to output real black, as it is backlit.

In the end my setup looked liked this:

I’ve turned off the lights and took the shots. However the results for ISO values below and equal to ISO320 are not good. All other ISO values looked fine.

If you’re interested in the results, you can find them here:

Please also share pictures of working stencils you created.

Feedback is very much welcome in the comments below!


This is a companion discussion topic for the original entry at https://pixls.us/articles/how-to-create-camera-noise-profiles-for-darktable/

#2

Great write up Andreas! I hope it encourages others to contribute to darktable. Have you noticed a big improvement with the custom profile?

If anyone is using the open source AMD drivers and can’t get OpenCL working in darktable, Andreas has an easy to follow guide here: https://blog.cryptomilk.org/2018/03/02/using-amd-open-source-and-the-amdgpu-pro-opencl-driver-for-image-processing/


(Tore Busch) #3

Excellent article, and just what I need! I have a Samsung NX1 camera that does not have an official noice profile in darktable yet, and have tried to generate noise profiles based on the original article on the darktable site, but did not quite manage to get good enough source images to be included in the distribution.

But after seeing this, I will definitely try again :slight_smile:


(Andreas Schneider) #4

Thank you Riley. The denoise (profiled) module gives you normally the quickest way to get good result for denoising. There is a nice triple which works on lightness, color and average which gives amazing results without loosing much detail.


(Andreas Schneider) #5

The first stencil I created failed, I just had two big holes. Then I created the one in the article and directly succeeded. Start with needle holes and improve from there, make sure you have some real black in the pictures (the edges which are only black in mine). If you’re successful please share you’re stencil and tell us which lens you used.


(Chris E) #6

I just took an out-of-focus photo of a bright spotlight shining on a wall in a dark room. This ensured I had blown highlights, clipped shadows and a range of brightness in between. Used this method to profile a couple of cameras and the generated profiles were accepted by the project. Seemed to work well.

When I ran it I used a differently-named script but, without the “-d $(pwd)” option I believe it will attempt to take the photos for you. Requires you to have tethered your camera via USB, pre-focussed the shot and have your camera be supported by gphoto2.


(Andreas Schneider) #7

Hi Chris,

this also sounds like an interesting idea. What light did you use exactly and can you post an example photo of a shot you took?


(Chris E) #8

I can’t upload at the moment but if you look at https://redmine.darktable.org/issues/10868 (comment 21) I think they’re included in the tar.gz I uploaded. As you can see I was considering writing such a guide myself to encourage more users to contribute, based on the original blog post https://www.darktable.org/2012/12/profiling-sensor-and-photon-noise/, which is a bit complicated and slightly off-putting unless you can get past the science!

I just used a normal lamp (LED bulb I think).

According to the original blog post, the only requirements are “take one shot per iso. it has to be out-of-focus and have a widespread histogram, i.e. be over- and underexposed at the same time”


(Chris E) #9

One of my profiling images. As you can see I didn’t put much thought into it apart from making sure it fit the criteria (out of focus, under- and over-exposed)


(Andreas Schneider) #10

I expected something different, but I have a new idea: Get a normal white piece of paper (a bit of light can shine trough) with a black frame (non-transparent). Illuminate the white paper from behind. Make sure to be far away from a wall and turn off the lights. This way the background should be black, we have a white spot in the middle which should transition to gray. If this is not overexposed yet, we can make a small hole in the middle of the paper for the overexposure.

Maybe someone could try this out …


(Chris E) #11

Worth a try though I’m not sure you’ll get a smooth transition all the way from white to black (there may be parts of the histogram that are empty, though defocusing will help). The simpler you can make the process the more likely people will give it a go.

Another thing to mention… Once I had my generated profiles accepted into the project there was a period during which I was waiting for them to be included in the next release of DT. In the meantime I found that the generated profiles could be manually incorporated into my existing DT installation by manually modifying the installed noiseprofiles.json file to include the contents of the generated presets.json. On my system (ArchLinux) I found the DT installed noise profiles in /usr/share/darktable/noiseprofiles.json.

Make sure you take a backup first!


(Andreas Schneider) #12

It was my intention to have some brainstorming and people contributing to the process. The more stencil we can test and get results from it, the easier the process will become. We can always update the article.


(Alex Mozheiko) #13

Oh, this method so sweet, can’t wait to try it :slight_smile:


(David Vincent-Jones) #14

I managed to make an image using a combination of outside/inside light that worked quite well. The results however astounded me and now provide an excellent correction (automatically) through the full ISO range of my camera. The only time that I need to adjust my denoise setting is when I push process a part of the image and therefor theoretically modify the image’s local ISO. Profiling took very little time and the developers now include my camera profile in the distribution. If your camera is not currently listed … do it!


(Chris E) #15

Could you explain what advantages the stencil has over the ‘out of focus under- and over-exposed’ approach (like the sample image I posted). Does it give a better quality denoise? I’ve had very good results from the simpler approach but perhaps I’m missing something.


(Andreas Schneider) #16

A lot of people tried and had over and underexposed areas, but the results were unusable. You find a lot of open tickets for camera support where it didn’t work. The stencil makes it easier to get good results. We need a good transition from white to black. We are interested in the grey between them. Your image has a lot of color, if you look at mine, there is white, black and grey (no color). The out of focus areas produce the grey values we’re interested in …


(Chris E) #17

Based on my unscientific research (I’ve looked through a number of the most recent accepted and rejected profiles in darktable issues) most of the tickets that were rejected seem to have one of two comments:

  • Not out of focus enough
  • Not enough values between over- and under-exposed

Many of the accepted images have colour in them - indeed white and grey contain all of the colours. I see a lot of accepted profiles based on images similar to mine - an image of a light on a wall in a dark room ensures a good range of values as the brightness drops off gradually with distance and a bare bulb ensures over-exposure.

My understanding is that the reason for defocussing is two-fold. First (most important) it prevents any finely textured objects from masquerading as noise. Second it will (as you say) give more values between over- and under-exposed.

I see where you’re going with the stencil approach though. It definitely could lead to a consistent reproducable way to produce noise profiles, which can only be a good thing and encourage more people to try it.


(Chris E) #18

I thought it might be useful to post some example images that have been successfully used to produce noise profiles (ones that have been accepted into the darktable project). I’ve also provided the relevant issue reference from https://redmine.darktable.org/issues for each image.

As you can see there’s quite a lot of variance in the images but all have produced acceptable profiles.

11842


11865

12007

11684

12095

11496

11291

10213


(Eduardo Battaglia) #19

I’ve recently did the noise profile for my Nikon D5600 following the original darktable post.
https://redmine.darktable.org/issues/12116
No comments yet, so I don’t know if they are going to accept it.

One thing I see you did differently is that you didn’t apply the “raw linear” style to your RAW images.

this makes sure we get linear camera raw rgb with no basecurves, no whitebalance, etc in the way. it is essential that you apply this style.

Just wondering why you choose not to apply it.
Thanks!


(Chris E) #20

When I ran my own, AFAIK the script did all that automatically. Following the original post (and taking into account that the script has changed a bit since then) I just set the camera up, tethered it and ran

~/darktable/tools/noise/gen-profile

The script did the rest - took the images, processed them and auto-generated the tar.gz file