Mean/Median Stack of multiple dark frames before demosaicing.

Hello, I would like to see if anyone has any idea of how to median stack raw files before demosaicing, and render a file, preferably higher in bit depth, yet read like the original file by Rawtherapee or any other raw processor.

To explain the intended use, I have a camera, the Blackmagic Pocket Cinema Camera, that have a mix of fixed pattern noise (line noise and amp glow) as well as random noise in the deep shadows. I know Rawtherapee has a dark frame noise subtraction feature, and know how to use it, but it is more useful for hot pixels for low ISO long exposure than high ISO with fixed pattern noise. This is because if there is enough random noise that if I were to use a single dark frame, it would cancel out the fixed pattern noise, but increase the variance of the random noise, thereby making the signal to noise ratio poorer. The solution to this is to mean/median the dark frames, but if the subtraction is done after the raw develop, then it potentially raises issues with the log transform, color matrix and other non-linearities that make the subtraction less accurate. Higher bit depth might be needed, as the extreme shadows information that I am trying to make use of is likely between the steps of the linear 12 bit file, but is dithered by the random noise, but I am not sure this will be 100% needed.

1 Like

Dark frames are applied before demosaic in RT

Upon posting this, I realized that this will probably be better posted in the processing general forum, but don’t have permission to delete it, so if you are a mod, feel free to delete it, I already copied and pasted into the general processing forum, but I am fine with it staying up if you guys are as well.

I mean median stack before dark frame being applied, for the above reasoning.

The pipeline I am trying to figure out is from start to finish, median of dark frames, render to new raw file, , subtract pre-stacked stacked dark frame raw file from the light frame file, then finally demosaic and process.

From http://rawpedia.rawtherapee.com/Dark-Frame

Under the widget, RT shows how many shots are found and how many groups of shots are found and averaged into a template

Thanks, guess I should have read the wiki, and sounds like something that would work for most instances.

There are times when it would be better to create a new raw file, for processing speed when there are 5-10 dark frames to load each times, and thousands of light frames to render in the case of raw video, so I am curious if there is some way to pre-median and create a new raw file.

Have you considered one of the astro tools like Deep Sky Stacker?

Good call, I will take this question to an astrophotography forum.

Yes, it took me a few minutes re-reading your original post, thinking, “sounds familiar, somehow”, then it became clear: the astro folk do this sort of thing regularly, building exposures from multiple long exposures of dim light, all stacked with “darks” and “flats” exposures to take care of the same statistical bias you’re describing.

Note: I haven’t used any of this stuff, yet…

Anyone else who is also curious about this question can look at this post I made at Cloudy Nights, and see the insights experienced astrophotographers have on this.

Looks like I found a solution.

Kandao Raw+

I tried it, and it legit spits out an undemosaiced noise reduced raw stack file that I was able to successfully use for removing amp glow in the BMPCC without adding more random noise.
Success!

Warning: I’m 90% certain Kandao’s RAW+ does a tile-based align-and-merge similar to Google’s HDR+ algorithm, which may cause unusual artifacts.

You want a straight mean/median stacking approach that does NOT do any sort of alignment - siril can do this. (In your use case, you’d want to treat the dark frames as being normal frames, since you want to feed the preprocessed darkframe to RT). However since it’s highly astronomy-focused it spits out a FITS file as output, which you then need to convert to DNG. You can use imagemagick’s convert command to create a 16-bit linear TIFF, rename to DNG, and use exiftool to add the appropriate metadata. I posted an example exiftool command in another thread here a few months ago, I’ll try and dig up the thread.

2 Likes

“You want a straight mean/median stacking approach that does NOT do any sort of alignment”

Well, I was aware that that was the ideal.

I tried out Kandao Raw+, knowing full well it might have issues because of the align-merge function, and ran some experiments, and the file it spit out did work to remove the amp glow and some of the hot pixels, so I kind of guess it defaults to no alignment when fed dark frames.

Nonetheless this is the ideal solution that I have been looking for for YEARS! Thank you so much!

“siril can do this. (In your use case, you’d want to treat the dark frames as being normal frames, since you want to feed the preprocessed darkframe to RT). However since it’s highly astronomy-focused it spits out a FITS file as output, which you then need to convert to DNG. You can use imagemagick’s convert command to create a 16-bit linear TIFF, rename to DNG, and use exiftool to add the appropriate metadata. I posted an example exiftool command in another thread here a few months ago, I’ll try and dig up the thread.”

1 Like

Still need to dig up my tagging approach, but https://github.com/ifb/makeDNG might be slightly less painful if you change the parameters to match your camera as far as converting from FITS back to DNG after processing in siril

1 Like

Thanks, I did successfully use Imagemagick to convert the fits file into a DNG, but couldn’t figure out how to even get exiftool running and doing commands on metadata, using Windows.

On further inspection, I realized that the output of Kandao Raw+ successfully removes amp current, but the complex AI stacking algorithm messes with the hot pixels.

I wil also give Makedng a go.

BTW, I did find the exiftool based flow I use often - Loading .raw images (from industrial cameras)

Note that your ColorMatrix will definitely be different (although for darkframe stacking it may likely not matter as I would assume RT will ignore the ColorMatrix metadata if it’s being used as a dark frame)

1 Like

I noticed that in your exiftool script the black level had four numerical entries presumingly for each channel of the bayer matrix, but in the metadata for a real BMPCC raw file, there was only one entry for the black levels. Which should I go by?

Ok, so I went with the four value black level, inputting the value found in the metadata for the real camera raw file. When I did the dark frame subtraction, I noticed that the result was clipped black until I applied negative raw blackpoint compensation in Rawtherapee at a value of -500. However, after application, it looks like the hot pixels and amp current were fixed.

Is this behavior an inevitable result of subtracting a darkframe with a raised noise floor, or does this mean I need to fiddle with the black point setting in Exiftool a bit more? The fact that this blackpoint compensation is needed when subtracting another camera original raw file suggests that it is inherent to the dark frame subtraction, and the metadata settings I inserted were correct, and changing the black point in Rawtherapee after the subtraction is the correct workflow. What are your thoughts?

Hmm, I’m not sure on this one, as I’ve never used the darkframe subtraction before.

There might be a corner case/bug that occurs if a non-DNG raw file is used with a DNG darkframe, not sure. What happens if you use a single original raw file?

1 Like