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
# demosaic by interpolating green vertically only
# break images into tiles, apply a FFT, keep the minimum FFT value from one image or the other, combine tiles.
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.