Add new comment

After unpack(), I'm trying to

After unpack(), I'm trying to use the raw_image as an input to opencv demosaicing (with cvtColor and type CV_BayerGB2RGB), and thus avoid the use of dcraw_process for demosaicing. opencv here requires a 1-channel data image. Yet when I use the raw data after unpac(), starting from the first visible pixel, it gives me some rubbish image.
As far as you know at least on the Libraw's side, am I getting the raw CFA data wrong? See below:

int raw_width = (int) rawProcess.imgdata.sizes.raw_width;
int top_margin = (int) rawProcess.imgdata.sizes.top_margin;
int left_margin = (int) rawProcess.imgdata.sizes.left_margin;
int first_visible_pixel = (int) (raw_width * top_margin + left_margin);
cv::Mat imRaw(naxis2, naxis1, CV_16UC1);
    ushort *rawP = imRaw.ptr<ushort>(0);
    for (int i = 0; i < nPixels; i++)
        rawP[i] = (ushort) rawProcess.imgdata.rawdata.raw_image[i+first_visible_pixel];
    cv::Mat demosaiced16;
    cvtColor(imRaw, demosaiced16, CV_BayerGB2RGB);

Above, imRaw.ptr is the pointer to the data buffer in the cv::Mat object where I want to copy my raw_image data.

The expected image (which I get after dcraw_process) is:

And instead, I have this: