Converting RAW images from Color to Mono

I need to convert raw images from color to mono using libraw. How libraw performs demosaicking for returning the individual R,G,B values for each sensor. so that the resulting image could have the checker pattern for each colors depending on the sensor filters.

Forums: 

libraw do not contain any

libraw do not contain any color->BW conversion code.
So, you may choose from two options
* convert interpolated (by libraw) rgb data to BW using your preferred formula
* or implement own raw to BW postprocessing instead of LibRaw::dcraw_process()

If you're processing data from 'converted' camera (initially color, but CFA removed, such as maxmax.com conversion), you may try to set imgdata.idata.colors to 1 after unpack() phase

-- Alex Tutubalin

Thank you!!

Thank you!!
So, libraw doesn't perform -d Document Mode (no color, no interpolation) like dcraw.
Thanks!

Getu Nigussie

It is implemented in

It is implemented in different way:

after unpack() call, decoded raw data are placed in
imgdata.rawdata.raw_image[] - for bayer image
imgdata.rawdata.color3_image[3][] - for 3-color images
imgdata.rawdata.color4_image[4][] - for 4-color images
(only one of these pointers is non-zero after unpack() call).

So, you may access unprocessed raw values directly.

Also, if you port code from dcraw.c (or old LibRaw versions), you may use LibRaw::raw2image() call to copy data from above-mentioned arrays to imgdata.image[4][] array

See samples/unprocessed_raw.cpp as a sample of raw_image[] array access.

-- Alex Tutubalin

Thanks Again!!

It is Bayer and imgdata.rawdata.raw_image[] only returns nonzero. How can I copy this data to Mat object (OpenCV) Could you provide me an assistant, Please!!

Getu Nigussie

Sorry, know nothing about

Sorry, know nothing about OpenCV

Look into unprocessed_raw.cpp sample

-- Alex Tutubalin