Demosaicing non raw images


I have several rggb cfa images in png format. I want to demosaic them using RawTherapee. I am aware that RawTherapee only allows demosaicing of actual raw images (how anyone actually thinks that this is a good idea I can’t understand). I tried converting the images into raw using GIMP 2, XnView and Fiji. However, RT doesn’t even detect the files. I exported the images as 8, 16 and 32bit images in both RGB and grayscale. Someone also suggested to export to .tif and then to rename the files to .dng. This also didn’t work.

Any suggestions?

(Alberto) #2

If you know the format, it should be possible to hack RT and write your own decoder that will make RT recognize your “raw” files.

(Morgan Hardwood) #3

I admire how you slip a subtle insult into your request for help, very ballsy.


I am just that frustrated. I am trying to run a compairson of various debayering algorithms using user created test images. For simple algorithms that’s not a problem. I can recreate them in matlab and be done with it. Testing the more complicated ones is more problematic. And I truly can’t understand why they would disable the option to demosaic non raw images. The capability is clearly there, just locked away.

(Glenn Butcher) #5

G’MIC has a bayer2rgb tool.

(Alberto) #6

There you go

(Alan Gibson) #7

If it helps, I show some de-Bayering methods using ImageMagick on my Demosaicing page. However, these are simple methods with no cleverness about edge-detection etc.

I show the opposite, making a Bayer image from a RGB image, in Mosaicing.

The ability to do both operations is useful to those of us who play with images. In my view, any software that can de-Bayer raw files becomes more useful and allows for more experimentation if it can also de-Bayer more open file formats.

(Alberto) #8

I think having a generic tool that does “mosaicing” and generates a DNG (which is an “open” format, or at least the specs are available) is much more feasible than waiting for raw converters to implement this. Sorry to repeat it again, but if you know how your input format is encoded, and if you have the interest in doing so, it shouldn’t be hard to implement.

(Glenn Butcher) #9

So, you’re interested in comparing debayer algorithms, but you’re going to do that with someone else’s interpretation of the formalism. I’ll contend that, if the above is really your interest, you should be wanting to code all of them in Matlab yourself, from your interpretation of the authors’ formal definitions. Someone else’s codification could include various optimizations that skew your conclusions.

Your frustration is misdirected. RT, dt, and the other raw processors are built to respond to photographers with cameras, not researchers with synthetic images. G’MIC might give you a better platform to do your work, but you need to learn to love the command line and very powerful but somewhat obtuse syntax and semantics.

If you’re going to dig into the weeds, you need to learn to love the mud in which they grow…

Glenn Butcher, DCS
Former Thesis/Dissertation Committee Curmudgeon… :rofl:

(Stefan Chirila) #10

Just out of curiosity:

1. Would it be possible to unlock the feature in RT for TIFs and PNGs? (I understand why it’s locked; RT can load TIFs and JPGs and PNGs and they’d only very seldomly be actual rggb files …and the potential for a mess, especially with ignorant users is HUGE. Though for the few that could make use of this feature, perhaps an on/off switch?)

2. When working with G’MIC or Imagemagick, are all the demosaicing algorithms available that RT has?

P.S. @Whirlwind They mean well. I get you’re frustrated, as such a feature would be great, especially for people in your field. But alas, there aren’t many, and as I said above, novices could potentially really mess up a regular TIF by mistakenly enable the feature.

(Alberto) #11

it’s not about protecting novice users – that might be a legitimate reason, but that’s not the reason here. raw and non-raw images come through two distinct and disjoint paths in RT’s processing pipileline. demosaicing is only available for raw images. if you want to have it also for non-raw, you’d have to write the code (or find someone willing to do that) for connecting the two paths. that is doable, but definitely more than enabling a greyed out checkbox. that’s what I meant by ‘hacking together a decoder for your “raw” format’ earlier in the thread.

(Stefan Chirila) #12

@agriggio oh I see. So doable but the amount of effort isn’t really worth it due to lack of need. Alright :slight_smile:


@Whirlwind I am curious what your synthetic images look like. Could you provide us with an example?

(Alan Gibson) #14

ImageMagick contains no code for demosaicing. But it has more fundamental operations that can be combined to demosaic images, as I show in a link above.

My purpose behind that page was merely to explore what demosaicing entailed, rather than to build high-quality and fast methods. IM might be a reasonable platform for trialling different demosaicing methods, but a compiled language would probably be needed for decent speed.

(Glenn Butcher) #15

Okay, my previous post was probably a bit heavy-handed…

This is not a new question here, recall this thread: How to create synthetic RAW image?. And there, we regarded how hard is this challenge. @Whirlwind, in this thread you’ll find some approaches to inserting synthetic image arrays into DNG containers, but they’re not straightforward.

There’s clearly a need for this sort of thing, a ‘tiff2dng’ tool that would not only insert the image array but also set the metadata appropriately. I downloaded the Adobe DNG API today, but I won’t get a chance to do much right now, trying to put a bow on rawproc 0.7.


Sure! In this example I mosaiced the Rawtherapee logo from the front page:
OriginalRGB CFA128x128Grayscale

For my testing I use single color filled circles and crosses, both with sharp and smoothed edges.


I’ve got a some demosaicing filters I made for GMIC available for the GIMP plug-in. You can access them through Testing-> Iain Fergusson.


Thank you, they work well.

(Morgan Hardwood) #19

@Whirlwind there is something about your B&W mosaiced RT logo that pleasantly takes me right back to the 90s and laser printers…


@Whirlwind, did you end up figuring out how to demosaic your rggb cfa images? I’d like to do the same thing, but I’m very new to all of this and was wondering if I need to go deep into the source code to achieve that.