Demosaicing /debayering in Rawtherapee by downsampling

Hello, there is a dcraw-option: “-h” . It debayers by downsampling. Can i use this in rawtherapee? Thanks and Regards Christian

No, RawTherapee does not support this option.

Both RawTherapee and darktable allow to output to disk non-demosaiced images, that you can then use various algorithms to resize to half the original image size. I did some experimenting with this procedure just to see what would happen. This image is one of the results - I think I used darktable for this particular image, and resized it using GIMP-2.10’s “linear” scaling algorithm:

knotweed
Photograph of Japanese Knotweed, with Everlasting Peavine (the pink flower) growing over it - both species invasive in North America.

2 Likes

The dcraw -h option is pretty crude because it leaves the image with uniform lateral chromatic aberration in a diagonal direction.

It’s best to demosaic and then downsample.

Thank you

Hello Elle, thanks for your advice. I will try it out :slight_smile:
Regards Christian

Hi @motavian - there are two different types of options in RT/dt: not doing any demosaicing at all, and the “mono” option which is technically for cameras that don’t have bayer filters.

I was exploring what RT and dt offer mostly from idle curiosity, in connection with the idea of possibly eventually maybe (not going to happen) having the bayer filter removed from my camera, and also as possibly an alternative way to denoise very noisy images from not enough light reaching the sensor.

Results do depend on the down-scaling algorithm, for example using “none” in GIMP seems to just literally rewrites the file leaving out every other pixel, which does produce all kinds of artifacts - maybe dcraw -h does something like this?

Not demosaicing the image also does affect resulting color. For example in my “Japanese knotweed” image, the pink Everlasting pea blossoms stand out very nicely when using the “non-demosaic and then resize” approach, much more clearly than when using normal demosaicing, which for this image was a decided advantage.

Anyway, @CarVac 's advice is of course correct, normally it’s best to use proper demosaicing. Though after testing and including the down-sizing, I really didn’t see a lot of difference in the final images for the two images I was working with, except for the nice color emphasis for the everlasting pea blossom.

So may I ask - feel free to not answer! - what are your motivations for wanting to output non-demosaiced but resized images?

Also, if you do any experimenting, I’d be curious to see results. I’d post my other sample image but I totally don’t remember the steps I followed, though it did end up being nicely denoised.

1 Like

Hello Elle, i like genuine results (i hope “ginuine” is the right word for what i mean). I also collected a lot of digital music in form of cds or lossless downloads (no mp3 etc.). I think, today we have enough digital memory to renounce of any calculations to save space. And every process / calculation makes the sound or picture more artificial. That is the origin of my motivation. I bought my camera and was happy to get pictures in a quite direct way without processing or calculating by using the digital negative or so called “raw-format”. Then i found out, that today most cameras (even the big ones for professionals) have the bayer-matrix. But from the bayer-matrix i just get a full resolution picture only then, when i use interpolation. This brings it near to jpeg with its sub-sampling procedures just like 4:2:0 in video-compression :confused: But there is a chance: Make out of the pixels new superpixels (2x2 → RGGB) und reduce the resolution. Than i have what i expected at the beginning, But just a quarter of pixels. I saw the results by using debayering-method “VNG4”. Quite good. So i don’t know if i want to downsample all my pictures for good. Maybe it is just for playing a little. But maybe sometimes there will be a foto which benefits from debayering by downsampling". Just downsampling is not enough. I have to do something with the green-channel. Because i have two green dots. Regards Christian

@motavian I get a feeling that you believe that RAW files do not give you all the information you expect to obtain from the camera’s sensor. But similar to the way that digital audio is recorded with a finite sampling frequency (44.1 kHz, 192 kHz, etc.), there are finite limits to the information you can acquire with a camera sensor. I suggest you read this excellent introduction to sensor design.
You will see that the Bayer matrix is one of a few ways to obtain color information, and that demosaicing is essential to obtain reasonable RGB pixel values.
I can assure you that you do not need to lose any pixels, and that interpolation is actually better than just downsampling your RAW file.

Ooh, Oooh! Teacher! Call on me!! :smile:

@Elle, I’ve been thinking through this very thing, with the following context: My present camera is a D7000, which measures a usable image of 4948 x 3280 pixels. Just about all of my output for either computer display or printing requires nowhere near that size of image; in fact, I’m currently batch-processing my raws to 800x600 proofs, and that’s usually as far as my processing goes.

In the next version of rawproc, there will be a demosaic tool, but my original intent for it was to use in a raw processing tutorial. So, I dug out the simplest demosaic algorithm there is to just get it going, the so-called ‘half’ algorithm. For those reading along, ‘half’ just takes each RGGB quad of pixels and turns them into a single RGB pixel, using the average of the two Gs for the G (Hmm, starting to sound like a military document, too many acronyms…). That makes my 4948 x 3280 image a 2474 x 1640 image, which gets me a little more than halfway to 800 x 600 without the statistical nastiness of the interpolation resize algorithms. Yay.

So now I’m thinking along the lines @motavian is cogitating, I think…

I will admit I haven’t inspected a great number of my half-processed images to really assess the difference to, say, AHD.

Oh, in my previous post, I didn’t articulate another advantage to ‘half’, that being speed. My batch processing of proofs drops from about 12sec per image to 4sec per, with ‘half’… I don’t use intermediate TIFFs or such, I start from the raw every time so I have the opportunity to change the demosaic algorithm with each processing session.

In case you only need small(er) sized pictures, this may be a valid approach of course!

I still want to consider what @CarVac said about chromatic abberation. Otherwise, I’m going to incorporate it in my proof processing. I went camping with my son this weekend, shot a bunch of images in a rather beautiful fall-colored Saturday morning. I didn’t batch-process in the field, but if I had I would have appreciated the shorter up-time on my tablet, as we had no power for recharging…

Deepskystacker optionally does dcraw -h. They call it superpixel.
I find the easiest way to get the effect of dcraw -h is to compile dcraw.c and use dcraw -h -T -4.

yes, when you are sampling music, you are loosing information. That is, what i would accept. I just want to avoid adding pseudo-information by a machine. But that is, what regular debayering does.

“Superpixel” and less noise and possibly nicer colors (for example the pink peavine flowers) were all reasons why I was experimenting with outputting non-demosaiced raw files and resizing them. Today’s cameras do output very large images and very often one doesn’t need that large of a final image.

Speed of processing to one side, has anyone compared results of “dcraw -h” with outputting the whole non-demosaiced image and resizing using various scaling algorithms?

Oh, if it’s relevant - I think it might be if the goal is to extract as much quality image information as possible - I shot the Japanese knotweed image through a magenta filter in an attempt to even out the amount of light reaching the pixels covered by the red and blue filters vs the pixels covered by the green filters on the bayer array.

Considering that the non-demosaiced data is somehow more ‘pure’ than demosaiced data is simply false. For every pixel on the sensor, there is always some light leaking onto the neighbouring pixels and there is always some aliasing going on. These effects can actually be remedied during demosaicing.

2 Likes

I have played with raw data exported by dcraw's document mode and I would say that down sampling raw data reduces the amount of detail that could otherwise be achieved by demosaicing. Sure, algorithms introduce artifacts and other problems but that goes away as the resolution of cameras increase (or better algorithms are discovered :slight_smile:). (I have an ancient camera by this forum’s standards, so I have to contend with less than ideal raws.)

I don’t think the audio analogy is an apt comparison. I would liken demosaicing to making a cookie. A completed cookie tastes better than the sum of its parts. :cookie::yum: However, you could technically eat it at any point of the process. I guess I am hungry for a late night snack. :blush:

Where was I…

The raw file is stored the way it is because that is what the sensor and electronics output. Of course, it isn’t the direct output; there is much more going on in the black box that is our cameras, unless you are in the business of knowing that stuff. We know why manufacturers give us access to raw files though. It is so that tinkers like us can do PlayRaws. :rofl: Or we disagree with the appearance in-camera generated JPGs. Or it is that these JPGs were optimized for speed and not for quality, etc.

1 Like

Thank you

Good afternoon! I came to the forum to suggest this method, but I see that I’m not the only one who thought about it. If this has any weight, I would also be happy to see this algorithm in the RT list. In my photo processing process, I eventually bring the final image to a resolution of ~4-5 megapixels, despite the fact that my cameras have 16 and 20 megapixels. Perhaps such an algorithm will avoid some intermediate processes of the demosaic with a subsequent reduction in size, I assume this will also minimize the need to sharpen and give a more accurate color by default. In addition, with a lower resolution, the load on the processor will decrease when using other tools and filters. I think that this is especially important with the advent of more and more megapixel cameras and the spread of pixel shift technology. Thanks!