Use a Samyang 14mm in darktable

rose_14mm_test

I just got myself a Samyang 14mm lens, more precisely the Samyang 14mm f/2.8 AE ED AS IF UMC, branded as Walimex Pro, but that is basically just a sticker, the lens is the same. In its latest incarnation with AE, so there is no more manual aperture setting and the resulting images contain EXIF data. Nice. However, Samyang decided to label the lens Canon EF 14mm f/2.8L II USM in the Exif data, so automatic lens correction doesn’t work. With this small Lua script that can be fixed by just replacing the lens name on import. I just have to make sure to never buy the real Canon lens as that would be “fixed”, too.

local dt = require "darktable"

dt.register_event("post-import-image",
  function (event, image)
    if image.exif_lens == "Canon EF 14mm f/2.8L II USM" then
      image.exif_lens = "Samyang 14mm f/2.8 AE ED AS IF UMC"
    end
  end
)

Comments are great

When programming I write small programs all the time. Sometimes as a test bed when looking for a bug, sometimes to help understand a library, sometimes as a tool to do things for me. They are relatively small in general, a single file, few hundred lines of code max. And more often than not I keep them when done. As reference about how to use an API, because I think the tool is helpful or just because you never know if some spare bytes might be handy in the future. Quite often the command to compile the whole thing isn’t just a straight forward gcc as libraries need to be linked, C standards have to be specified, you name it. In the past I just had a comment in the top of all these files looking like this:

// gcc -Wall -g -o hello_world hello_world.c && ./hello_world

#include <stdio.h>

int main()
{
  int i; // <-- just to see some compiler output in the example
  printf("hello, world\n");
  return 0;
}

Whenever I came back to it I copy&pasted it to my shell and was happy. Now, given that I like to tinker I wanted to make that easier and quicker, so here is my new way of doing it:

#define SHELL_HELPER \
 gcc -Wall -g -o hello_world hello_world.c && ./hello_world; exit $?

#include <stdio.h>

int main()
{
  int i; // <-- just to see some compiler output in the example
  printf("hello, world\n");
  return 0;
}

With this I can now treat the C file as a shell script:

$ sh hello_world.c
hello_world.c: In function ‘main’:
hello_world.c:8:7: warning: unused variable ‘i’ [-Wunused-variable]
   int i; // <-- just to see some compiler output in the example
       ^
hello, world

The reason why that works is that the # is a comment in the shell, so it’s ignoring the first line. Then it executes the second which ends in a call to exit which terminates the script once the sources are compiled and the result run.
The compiler on the other hand sees a #define in the first line, and as it ends in a backslash it also covers the second line. Thus it’s basically ignored.

Neat, isn’t it?

Fake miniatures in darktable

Faking the looks of a miniature shot with its shallow depth of field is quite easy in raster image editors like GIMP, but sometimes you might want to do that step directly inside of darktable. While that is not as flexible and fast for single images when you have a complicated composition in your photo and need to work pixel perfect it can however save you a lot of time for simple scenes and when you have to apply the same editing steps to a big number of images, for example when doing a timelapse.

    the photo I am working with, only default modules applied

the photo I am working with, only default modules applied

In order to pull off a convincing job the photo you are working with should have a fairly wide view, some objects of interest in the middle ground and not too many overlaps of objects with different distances from the camera. Ideal is a view from some high point on a relatively flat area.

I am going to use a not-quite ideal photo to show different techniques and where a tool like GIMP has benefits.

As we can see the image has something to focus on in a medium distance from the camera, a relatively flat ground, and the view isn’t too narrow either. However the sitting people are overlapping parts of the pavement that is much farther away from the camera which we have to deal with somehow.

exposure and saturation changed

exposure and saturation changed

In a first step I am fixing the exposure and adding quite some saturation to make it look more like an artificial miniature world.

Next I am enabling the lowpass module in the effects group, setting the blur radius to 15. In order to keep the man on the bench in focus I add a first bézier mask in the form of a rectangle with a falloff that is wider on the bottom to simulate a shallow depth of field. By default that would lead to a blurred region in the middle of the image with the rest untouched. That’s not exactly what I want, so I enable invert mask in the module settings.

the mask for the ground

the mask for the ground

Due to the aforementioned overlap of man and background I also have to mask him out, so I add a second bézier mask and try to trace around him, playing with the falloff size where I have to. With this image it’s possible to do that, even though it would have been easier in GIMP where layer masks allow working really precise. The resulting mask should exclude everything with the same distance from the camera and thus be in focus.

preview of the mask for the in-focus area

preview of the mask for the in-focus area

The result isn’t that bad if my sloppy work with masking out the guy is ignored. If you invest more time it could be done much better.

result with just one instance of lowpass

result with just one instance of lowpass

Since objects that are further away from the camera are blurred more I add a second instance of the lowpass module with a radius of 30. To mask out the center part I add two gradient masks. They can be dragged on the canvas, and the falloff can be changed with the mouse wheel – just as with other mask types.

preview of the gradient masks for the big blur

preview of the gradient masks for the big blur

For simpler scenes without overlapping or if less blurring is used this is a quick and copy&pasteable way of adding a miniature effect to image sequences. In this case it would be borderline as the man would probably be moving so a tracking mask would be needed, something darktable doesn’t support (yet). For static landscape scenes it’s a viable option though.

final result with two passes of blurring

final result with two passes of blurring

If you want to try it yourself you can download the raw file and the XMP of my result to play around with.

In case you didn’t notice: you can click on all the images to see them bigger.

Update: I replaced the final version with a less sloppy one. The raw+XMP package got updated.