Add new comment

Determining CFA Pattern from cdesc and filters

Hi folks,
This is my first rodeo using libraw to read RAW files and so apologies in advance if these questions are very trivial.

I am trying to determine the Bayer layout of the RAW images in some sample images I have. It appears that using the filter field in conjunction with cdesc is the way to go. Please correct me if I am mistaken.
I also tried to call COLOR function to confirm my understanding. But, the results I am getting do not appear to be consistent.

My workflow is below:
LibRaw rp;
rp.open_file(fileName);
rp.unpack();
% Inspect rp.imgdata.idata
rp.raw2image();
int c = rawProcessor.COLOR(0, 0);
c = rawProcessor.COLOR(0, 1);
c = rawProcessor.COLOR(0, 2);
c = rawProcessor.COLOR(0, 3);
c = rawProcessor.COLOR(1, 0);
c = rawProcessor.COLOR(1, 1);
c = rawProcessor.COLOR(1, 2);
c = rawProcessor.COLOR(1, 3);

For a sample DNG file, I got
cdesc = "RGBG" and filters = 3789677025. This translates to a G2 B R G1 pattern. I derived this by examining the 32-bit value 2 bits at a time. The COLOR outputs based on the code above are in the order 1, 0, 1, 0, 2, 3, 2, 3 which dont appear to match the pattern derived from filters and cdesc.

Similarly for a NEF file, I got
cdesc = RGBG" and filters = 3031741620. This translates to B G2 G1 R pattern. The COLOR outputs based on the code above are in the order 0 1 0 1 3 2 3 2 which dont appear to match the pattern derived from filters and cdesc.

Is cdesc and filters the correct way to derive the CFA Pattern?

Appreciate any help.

Dinesh

Forums: