Decoding RAW without Bayer interpolation to single greyscale

Dear developers,

thanks for a great RAW converter. I'm looking for one feature that might be there but hidden:

I'd like to convert all 4 color channels (RGGB) into a single image without any Bayer pattern interpolation (like "unprocessed raw" does). I'd like to use this image for sensor testing purposes, and the object is pure B&W.
In principle, one could use the unprocessed Raw and regard it as native resolution B&W file. However, since these 4 channels have different internal gains, the resulting image has a distinct pattern from the color filters. For example, the range for the Green pixels is 0-2000, while red only has 0-800. This results in an image where every red pixel is much darker than the other pixels. I'd like to adapt the gain for each color channel seperate, so in this specific case the red channel needs to be rescaled to values from 0-2400 too. A type of white balance for B&W if you will.

Now, "unprocessed raw" gives the option to adapt the gain, but this uses a single gain for all channels. Is there an option to change the gain per channel, or even better, use an "white balanced" gain?

(I'm using sony ARW files from a Nex-7.)

Thank you,

Forums: 

I was just wondering if you'd

I was just wondering if you'd had any success with this? I'm considering my options for creating multiple full-resolution, non-bayer, non-interpolation, monochrome/grayscale camera for a Raspberry Pi. I could try and remove the bayer filters from all of them, but this is trick and could easily cause damage. I'd much rather process the Raw files from the cameras (v2 8MP) to create monochrome, but with the red, green and blue scaled correctly...

Imagine scene, contains red

Imagine scene, contains red and blue surfaces (patches), shot via camera with color (bayer) filters.

Red/Blue (pixel values) ratio on red will be much higher than R/B ratio on blue patch. This is how a color camera works.

There is no way to fix it via single (per channel) gains, R/B(red) always will be higher than R/B(blue), regardless of gain used.

So, demosaic (i.e. recovering of missing color values), than RGB -> grayscale conversion looks like the only way to go.

-- Alex Tutubalin

I want to characterize my

I want to characterize my sensor. For that i need raw data but using MATLAB it give only bayer pattern pixel format. The Bayer pattern display three bands/sheets separately in one display but i need one raw image display. So, my question is choosing pixel format BayerRG16 and then displaying image in gray scale is better option?
If not then how i can i get raw images ?

The question actually was about B&W objects

Since the question was actually about black and white objects, the - otherwise correct! - caveat of images possibly having color patches in them does not apply.

The question should instead be answered with: Libraw currently does not have such a function and due to its generalistic approach never will have, yet building a solution is rather easy and straight forward: If you know that your objects are reliably black and white anyway, just shoot a gray image, read out the channel differences (i.e. the "scaling" introduced by the color filters) and re-multiply with the appropriate scales.

Mact

Since the light "colour"

Since the light "colour" uniformity is not that simple of an issue, having b/w objects doesn't guarantee the image taken is uniformly b/w.

--
Iliah Borg

Agreed

I agree - you can always get a hue introduced from lighting conditions, lens CA etc. No doubt!
Yet, the answer to the specific question really should have been "within your specific setup, you can actually skip the color interpolation / demosaicing step".
I say this because no matter how good your interpolation process (demosaic) is, it is an interpolation after all, it "guesses" (mathematically calculates) values that aren't really there. With the specific, narrow use case of shooting BW objects (ideally in controlled lighting conditions), you would most likely get a better BW result by skipping the color interpolation.
(I have done this and can say from experience that it does give you more fine detail than any RGB interpolation I have tried ;) )

Mact

IMO a good thing is to start

IMO a good thing is to start with stating the purpose. Without that, and without an estimate of the allowed error, nothing can be done. For sensor characterization having light spectrum changing across the scene is a matter of concern. Exact experimental setup and flat field are the first order of business. Before that, any discussion of the need in demosaicking is premature.With decent setup demosaicking can be skipped, but the lightness error introduced by demosaicking is typically less than 2 dE.

--
Iliah Borg

Agreed again :)

I do agree :)

Merely quoting from the 5-years-old question: " I'd like to use this image for sensor testing purposes, and the object is pure B&W." - without knowing the exact setup, the best we can do is suggest things to try. Trying out what quality you get from the "scale BW" approach I outlined only costs about 5 minutes to write and check. Trying out an alternative "convert to HSV and use the V channel" (or Lab or whatever) approach costs another 5-10 minutes. So after half an hour you know what's best :-)

No need to discuss the necessity of demosaicing at all, I just wanted to share a possible approach to the actual problem described. I fully agree that in most scenarios you will want to go RGB->Gray. However, the thread opener was talking about "sensor checking", so I feel comfortable to assume that he knows what he is doing ...

Mact

I don't see why not to check

I don't see why not to check demosaicking first. And while I appreciate your intent, no, I can't assume anything about anybody. I always prefer to know the exact goal, and to start with discussing the setup.

--
Iliah Borg