Can a Bayer RAW file be converted to a lower-resolution RGB image without demosaicing?
Asked 9/25/2017
3 views
2 answers
0
Is there a way to process a Bayer RAW image by treating each 2×2 RGBG block as one output pixel, instead of doing normal demosaicing? Specifically, can software create a half-width/half-height image using the red, blue, and green values from each Bayer block, with no interpolation between neighboring blocks?
Originally by Photography Stack Exchange contributor. Source · Licensed CC BY-SA 4.0
Photography Stack Exchange contributor
8y ago
2 Answers
3
The command line program dcraw can almost do what you want. It does two things differently, though: it averages in both green pixels, and it also adjusts the color balance using its own internal algorithms. But, if you run it as dcraw -h -T, you get a TIFF file with just averaging and no interpolation — half-scale in both dimensions, so ¼ the overall area.
Here is the 1:1 pixel center crop from a random image from my working directory:
(Apologies for the non-level horizon — I was on a boat.)
Here's the same image using AHD interpolation, dcraw -q 3, and the scaled down by half without further interpolation:
Neither of these have any sharpening applied; feel free to try it. If you do, you'll find that if anything sharpening makes the AHD image's benefit even more clear. (As, for that matter, scaling it down with a less lossy approach.)
If you really want, it would surely be trivial to modify dcraw to skip the other green pixels, but I don't see any particular benefit.
For further reference, here's a conversion with Rawtherapee and its default "AMaZE" demosaicking algorithm, also resized to half-scale but this time with Lanczos resampling and with post-scaling sharpening added (which I may have overdone a bit looking now, but this is just meant to be a quick demo).
And as a final comparison, here's the out-of-camera JPEG (this is from a Pentax K-5ii):

(Resized and sharpened with a very quick unsharp mask, and then saved as PNG to avoid recompression artifacts.)
Originally by user1943. Source · Licensed CC BY-SA 4.0
user1943
8y ago
0
Generated from our catalog & community — verify before relying on it.
Yes. This is essentially a half-size RAW conversion rather than full demosaicing. A Bayer sensor records one red, one blue, and two green samples in each 2×2 block, and software can combine each block into one RGB output pixel at half the width and height (one quarter the total pixels).
From the answers provided, dcraw can do this with:
dcraw -h -T
That mode produces a TIFF at half-scale in each dimension and avoids the usual interpolation used in demosaicing. However, it does not simply discard one green pixel: it averages the two green samples, and it also applies its own color-balance adjustments.
So the short answer is: yes, you can get a non-interpolated half-resolution image from Bayer RAW data, but the common implementation described here uses both green pixels rather than throwing one away. According to the example in the community answer, full demosaicing with AHD still gave visibly better detail than the half-size no-interpolation result.
Recommended products
UniqueBot
AI8y ago
Your Answer
Related Questions
Can downsampling or pixel binning improve low-light image quality?
What does Photoshop’s RGB histogram show, and how is it different from luminosity?
Does a Bayer RAW file record one color value per photosite or full RGB per pixel?
Can a full-spectrum digital camera produce separate RGB and near-infrared channels from one RAW file?
Does full-resolution demosaicing still matter if I only need a small downscaled image from RAW?


