Ufraw support for Nikon D5100

2012-08-09    Filed under photography, Tags nikon ufraw

Ufraw is a very nice open source program to develop raw files from digital cameras. It imports a variety of camera raw file formats, in particular NEF files from Nikon cameras. But unfortunately, at current version (0.18) it doesn't support the Nikon D5100 files.

By using some web references (see below) I was able to modify the source code and compile the program myself so now it is capable of opening and converting the NEF files of this camera. It isn't difficult but I had to gather the needed information from several different web pages so I wrote a quick notes on how to do it.

This instructions are for a Debian based distribution of Linux, but the general idea should be the same for others. The Nikon D7000 is supported by the program and the sensor in that camera is exactly the same as in the D5100.

First you need to download source code of ufraw from the download page in its website. In particular I got the ufraw-0.18 tarball file. Download it and extract to some work directory.

Modifications to source files

First, it is necessary to include the sensor data. Without this sensor information the error "image: channelmultipliers: valor 0.000 too small, truncated to 0.100" shows when trying to change color temperature (white balance).

Edit file dcraw.cc and find a line like this:

{ "NIKON D7000", 0, 0,
  { 8198,-2239,-724,-4871,12389,2798,-1043,2050,7181 } },

Just copy the line so you have an entry for the D5100 with the same values:

"NIKON D5000", 0, 0xf00,
  { 7309,-1403,-519,-8474,16008,2622,-2433,2826,8064 } },
"NIKON D5100", 0, 0,
  { 8198,-2239,-724,-4871,12389,2798,-1043,2050,7181 } },

Further down in the same file a line like this can be found:

} else if (!strcmp(model,"D7000")) {
    width -= 44;

It should be modified to:

} else if (!strcmp(model,"D5100") ||
         !strcmp(model,"D7000")) {
    width -= 44;

Both sensors D7000 and D51000 have the same dimensions. Without this change a thin black strip appears to the right side of every interpolated image.

Second, the white balance multipliers for each white balance camera settings must be added. This values can be extracted from the camera by taking a picture with each white balance preset and loading it in ufraw. Then select "Camera white balance" and take note of the multipliers that appear in the white balance settings.

Open the file wb_presets.c and add an entry for D5100, just after D5000 and before D7000, like this:

{ "NIKON", "D5100", DirectSunlight, 0,         { 2.0273, 1, 1.3906, 0 } },
{ "NIKON", "D5100", Flash, 0,                  { 2.2813, 1, 1.2109, 0 } },
{ "NIKON", "D5100", Cloudy, 0,                 { 2.1680, 1, 1.2656, 0 } },
{ "NIKON", "D5100", Shade, 0,                  { 2.4922, 1, 1.1367, 0 } },
{ "NIKON", "D5100", Incandescent, 0,           { 1.3047, 1, 2.2148, 0 } },
{ "NIKON", "D5100", SodiumVaporFluorescent, 0, { 1.2031, 1, 2.4375, 0 } },
{ "NIKON", "D5100", WarmWhiteFluorescent, 0,   { 1.3008, 1, 1.9648, 0 } },
{ "NIKON", "D5100", WhiteFluorescent, 0,       { 1.4961, 1, 2.3047, 0 } },
{ "NIKON", "D5100", CoolWhiteFluorescent, 0,   { 1.8320, 1, 2.0273, 0 } },
{ "NIKON", "D5100", DayWhiteFluorescent, 0,    { 1.8984, 1, 1.3906, 0 } },
{ "NIKON", "D5100", DaylightFluorescent, 0,    { 2.1680, 1, 1.1172, 0 } },
{ "NIKON", "D5100", HighTempMercuryVaporFluorescent, 0, { 2.4844, 1, 1.3672, 0 } },

Install dependencies for compiling

All necessary instructions are written in the download page of ufraw, but for my particular distribution (Linux Mint LMDE 201204) all I need is the following command to install the needed development libraries:

sudo apt-get install libglib2.0-dev liblcms-dev \
    libgtk2.0-dev libgtkimageview-dev libgimp2.0-dev \
    libexiv2-dev libjpeg-dev libtiff-dev libcfitsio3-dev \
    libbz2-dev liblensfun-dev

Then prepare source tree to compile:

./configure --with-gtk --with-gimp --enable-extras \
    --enable-dst-correction --enable-contrast --enable-mime

Check that everything is right and compile and install:

make
sudo make install

This will install ufraw executable at /usr/local/bin/ufraw. And that's all.

Edit:

See the entry Ufraw with Nikon D5100 and Archlinux for instructions on how to prepare a package for Archlinux.