Some notes regarding Nikon Raw (NEF) image processing

Tools

Recipes

Extract histogram data from a raw image file (Nikon) to create a full dynamic range histogram.

dcraw extracts data completely unprocessed as 16 bit values from raw (no demosaicing, no interpolation, no scaling, no color processing). Then convert produces the histogram data on these values which get reformatted by sed and finally get piped to gnuplot to produce a graph.

dcraw -D -4 -c <RAW image file> \
  | convert pgm:- -define histogram:unique-colors=true -format %c histogram:info:- \
  | sed -n -e 's/^\s*\([0-9]\+\):\s*(\s*\([0-9]\+\),.*$/\2 \1/p' \
  | gnuplot_pipe.pl <gnuplot command file> | gnuplot -p

Example command file for gnuplot

#! /usr/bin/gnuplot
#
# Plot a histogram of a Nikon raw image (NEF) prepared by dcraw and imagemagick
#
# AUTHOR: Lukas Zimmermann

set terminal x11
set xrange [0:4095]   # 12 bit quantization on Nikon D40
set yrange [1:300000]
set logscale y
set style line 1 lc rgb '#0060ad' lt 1 lw 2 pt 7 ps 1.5   # --- blue
plot "-" using 1:2 with lines ls 1

Extract histogram data from a raw image file (Nikon) for only one out of the Bayer quadruple.

Same procedure as above but convert does a minify by sub-sampling at 50% and a roll by 1 in either x or y direction or in both.
see Bayer interpolation with imagemagick


On a Nikon D40 from Exif: CFA Pattern : [Blue,Green][Green,Red]
then green pixels should be "-roll +1+0" and "-roll +0+1",
red pixels should be "-roll +1+1"
blue pixels should be "-roll +0+0"

But looking at the histograms suggests:
green pixels being "-roll +0+0" and "-roll +1+1",
red pixels "-roll +0+1"
blue pixels "-roll +1+0"

dcraw -D -4 -c <RAW image file> \
  | convert pgm:- -roll +0+0 -sample 50% -define histogram:unique-colors=true -format %c histogram:info:- \
  | sed -n -e 's/^\s*\([0-9]\+\):\s*(\s*\([0-9]\+\),.*$/\2 \1/p' \
  | gnuplot_pipe.pl <gnuplot command file> | gnuplot -p

Extract the embedded jpg from a raw image

exiftool -b -JpgFromRaw DSC_0001.NEF > DSC_0001.NEF.jpg

see also here.

Copy EXIF data from one image to another

exiftool -TagsFromFile DSC_0001.NEF DSC_0001.NEF.jpg

see also here.

line
linux logo Powered by Apache
line
This site maintained by:
lukas.zimmermann@unibas.ch
My public PGP key
last updated: 2013-04-15 Valid CSS! Valid XHTML 1.0 Strict