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

  • 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... – twalberg Jun 20 '18 at 17:10
  • 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. – junkyardsparkle Jun 20 '18 at 21:04
  • 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. – Nuno Tavares Jun 21 '18 at 13:55

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.

  • 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. – doug Jun 21 '18 at 2:40
  • Thank you for the feedback, I'll try it and later write some conclusions. – Nuno Tavares Jun 21 '18 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

and repeat for the other channels.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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