2
\$\begingroup\$

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.

\$\endgroup\$
9
  • 3
    \$\begingroup\$ Yes, this algorithm clearly exists as you've just written it down. What were you wanting to use this algorithm for? \$\endgroup\$
    – Philip Kendall
    Sep 25, 2017 at 17:35
  • \$\begingroup\$ 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)? \$\endgroup\$ Sep 25, 2017 at 18:38
  • \$\begingroup\$ 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. \$\endgroup\$ Sep 25, 2017 at 19:03
  • 2
    \$\begingroup\$ 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. \$\endgroup\$ Sep 25, 2017 at 19:05
  • 2
    \$\begingroup\$ You'd probably get slightly better results averaging the two green pixels in each four pixel group rather than discarding one of them. \$\endgroup\$
    – Michael C
    Sep 26, 2017 at 1:18

1 Answer 1

3
\$\begingroup\$

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

\$\endgroup\$
4
  • \$\begingroup\$ 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. \$\endgroup\$
    – Michael C
    Sep 26, 2017 at 1:20
  • \$\begingroup\$ @MichaelClark there's clearly a difference in sharpness between these two examples, but I don't see any color difference between them. \$\endgroup\$ Sep 26, 2017 at 2:19
  • \$\begingroup\$ 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. \$\endgroup\$
    – Michael C
    Sep 26, 2017 at 2:20
  • \$\begingroup\$ 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. \$\endgroup\$
    – Rafa
    Aug 28, 2018 at 7:11

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.