I'm doing a project where I need to export 3 different images from a raw file (DNG or RAF), each image with a different color (Red, Green and Blue). I'm using dcraw.c, Dave Coffin's raw photo decoder. I don't know how I can do this using this software, do you suggest other alternatives?

Best Regards

  • \$\begingroup\$ Do you have to export to three separate images directly, or can you e.g. export to a PNG or JPG and then separate the channels after? I'm not sure dcraw has options to do that; at least the version I'm running doesn't - if it does, it's a (fairly) recent addition... \$\endgroup\$
    – twalberg
    Jun 20, 2018 at 17:10
  • \$\begingroup\$ I don't think there have been any additions to dcraw for a while. It sounds like OP wants data that hasn't already been through a demosaic algorithm. \$\endgroup\$ Jun 20, 2018 at 21:04
  • \$\begingroup\$ Yeah I want images which were not been through a demosaic algorithm, I just want to get one image for each channel. But I think dcraw doesn't have this option. \$\endgroup\$ Jun 21, 2018 at 13:55

2 Answers 2


dcraw can't do this directly, but it can do something which will get you pretty close: render each pixel as a grayscale, either with unscaled pixel values with -D or scaled ones with -d. This will give you a PGM format image which will look like this (cropped and zoomed in, so each square is one pixel):

mostly raw

In this image, the bright dots happen to be the blue-filtered pixels. You can process this image in various ways to extract just those and discard the other. You'll have to, of course, decide what you want to do with the spacial discrepancy, because of course (this not being a Foveon sensor) the various colors are offset from each other. One easy approach is to just divide the whole thing in half in each direction (quartering the area).

If you want to do this in a less hacky way, try LibRaw, a C/C++ library which is in many ways the successor to dcraw. You could write a simple program to get the data you want and do whatever you want with it. That, however, is out of the scope of photography, really, and probably better on Stack Overflow.

  • \$\begingroup\$ Yes, this approach works well. I've used it extensively as a precursor to reading the resulting "image" with C++ or Matlab and then processing colors individually. They are typically arranged in a 2x2 square. \$\endgroup\$
    – doug
    Jun 21, 2018 at 2:40
  • \$\begingroup\$ Thank you for the feedback, I'll try it and later write some conclusions. \$\endgroup\$ Jun 21, 2018 at 13:52

I don't know of any raw converter (dcraw, ufraw, etc.) that will do this for you. But, if you have ImageMagick installed, you can use dcraw to create a TIFF and then just do:

convert -channel red -separate myimage.tif red.pgm

To extract all channels into separate files, you can use:

convert myimage.tif -separate myimage_%d.pgm

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.