preserving DNG brightness on conversion to RGB

I'm trying to use libRAW to convert some DNG files into a format readable from Matlab.

I take a number of images with specific exposure times and I need the conversion from DNG to any RGB format to preserve the relative luminosity of the images.

If I do the conversion using the Adobe DNG SDK it works well (I use stage 3 of the conversion, before auto-exposure and other processing).

If I use DCraw_emu from the libRAW Windows binaries, I see that the relative brightness of the images is altered.

I attach a plot of the average pixel value for both the cases. You can see that the SDK gives me a linear average value VS exposure time, as I expect, while libRAW does something to the images. I don't mind if the converted images have a gamma/black level applied to them, but nothing else, and they need to sit on a smooth curve.

For libRAW I run

dcraw_emu -W INPUT

Any suggestions?


Image icon imgavg.png22.66 KB


dcraw (and, so, LibRaw)

dcraw (and, so, LibRaw) standard processing is 'auto-ETTR', there are a lot of option to change it.

-- Alex Tutubalin @LibRaw LLC

anything I can do via options

anything I can do via options in the binaries? Any pointers on where to start would be great. Thanks.

Thanks. I tried different

Thanks. I tried different combinations of the options in the list you linked, but no luck.
Can you point me to where I can access settings for Auto-ETTR in the source code?

Auto-ETTR is performed on

Auto-ETTR is performed on output stage, while converting from linear internal representation to gamma-corrected output in LibRaw::write_tiff_ppm or LibRaw::copy_mem_image

-- Alex Tutubalin @LibRaw LLC


I'm also struggling with this. Can you point out which command do I need to use to turn it off?

Could you please clarify: you

Could you please clarify: you use LibRaw library from your application, or some LibRaw sample programs 'as is' (as a command-line utility)

-- Alex Tutubalin @LibRaw LLC

Yes, this should(*) turn off

Yes, this should(*) turn off auto-ETTR/auto-scaling, so this will result into dark(er) images.

(*) we're not responsible for AndroidLibRaw so not absolutely sure set....() calls works as expected.

-- Alex Tutubalin @LibRaw LLC

Sorry, I didn’t realize right

Sorry, I didn’t realize right away that I was already talking with two people.

Could you please formulate your problem not referring to the 'OP'. Also, it would be great to have RAW file(s) in question еo discuss something in specific detail and not in the abstract.

-- Alex Tutubalin @LibRaw LLC

example images

You can find an example dataset here

There you can find
1) DNG images from the camera
2) JPG images automatically generated by the camera (I use those to get exposure times from EXIF data)
3) TIF images obtained using the stage3 output of the Adobe DNG SDK
4) PPM images obtained using dcraw_emu.exe -W (which should be equivalent to what described in this comment

I like the TIF images because for half the exposure time I get half the pixel value, across the exposure range. The PPM images are not predictable, which implies that some extra processing is happening. Please see the original attachment for a plot of image average (across all pixels, all channels) VS exposure time.

>> for half the exposure time

>> for half the exposure time I get half the pixel value

If you need 'linear output' you probably may want to set output gamma to 1.0

-- Alex Tutubalin @LibRaw LLC

Also, your 'tif' files are

Also, your 'tif' files are not white-balanced, probably you may want to set custom 'Uni-WB' white balance.

Also, if you want to get unscaled/unaltered data extracted: take a look for unprocessed_raw and/or 4channels LibRaw samples.

-- Alex Tutubalin @LibRaw LLC

Thanks for the suggestions

1) when using dcraw_emu, -g 1 0 doesn't seem to have an effect on top of -W. I actually don't have a problem with having a non-unitary gamma, as long as it is the same on all images. I can compensate for that later in the processing.

2) White Balance is not really a problem neither, I have a neutral area in the target I'm imaging and I will in any case perform white balance using that.

3) I did look at unprocessed_raw and it does give a linear output. However, it returns images before demosaicing, which I'd prefer not to have to code in myself, since I'd assume libRAW has significantly better functionality for this than I can code. I'd rather invest time into trying to get linear output from built-in functionality than having to code demosaicing.

So, what I'd like to find out is if there is something we can do to get rid of that extra processing that happens in dcraw_emu -W, but without going as far back as unprocessed_raw.

I see, thanks. As I said

I see, thanks. As I said though, gamma is not really a problem. Even if I set gamma to 1 I do not see the linear behaviour that I'd like to get ( for just a few images), while I do get it with the DNG SDK and unprocessed_raw.

Please define "linear

Please define "linear behaviour" and maybe demonstrate with numbers over a grey step wedge what you mean.

DNGs don't have brightness. First, brightness isn't an attribute of a digital image; second, there is no such thing as standard calibration for raw.

This needs to be said, sorry.

Iliah Borg

I'm not sure what you mean,

I'm not sure what you mean, but by linear behaviour I mean that if I take images of the same identical subject with the same illumination, but with different exposure times, and then plot pixel value VS exposure time, the curve is linear (if gamma is 1). In the plot I attached to the original post you can see this behaviour.

You probably need to either

You probably need to either use unprocessed raw values or program your own (simple) postprocessing.

-- Alex Tutubalin @LibRaw LLC

Final followup: you probably

Final followup: you probably need to turn off auto-maximum detection via dcraw_emu -c 0

-- Alex Tutubalin @LibRaw LLC



dcraw_emu -W -c 0 -g 1 0

gives linear response to varying exposure time. Thanks.