What is the best way to convert on the command line a Canon raw file (CR2) into 2 or 3 differently exposed tiffs for HDR/tonmapping?

I would like to use Apple's sips, but couldn't find anything to set an exposure parameter. So now I am interested in a solution to get differently exposed tiffs from a raw file via the command line raw converter dcraw.


2 Answers 2


If you are interested in this, I would suggest getting 'dcraw' which is a command line RAW converter. There is a Mac version for download from the site, the source code, and if you have HomeBrew installed, you can install it via 'brew install dcraw'.

The 'dcraw' program allows you to specify a variety of options including the Gamma and Exposure level settings to apply to the output file.

I've used it for this purpose before, to "convince" the HDR merge programs to make use of the information. Note it will probably take some messing around.


I use the '-b' option:

rawfile=<your raw file name>
for b in 0.25 0.50 1.00 2.00 4.00 8.00
   dcraw  -T -4 -v -w -W -b ${b} $rawfile
   mv ${rawfile}.tiff ${rawfile}-b${b}.tiff

This will create a series of TIFF images with varying levels of brightness as well as being 16bit linear Tiffs. (Gamma=1)

You can then merge these images in an HDR program to take advantage of the lightened shadows and darkened highlights.

dcraw also has a highlight recovery option:

-H [0-9]  Highlight mode (0=clip, 1=unclip, 2=blend, 3+=rebuild)

which can be applied to the raw processing.

To "assist" the HDR merge program(s), you will then also need to adjust the exposure settings in the EXIF meta embedded in the TIFF files generated. The easiest would be to change the ISO value.

So, for where b=1.0, which is the normal:

exiftool -ISO <filename where b=1.0>

This should tell you the ISO value.

For the other images, you will want to change the ISO value to reflect an effective EV change:

b8.00 = ISO * 8
b4.00 = ISO * 4
b2.00 = ISO * 2
b0.50 = ISO/2
b0.25 = ISO/4

(Someone correct me if I'm wrong on the EV/ISO values).

So let's say the ISO was 100 for b1.0:

exiftool -ISO=25 <filename where b=0.25>
exiftool -ISO=50 <filename where b=0.50>
exiftool -ISO=200 <filename where b=2.0>
exiftool -ISO=400 <filename where b=4.0>
exiftool -ISO=800 <filename where b=8.0>

This way, the images will be recognized as being part of different exposure ranges.

Note, the brightness doesn't translate directly into EV steps, but this will allow the merge program to put the images in the general ballpark of where the images would be given the change in effective brightness.

  • \$\begingroup\$ What command line option(s) do you use to adjust the exposure with dcraw? \$\endgroup\$
    – coneslayer
    Commented May 22, 2013 at 1:51
  • \$\begingroup\$ Yep, I agree dcraw is the way to go. But How? How do I get tiffs with, say, +-0EV, +1EV and -1EV? \$\endgroup\$
    – halloleo
    Commented May 22, 2013 at 8:25
  • \$\begingroup\$ More about dcraw: In the dcraw man page I cannot find an EV option. Do I have to use the -b option? But how does it translate into EV steps? \$\endgroup\$
    – halloleo
    Commented May 22, 2013 at 8:36
  • 1
    \$\begingroup\$ Updated answer with -b options as well as exiftool examples to modify the exif data so that an HDR merge program will put the images in the correct relative brightness ranges. \$\endgroup\$ Commented May 22, 2013 at 19:30
  • 1
    \$\begingroup\$ That's exactly what I wanted to know! I'll try it out. Thanks a lot! \$\endgroup\$
    – halloleo
    Commented May 23, 2013 at 14:34

I think (I'm not sure though) there is no built-in command line tools for such task. Instead, you can use third party softwares. Allow me to introduce you to very nice ImageMagick.

It is a set of cross-platform command-line tools that allow you to do a lot. It has lots of tools and also many scripts based on it are available online. They have also a forum that can help you with what you wanna achieve.

  • \$\begingroup\$ Be sure you have a look at their tutorials. ImageMagick has one drawback IMHO and that is being a little complected for a simple task like exposure compensation. \$\endgroup\$
    – Pouya
    Commented May 21, 2013 at 17:48
  • \$\begingroup\$ Under the hood ImageMagick does use dcraw for conversion from raw to tiff. However I don't know whether Imaggick's exposure compensation options of the convert command grab the hidden details of the raw file for specifically developed tiff. I guess using dcraw directly is more promising, but I don't how to get different exposures out of dcraw. \$\endgroup\$
    – halloleo
    Commented May 21, 2013 at 21:43
  • \$\begingroup\$ @halloleo Gimp also comes with set of command line tools (at least on linux. I'm not sure about mac). You may or may not find something that satisfy your needs. I'm not familiar with gimp scripts so much. You can give it a try or at least do some research on that. \$\endgroup\$
    – Pouya
    Commented May 21, 2013 at 22:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.