New Demosaicing filter

I’ve added IID Demosaicing to Testing>Iain Fergusson

IID is a demosaicing algorithm that produces good colour detail and works well in the presence of chromatic aberrations. It attempts to reduce moire patterns. Noise tends to render as a maze like texture. False colours around edges will need post processing.

It does NOT include the algorithm to remove moire that I posted about a while ago. I wanted to keep things simple so I could actually get something finished and be able to share it.

I am quite pleased with the results on this difficult image.


hi @Iain, I don’t use G’MIC but would it be possible for you to upload the raw file and the output for the photo above, in order to do some pixel-peeping, please?, I think it’s interesting.

Is this the “Mine 1” sample in here? Diagonal interpolation correction artifacts with AMaZE Demosaicing - #65 by samuelchia
I meant to ask if you were developing this, it seemed to produce a nice result. If it comes to fruition, is it something that could be ported into RT do you think?

The above image is part of a set of standard test images as found here: True Color Kodak Images
I ran the GMIC bayer filter over it and then demosaiced it.

The algorithm above is closer to mine 2a in that thread. It has the addition of adding the amount colour variation to the horizontal or vertical weighting.

The other thread I mentioned was the following.

I am still playing around with various demosaicing methods and I intend to release a filter based on ‘mine1’, as mentioned above, at some stage.

I don’t have the skills to port the anything to anywhere I’m afraid. And I assume it would take a lot of work for someone else because a GMIC filter script is vastly different to lower level programming languages that will be used for RT. But if a developer’s interest is piqued it might happen. I would support any effort if they did.

Is there a filter or demosaicing method designed to fight moire in G’MIC?

I am working on a demosaicing filter that significantly reduces moire. See this thread

It’s not finished because it doesn’t work well at actual chroma boundaries yet. I will keep working on it.

GMIC has several smoothing filters which can be used on chroma channels to improve the appearance of moire.

Hi lain. I’m using GMIC 1.7.9 in GIMP. When I update the filters, your new demosaicing filter doesn’t appear.
Will it show up in the new GMIC 2.0.0?

Thank you, sir!

I am using GMIC 2.0 pre-release and it works for me, so I assume it will work for you in 2.0

1 Like

I’ve updated the filter.

I’ve added a refinement bit for improving fine luma details and reducing false colours. The downside is you may see some artefacts on chrome edges

I’ve also partially implemented moire reduction. Which looks good even though it is a simple version of the algorithm and needs a bit of improvement.


It would be great if we could have this algorithm in RawTherapee (and other software)!

@Iain could you possibly link me to the relevant code?

… and give it a good name, like astoniain or iainpress.

I created a simplified GMIC filter script to isolate the moire removal code

It’s conceptually simple and I have commented to explain most of it. Here is the overview, more details in the link.


-rgb2bayer[-1] $bayer_pattern,1 # convert greyscale raw image into RGB

# demosaic by interpolating green horizontally only
--moire_remove_horizontal[0] $bayer_pattern,1

 # demosaic by interpolating green vertically only
-moire_remove_vertical[0] $bayer_pattern

 # break images into tiles, apply a FFT, keep the minimum FFT value from one image or the other, combine tiles.
-iain_min_fft4[0,1] $2

This creates a slightly soft image with reduced moire. Then you can take the chroma data from this new image and use the luminance from whatever other demosaic you prefer. You get a little bit of chroma softness, but it beats moire.

It is possible to use the new moire reduced image to guide another demosaic which will pull out excellent fine detail from moire areas. But I have not perfected that yet.

Edit: I’ve noticed that this simplified version could be improved by better interpolation of the G-R and G-B in the horizontal and vertical demosaic step. By using the directional information from the green channel, the chroma channels can be interpolated on the diagonals first. It reduces the false colours and blockiness. Perhaps that is something for another thread.

I’m no good with names.

Following up on my [post] ([PlayRaw] High ISO Challenge - #38 by afre), IID appears to darken and flatten the image and to color balance properly only when “reduce moire” is on. Enabling “reduce moire” darkens the image even more. Maybe I am doing something wrong. Thoughts?

dcraw -r 1.59237 1 4.25538 1 -S 4149 -H 2 DSC04028.ARW

dcraw -r 1.59237 1 4.25538 1 -S 4149 -d DSC04028.ARW
gmic input -iain_iid_demosaic 0,1,1,0,0 output

dcraw -r 1.59237 1 4.25538 1 -S 4149 -d DSC04028.ARW
gmic input -iain_iid_demosaic 0,1,1,1,0 output

The was a problem with part of the refinement code which clamped the values to local minimum and maximums. I’ve removed the clamping as a workaround to the problem.

I’m not sure how long it will take for the changes to propagate through the system.