Dcraw 8 bit output versus 16bit output.

norsk

Dcraw 8bitThe picture at right is straight from dcraw in 8 bit mode. In this post I try to find out what dcraw does in 8bit mode versus 16 bit mode. The point for me is just to learn more about how dcraw works.
If you have played with dcraw you have certainly noticed the big difference between 8 and 16 bit output. The difference is explained in the man page: It says something like this:

” with no gamma curve, no white point, , and no -b option.”

and another place

“BT.709 gamma curve and a 99th-percentile white point”

The default not gamma corrected output from “dcraw -4″ looks like this:

dcraw not gamma corrected

This is of course very dark and as explained above I need to gamma correct this and set the whitepoint.

The gamma step gave me some headache. There is a lot of tools out there that let you applay a gamma curve to an image. But gamma curves are different. Since the manula says that it is a BT. 709 curve it was much simpler to find the right one. The tool netpbm is able to gamma correct with an BT. 709 curve. Unfortunately the netpbm version that comes with ubuntu linux have some shortcomings. After I had compiled it from source I was able to use pnmgamma with option -bt709ramp.

The whitepoint gave me similar problems. I had to recompile netpbm to get the more fancy options of pnmnorm. The white point is mentioned to be 1 percentile. I fixed this with pnmnorm -colorvalue -bvalue 0 -wpercent 1. The colorvalue option is absolutely necessary. It instructs pnmnorm to use HSV space and the value channel. The -bvalue set the blackoint to zero, therefore no blackpoint scaling. The -wpercent 1 clips the white point at 1% of the brightest pixel.

This whitepoint setting is aggressively and clips highlights. I also note for myself that the blackpoint is not set. Normally I would do a -wpercent 0.01 and -bpercent 0.01 and use this file as a starting point for later contrast expansion. But here the point here is to find out how dcraw works in 8bit mode. To conclude:



dcraw -w -T -v crw_7386.crw

gives almost same result as

dcraw -4 -w -v -c crw_7386.crw |pnmgamma -bt709ramp|pnmnorm -colorvalue -bvalue 0 -wpercent 1 |pnmdepth 255| pnmtotiff -truecolor  > crw_7386.tif

Then I end up with this one:

dcraw 16bit

The histogram difference are small. The histograms are created with help of the histog script created by Fred Weinhaus.

dcraw histogram

The -b option

There is also a b option in dcraw when you work in 8bit mode. What does it do. To me it looks like it just set the whitepoint in either direction. The output from dcraw -b 2 looks like this:

b2 with histogram

I think I get similar output if I use the curve tool like this.
Curve tool
The b values <1 can be archive either with the curve tool or with pnmgamma. The image over created with -b can be made with

dcraw -w -v  -c crw_2007_10_07_1112a.crw |pnmnorm  -bvalue 0 -wvalue 47185 |convert - b2like.png

and for 16 bit just pass it thru the command above.

dcraw -4 -w -v -c crw_2007_10_07_1112a.crw |pnmgamma -bt709ramp|pnmnorm -colorvalue -bvalue 0 -wpercent 1 |pnmnorm  -bvalue 0 -wvalue 47185 |convert - b2like-16bit.tif

The -wvalue here is an empiric number, after a few tests.

For b values <1 I found no way to use netpbm, but imagemagick can do this. I found a script called im_fx_curves on one of Anthony Thyssen’s excelent imagemagick example pages. I ended up with something like this.

dcraw -w  -v  -c crw_2007_10_07_1112a.crw  |convert - -fx ` ./im_fx_curves -p   0,0  100,72 ` like_b_0,5.png 

The im_fx_curve 0,0 100,72 in the middel of the command line is almost self explained. It lover down the 100,100 to 72. The problem is that the -fx operator is very slow and it’s much faster to just load the image in cinepaint and do it there with a curve.

Leave a Reply

Please copy the string T00M95 to the field below: