I’m writing a software that can help me calibrate and stack images – this technique is often used in Astronomy/Astrophotography to reduce noise and get rid of optical issues, like vignetting. I’ll start by explaining in a bit more detail:
Calibration consists of 3 files – a Bias, Dark and a Flat Field. The Bias and Dark are subtracted from the main image and then the main image is divided by the Flat Field. All these operations are pixel by pixel, as you can imagine. All of this is not a problem, I’ve programmed it and it works just fine. I open one image at a time, calibrate it and then close it. Releasing memory as I go.
However, I also need to be able to stack images i.e. average them, or take a median.
My question is, should I calibrate each image first, save it in a temporary directory and then read the each image row by row and average the result? Writing each averaged row as I proceed.
Or
Should I keep every image in memory (which can get very large), calibrate the raw pixels and then save the stacked image?
What is the best course of action in this scenario?
The pixel arrays are stored as (double*)rawPixels when I’m manipulating them.
You could also allocate space for the average/median image (the result) beforehand and calculate it as you iterate over the images. In pseudocode:
Well, not that simple, but you get the idea