Diagonal interpolation correction artifacts with AMaZE Demosaicing


(Luis Sanz Rodríguez) #101

Hi, and thank you all!

I have released the code here:

https://github.com/LuisSR/RCD-Demosaicing

As you can see, my C coding skills are very basic. I have added an overview in case you want to understand the different parts of the algorithm.

The same crop as above. Thanks RawConvert for the file:


(Samuel Chia) #102

Hi Luis,

I cannot tell you how overjoyed I am to read this. How do I give your post a SUPER like!

I am currently away from home which is under renovation and don’t have most of the raw files which I originally posted on hand but I do have some new ones which will exhibit similar flaws with the current AMaZE implementation. I’ll try to find them later.

The crop you show of my back lit (durain, in case anyone’s interested) tree looks unbelievable. I’m taking a look only on my phone screen but even then I see it looks better than DCB, and exhibits none of the flaws of AMaZe. That’s utterly brilliant!!


(Samuel Chia) #103

Incredible! Flawless…


(Samuel Chia) #104

Thanks owed to Ingo and Alberto for the work to implement in Raw Therapee :blush:


(Ingo Weyrich) #105

No thanks in advance please :wink:


(Luis Sanz Rodríguez) #106

Hi, @Samuelchia, and thanks for the kind comments.

To be fair, i think AMaZE is a more complete algorithm. It performs fairly well under a broad variety of scenarios. If I wanted RCD to deal with moirée and noisy images, the output will undoubtedly have some flaws in this kind of low ISO shots.

You’ll find that the RCD output is a bit smoother than most of the demosaicing methods in RAWTherapee but due to the lack of artifacts it sharpens better than most of them.


(Samuel Chia) #107

Thank you for going into the details. What you say about noise rendition concerns me as I’ve started doing a bit of astrophotography. I’ve noticed that AMaZE and DCB tend to cause noise to coalesce into 4 or 5 pixel chains in a perfect line, vertically or horizontally. Only VNG4 does not result in any such artifact and the noise looks almost perfectly random.

So I’m not sure how AMaZE is more complete than RCD, since I already think AMaZE is not complete in several ways. DCB too.

I’m attaching an ISO 800 image comparison from a Sony A7R II, crop from a night sky, processed with DCB and then again with VNG4. All other settings zeroed. (edit: VNG4 is on the left, DCB right) I don’t have the raw file on me at the moment as I’m outside. I can upload that later. As one can see, the noise from VNG4 looks very pleasant. Of note, Lightroom’s demosaicing looks almost identical to VNG4.


(Morgan Hardwood) #108

Are you aware of any open-source demosaicing algo designed to specifically mitigate moire?


(Samuel Chia) #109

One of the good test files is the one from the Canon 5DsR on DPReview of their typical studio image. The central tiny B&W text and also the etching drawing are very good stress tests for demosaicing. Not to mention the issues with noise in the shadows at base ISO.

https://www.dpreview.com/reviews/image-comparison/download-image?s3Key=9ef169a9dc1e4a639994abc63e7ff240.cr2


(Luis Sanz Rodríguez) #110

No, I’m not, but I haven’t looked for them lately. I read a few papers some time ago, but I haven’t seen any open source implementation yet. Any ideas?


(Luis Sanz Rodríguez) #111

RCD creates that kind of pattern with noise too.

VNG4 treats the two green pixels in the 2x2 Bayer CFA as separate channels. This way it avoids many artifacts, but there is an important loss of resolution.

If you are interested, I can easily fine tune RCD for high ISO images so that it keeps the noisy pixels isolated instead of creating lines between them, but I would like to keep it as a separate algorithm.


(Samuel Chia) #112

That sounds perfect! Two approaches, one for max resolution and one for making noise look pretty, whist sacrificing resolution.


(Luis Sanz Rodríguez) #113

Let me know what do you expect. Any info you can provide will be welcome, since I don’t do astrophotography myself. It would be great if you can show me samples of flaws you want to avoid, share some raws for testing purposes, etcetera.


(Pat David) #114

Didn’t @Iain do something with moire reduction not long ago?

Edit: found the thread:


#115

Yes, I tried IID briefly in one of the PlayRaws and initiated a light conversation on it.

PS That hatching pattern that @samuelchia showed has always annoyed the heck out of me. It affects me more because my aging camera produces noisy low resolution output.


(Alberto) #116

FYI, I’ve done a bare-bones (i.e. unoptimized) integration of the RCD demosaicing by @LuisSanz in RawTherapee. If you are interested, you can find it in the rcd-demosaic branch.


(Samuel Chia) #117

@LuisSanz, to add further detail and examples regarding how various demosaicing algorithms render grain structure. I’m attaching annotated crops magnified to 300% for easy quick viewing, and also the raw file. It is from a Sony A7R II at ISO 800. It was shot on a Star Adventurer tracker which I aimed blind at Polaris because I was standing next to a cliff so the tracking is not perfect. I think this astro image is a reasonably good test because there is a fair bit of noise, smooth areas where it’s easy to see any patterning artifacts, and fine star details which tend to produce a lot of false colour artifacts.

In terms of noise pattern, I like VNG4 and Adobe Camera Raw/Lightroom’s result the best. Note the bright star in the upper right. VNG4 produces a zipper artifact along that edge while Adobe does not, bearing in mind that the Adobe algorithm is prone to severe zipper artifacts as demonstrated in the earliest examples. In this case it did not trigger with Adobe but in VNG4 we see it. I find VNG4 to be very prone to this kind of zipper artifacts too.

The Raw Pedia page recommends LMMSE or IGV for noisy images, which I find to be a poor recommendation. They both enhance the noise contrast more than VNG4 does, and perhaps the color artifact suppression is a bit strong and robs away some star colors. There are also random 45 degree diagonal artifacts usually of three or four pixels in length where the pixels are too dark in smooth (!) areas, which is something I’ve not seen before. Sometimes it is two adjacent pixels, or two adjacent pixels separated by a lighter middle pixel.

AMaZE has slightly less of the mazing pattern in the noise, DCB has a little more and AHD has the most. These patterns are impossible to remove with typical noise reduction tools in the raw converter or third party apps like Topaz Denoise. @afre, I feel your pain. AMaZE tends to pick up and increase the contrast of a random pixel here and there a bit too much making it too dark, while DCB’s micro contrast is smoother (i.e. less standard deviation of brightness of pixels in the dark star-less sky areas which is not featured in this crop illustration).

VNG4 produces a lot of green fringing false color halos around the stars. Adobe color fringing errors tend towards red/magenta. LMMSE produces even less false color, and IGV has the lease false color and color noise is strongly suppressed, but star colors seem to be destroyed also. DCB seems to produce the better balance of false color/color fringing artifacts, followed closely by AMaZE, but one can find stars where either one produces a better result.

Overall it’s close between Adobe and VNG4 when it comes to dealing with noisy data. The Adobe result has less zipper artifacts in the high contrast stars, eliminates hot pixels slightly better and generally has less objectionable color fringing artifacts. The VNG4’s green halos on high contrast edges (stars) I find to be objectionable, which is not removed by the false color artifacts suppression slider, but can be dealt with using the Defringe tool. VNG4 produces better star shapes in some of the smaller, fainter stars, which I appreciate.

If RCD is able to avoid the color artifacts better, and incorporate VNG4’s method of treating the green channel pixels as separate etc. etc, I think we may have a winner.

VNG4 does rob quite a bit of resolution away, so my current favourite technique is to render the image twice, once with DCB and once again in VNG4, and mask out the stars which will come from the DCB image, and the smooth low contrast areas will be from VNG4. I agree that a modification to RCD to handle noise patterns better should be kept separate, the loss of resolution and detail is pretty significant. I’d much rather have the final control of manually blending the two together for best results.


_DSC4132.ARW (81.6 MB)


#118

A compiled test version for Windows (x64. Gtk3.22.26) can be downloaded from here:
https://filebin.net/x6uf72a6r1on1roj

No installer included. Extract the folder “RawTherapee_rcd-demosaic” to e.g. your Desktop and run “rawtherapee.exe” inside this folder.
Cache and settings are saved into “%localappdata%\RawTherapee-rcd-demosaic”. It leaves your existing installation untouched.


(Samuel Chia) #119

Big thanks to @agriggio for adding the code @TooWaBoo for the complied test version!

So I was able to repeat the test on the durain tree raw image. This illustration shows AMaZE, DCB (current best overall choice), RCD and VNG4. I did LMMSE and IGV but both were pretty awful compared to VNG4, removing color in fine details and resulted more noise than VNG4.

The first row is a straight raw conversion with a camera profile with a single point brightening tone curve with input 50% and output 75%. All other settings zeroed, no sharpening, no noise reduction, no false color suppression. As the differences appear very subtle, the second row has unsharp masking of 500% and radius 0.3 applied to exaggerate the differences to make evaluations easier on the eye. These are 100% magnification crops, upsampled to 300% with Nearest Neighbour interpolation. Please note that I do not apply this kind of sharpening for regular, normal editing.

The first most interesting observation is that RCD has the smoothest rendition of noise, even smoother than VNG4, which until now had the best noise rendition, and only in certain areas does the hatching pattern become visible. I was not expecting this! If a modification could be made to remove the hatching pattern, this could be the best result ever for noisy images.

RCD also has the least false color issues overall, by a very significant margin compared to AMaZE and DCB. Outstanding.

The diagonal zipper artifacts is greatly suppressed in RCD compared to AMaZE, but they are still present, and I see ringing artifacts still present. RCD also suffers from more mazing artifacts than AMaZE (see some of the leaves in the lower region). However, any artifact usually has far lower contrast than AMaZE so more real-world sharpening routines will probably not cause them to become too obvious, or probably not even at all.

DCB has no ringing artifacts and no mazing artifacts, only the occasional too-dark random pixel. Other than the false colors, which can be mostly avoided with two steps of false color suppression, I still think DCB overall provides a more artifact-free, natural looking result, albeit with slightly less ultra fine detail which loss is not visible at 100% magification, and certainly not even in the best prints possible today.

I really like RCD. If the diagonal zipper and ringing artifacts could be brought down to DCB levels, it could be the best demosaicing I’ve ever seen.


(Luis Sanz Rodríguez) #120

Hi! Thanks @agriggio for merging the code into a new branch and @samuelchia for the testing. I believe there is a small bug somewhere in the implementation, since the code in RT creates zipper artifacts in the diagonals as Samuel noted.

Note in this sample that in the ouptut I’m getting from dcraw the straight lines and the edges are rendered smoother than in RawTherapee. I’ll have a look to the code to see if I can find the cause for the divergence.

dsc_7738_rcd-dcraw_res