using example, image data not understood

Reading a CR2 canon file from a Canon 6D MK1, known good. Using the example code on the "https://www.libraw.org/docs/API-overview.html" page; the max value out of any RGBG sample is about 5600. Scaling the data up ((data/5600.0)*65535) to a full 16bit sample results in what looks like fairly even tempered noise, not anything like the image data that is actually in the file.

I want to read out the RGB values of the image, and this doesn't seem to do that:

iProcessor.open_file(
iProcessor.unpack(
iProcessor.raw2image(

Followed by a loop reading the data, as follows, where v step through the image size as shown in the example:

iProcessor.imgdata.image[v][0];
iProcessor.imgdata.image[v][1];
iProcessor.imgdata.image[v][2];
iProcessor.imgdata.image[v][3];

The image dimensions are right, and I am not getting any errors (API call results are 0.)

It is presently unclear to me just what I am supposed to do, other than the example, to read back valid 16 bit/channel RGB image data.

Forums: 

1st: raw2image does not

1st: raw2image does not subtract black level, most likely you need to do that (by calling LibRaw::subtract_black() after raw2image).

Also, you may access raw data via imgdata.rawdata.raw_image (this is flat array with unaltered raw values; pixels outside of active area are included too).

max value of 5600 (before black subtracted) is about ~2 stops lower than this camera data range, so your image is, most likely, heavy underexposed.

-- Alex Tutubalin @LibRaw LLC

okay...

I found an error with my code; I can now read the data. Thank you for your prompt reply.

However, it appears to be Bayer sensor mosaic data; does libraw do conversion to adjusted, de-mosaiced 16-bit image data? Or is that something I am expected to do from the bayer mosaic data?

Here's part of the image as displayed in Adobe Lightroom:

http://fyngyrz.com/images/from-lightroom.png

Here's what I'm reading from more or less the same region:

http://fyngyrz.com/images/from-libraw.png

I have not done a black level subtraction, inasmuch as that would dim the image even more.

LibRaw::dcraw_process does

LibRaw::dcraw_process does full postprocessing pipeline (white balance, demosaic, color conversion...)

-- Alex Tutubalin @LibRaw LLC

good

Good to know. Is there an example somewhere that shows how to do that in a step by step manner?

What I would like is to be able to load an image from the raw file as the camera generally would have the user see it using the user's white balance and so on, exposed as they see it on the camera's preview. Ideally, it would be ready to view and do further adjustments to if desired.

This sequence:

iProcessor.raw2image();
iProcessor.subtract_black();
iProcessor.dcraw_process();

resulted in a deep red image. Not correct at all.

If I load it with just this...

iProcessor.raw2image();

...I can, with a serious gaussian blur and a window and level adjustment, turn it into something close to what it should be.

So I'm still missing something.

win win win

Alex,

Here's a comparison between the two. I turned around and looked at the guitar, and the libraw result is truer to the actual colors of the instrument than the lightroom first-pass rendering:

http://fyngyrz.com/images/comparisonnow.png

Alex, I suggest you add these to your example on the API intro page:

// Convert from imgdata.rawdata to imgdata.image:
// ----------------------------------------------
iProcessor.raw2image();
iProcessor.imgdata.params.use_camera_wb=1;
iProcessor.subtract_black();
iProcessor.dcraw_process();

Kudos. Fine work you've done. :)

Could you please convert this

Could you please convert this image to DNG and look at the value of the baseline exposure tag? LibRaw doesn't apply that correction of lightness.

--
Iliah Borg

conversion to DNG

How would you have me convert it? What tool, etc. I'm using OS X 10.12