Trying to derive linear image from NEF, how do I use cam_mul?

I am trying to derive a linear image from a D7000 NEF 14-bit. I need both color and gray. I am using opencv cv::cvtColor(rawMat, debayeredMat, cv::COLOR_BayerBG2BGR) to convert to RGB CV_16UC3 (3 component ushort).
I believe I need to use cam_mul to get proper wb.

I am getting these values for cam_mul
cam_mul[0] = 486
cam_mul[1] = 256
cam_mul[2] = 371
cam_mul[3] = 256

I am not sure how to use these values to get anything sensible.

Thanks for any help you can provide!


If you want to use your own

If you want to use your own processing (demosaic), you need to
- subtract black (bias) level. It is zero for D7000, so if you working with only one camera, skip this step
- multiply to WB coeffs.
To not overflow ushort data, you need multipliers less than 4.0 (16-bit range and 14-bit data), so normalize the multipliers (divide to something) to fit range 0.0..4.0

-- Alex Tutubalin

Great! Thanks!

Great! Thanks!

To follow up. If I demosaic, subtract black, scale with normalized multipliers(cam_mul), then do a max() of all three color components, I should generally have a linear black and white image, correct? Anything else I should consider or be concerned about?


Generally, you need to apply

Generally, you need to apply WB before demosaic (if your demosaic method use something like luminosity maps, the components should be balanced before).
Also, bias subtraction should be done before WB (and demosaic).

I do not think, that max(R,G,B) will give you good BW image. Better use something like RGB to Y[CC] or Lab conversion and use Y or L channel as BW image.

-- Alex Tutubalin

Ahh. Yes, tons more I need to

Ahh. Yes, tons more I need to learn. Can you recommend a Libraw process to derive linear RGB and BW images from D7000 NEF? I'm looking for a "no-frills" kind of implementation if possible. The output is for a 3D structured light setup which is dependent on capturing a series of linear images.
Thanks again for your help!