that is it takes each four pixels RGBG ignores one of the greens and produces a single pixel from the 3(RGB), with no interpolation.

  • 3
    Yes, this algorithm clearly exists as you've just written it down. What were you wanting to use this algorithm for? – Philip Kendall Sep 25 '17 at 17:35
  • I just wanted to see the result of it, let's say I have a 20 Mp camera I get 5 Mp. What is the easiest way to code such algoritm, as a part of some software plugin like darktable, or a python script that takes the raw and produces the tiff(I'm learning python)? – Tito José Ferreira Figueiredo Sep 25 '17 at 18:38
  • Hi Tito and welcome to Photo.SE. Could you indicate what you have tried already? Did you try googling python read camera raw file for example? It's better if you do some research first and then, if things remain unclear, pose a question on the suitable StackExchange site. – Saaru Lindestøkke Sep 25 '17 at 19:03
  • 2
    dcraw runs from the command line, you can give options to output a tiff file without demosaicing. You can then easily apply your algorithm on that tiff file. – Count Iblis Sep 25 '17 at 19:05
  • 2
    You'd probably get slightly better results averaging the two green pixels in each four pixel group rather than discarding one of them. – Michael C Sep 26 '17 at 1:18

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:

dcraw -h

(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:

dcraw -q 3

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).

raw therapee

And as a final comparison, here's the out-of-camera JPEG (this is from a Pentax K-5ii): ooc resized

(Resized and sharpened with a very quick unsharp mask, and then saved as PNG to avoid recompression artifacts.)

| improve this answer | |
  • I think these two images illustrate well why we go to the trouble of demosaicing and interpolation. It's worth it both in terms of resolution and color accuracy. – Michael C Sep 26 '17 at 1:20
  • @MichaelClark there's clearly a difference in sharpness between these two examples, but I don't see any color difference between them. – Mark Ransom Sep 26 '17 at 2:19
  • Look at the yellows, reds, and oranges. There's not much in the scene, but even at the small sizes you should be able to see a significant difference in the transitions between brighter and darker tones of the same hues. – Michael C Sep 26 '17 at 2:20
  • I found your test very interesting. I found however a clear benefit on the first image (dcraw -h one). Look at the top lights, green and red, on the center big boat down the big building arc, that colour and detail are not reflected in the next 3 images. – Rafa Aug 28 '18 at 7:11

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.