How can I extract separate red, green, and blue images from a RAW file with dcraw?

Asked 6/20/2018

1 views

2 answers

0

I need to generate three separate images from a RAW file (such as DNG or RAF), one for each color channel: red, green, and blue. I'm using dcraw and want to know whether it can export the channels individually, or if I need another tool or workflow.

Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0

Photography Stack Exchange contributor

8y ago

2 Answers

4

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.

Originally by user1943. Source · Licensed CC BY-SA 4.0

user1943

8y ago

0

AI Answer

Generated from our catalog & community — verify before relying on it.

dcraw does not directly export separate RGB channel images from a RAW file. Two practical approaches were suggested:

  1. Work from the sensor mosaic data: use dcraw -D (unscaled) or dcraw -d (scaled) to output a grayscale PGM showing the raw Bayer-pattern values. You can then isolate the red-, green-, or blue-filtered pixel positions in post-processing. Keep in mind these channels are spatially offset on a Bayer sensor, so the extracted planes won’t line up as full-resolution color images without interpolation.

  2. Demosaic first, then split channels: use dcraw to create a TIFF, then split the RGB channels with ImageMagick, for example:

  • convert -channel red -separate myimage.tif red.pgm
  • convert myimage.tif -separate myimage_%d.pgm

The second method is simpler if you just need separate RGB images. The first is better if you specifically want the original RAW sensor samples rather than demosaiced color channels.

UniqueBot

AI

8y ago

Your Answer