Monochrome Debayer Option with Monochrome Camera


(Dan Llewellyn) #1

Hi, One of the things I do is modify cameras to become monochrome by removing the Color Filter Array (CFA) from the surface of the sensor (it takes semiconductor fabrication equipment). When choosing the Demosaicing Monochrome option, a can see a pixel pattern if I zoom in enough. I can look at the sensor under a microscope and see that there are bare photodiodes, so I shouldn’t be seeing a pixel pattern in RawTherapee. I suspect the something in the weighting of the RGB channels needs to be tweaked.


(Ingo Weyrich) #2

Can you please upload a sample raw file to e.g. filebin.net and post the link here?


(Glenn Butcher) #3

In the DPReview Photographic Science and Technology forum a few months back, it was pointed out to me that most camera manufacturers do some sort of individual channel scaling for various usually undisclosed reasons.

What you might have to do is to shoot a neutral patch of some sort, then note the differences in an image produced by, say, dcraw -D. Then, you can compensate with per-channel curves or levels, or somesuch. Edit: wait, need to think about this a bit, you’ll probably need to develop your raws with demosaic so you have some capture of the camera’s expectation for what should be R, G, and B. Anyway, food for thought, I probably shouldn’t post answers interleaved with doing household projects… :smiley:


(Dan Llewellyn) #4

Here is a link to a Debayered Nikon D800 picture

https://www.maxmax.com/downloads/BW/DSC_0050.NEF

If a debayered sensor White Balance is set to Auto, the picture looks red because the manufacturers add gain to the red channel because the red channel is less open than the blue and green. So, I set a custom WB with a white card which turns the picture mostly monochrome except that manufacturers also play with the color channels further to get a certain look - emulating different film stocks or whatever. So I also have to set camera to use Monochrome color picture style else the camera will add color that doesn’t really exist.

Some debayering programs seem to handle these converted color sensor fine, but others leave a pixelated pattern. I tried DCRAW once, but I had to figure out odd scaling values. Many years ago, Dave emailed me this comment:

“dcraw -v -d -a” looks very nice. This is equivalent
to “dcraw -v -d -r 0.956368 1 1.219102 1”


(Ingo Weyrich) #5

I made a hack to the code to test with your file and get this now. Not perfect but much better than before. Do you have sample raw files from other brands than Nikon I can use to test the code changes? If you build rt yourself, I can also post the patch so you can test.

Edit: Here’s the screenshot from roughly the same region before the changes to code:


(Dan Llewellyn) #6

That fix looks better. Here are a couple more links to a Fuji X-Pro1 converted to monochrome.

https://www.maxmax.com/LargeFiles/DSCF1816.RAF

https://www.maxmax.com/LargeFiles/DSCF1761.RAF


(Ingo Weyrich) #7

Do you compile rt yourself or do you use a packaged version of rt?


(Ingo Weyrich) #8

Here’s the cat shot before the fix:

and after the fix. For whatever reason, after fix the shot is not neutral gray, but still has less patterns:

Edit: After applying auto white balance the after fix shot is also neutral gray…


#9

You could try with a nikonhacker firmware, it removes the colour channel scaling which causes the grid pattern. Another trick is to use flat field images.


(Dan Llewellyn) #10

Do you have a patch that I could apply? What sort of code changes did you make?


(Ingo Weyrich) #11

Here’s the patch:

diff --git a/rtengine/rawimagesource.cc b/rtengine/rawimagesource.cc
index a1f15787..acc9bf87 100644
--- a/rtengine/rawimagesource.cc
+++ b/rtengine/rawimagesource.cc
@@ -597,7 +597,7 @@ void RawImageSource::transformRect (const PreviewProps &pp, int tran, int &ssx1,

 float calculate_scale_mul(float scale_mul[4], const float pre_mul_[4], const float c_white[4], const float c_black[4], bool isMono, int colors)
 {
-    if (isMono || colors == 1) {
+    if (/*isMono || */colors == 1) {
         for (int c = 0; c < 4; c++) {
             scale_mul[c] = 65535.0 / (c_white[c] - c_black[c]);
         }


(Stefan Chirila) #12

This is so cool! @dllewellyn love what you’re doing! Is it very complicated to have it done to a sensor? I take it the answer is a yes. I am wondering what the advantages are to making this modification. Off the top of my head, and without much experience in the field, I would assume that since normally in the bayer layout 4 sensor pixels (1R 2G 1B) produce the colours of 1 final jpg pixel, then taking the filters off would potentially produce an image where each pixel is a pixel …so 4x the camera’s original resolution?

Either way it’s awesome to see someone do this!


(Ilias Giarimis) #13

Advantages are

  • Around 3X greater efficiency at capturing photons
  • Up to 2X greater linear resolution … it varies from 1.05X to 2X depending on the effectiveness of the compared demosaicer … on average I’d put it at around 1.4X linear.
  • A lot less aliasing artefacts

(Dan Llewellyn) #14

Hi Stefan, with a monochorme camera, you gain spatial and contrast resolution while you lose color resolution. Most objects are mixes of RGB so while a monochrome camera does have higher resolution, it is rarely 4x. The microlenses that help concentrate light on the photodiode are also lost because they are on top of the CFA. Losing the microlenses and CFA change the frequency response of the sensor. In visible light, you gain about 2x more sensitivity. In UV light 6x, In IR light, net gain until 800nm and then net loss because the CFA becomes transparent above 800nm and you have lost the microlenses.

The biggest difference is that you see much more small contrast details.


(Stefan Chirila) #15

thank you!


(Pierre Edelman) #16

hello to everyone,
I’m a happy new client of Dan. I had my Sony A-6000 converted to BW and I get a kick out of it. However, I encounter the same grid problem “sometimes” when zooming in/enlarging some pictures, sometimes even when not enlarging.
See full frame Lady Liberty’s trees/pedestal here for instance.


This picture is my first try with RT after trying Darktable and Gimp (with Ufraw) This last one seems to work OK although the UX is hard to master.
I’m glad to have encountered RT since it looks like it gives a lot of control + you are pointing to a solution to the same problem I have.
ingo, can you explain how to apply your patch ? I am running RT packaged on Linux/Ubuntu (although not able to understand code, just daring enough to insert some in a given file). Let me know if you’d like some RAW files.


(Morgan Hardwood) #17

@pierpiotr that’s aliasing. Could you upload the raw file?

I can help you compile RT and apply the patch but I’d like to confirm whether it solves your issue first.

Use the “@” sign to get someone’s attention, e.g. @heckflosse


(Pierre Edelman) #18

Hi @Morgan_Hardwood,
Here is the RAW file. DSC00179.ARW (23.6 MB)
Thanks for your help and for the tip “@” BTW


(Ingo Weyrich) #19

Can’t reproduce. Here’s a crop of your image as it shows in rt (I raised exposure a bit, because it’s quite dark)


(Morgan Hardwood) #20

@pierpiotr I noticed that you used RawTherapee 5.2. We couldn’t reproduce the problem using RawTherapee 5.4, so try upgrading.


DSC00179.jpg.out.pp3 (10.2 KB)