A couple of useful image blending/stacking scripts

Recently I have been working on a couple of scripts that automate the process of merging several images, to improve the visual output in different ways.

Both scripts use the batch version of photo flow and various tools from the Hugin suite to process the input images, align them, and merge back the aligned images.

The first script allows to blend several bracketed shots into a single HDR image with preserved highlights and improved shadow detail, pretty much following the philosophy of ZeroNoise.
The script takes a series of RAW images as input, and generates a photoflow .pfi file which performs the actual blending.
This script had been already introduced in this other thread:

The second script is currently geared toward astrophotography. It allows to read several images in FITS format and to combine them via median stacking to significantly reduce the noise and improve the details in the image. However, it can be easily adapted to other image formats, like RAW or TIFF.

Currently, the main limitation probably comes from the fact that the two scripts need a photoflow executable from the non-default linear_gamma branch, that is not routinely packaged.

The two scripts are available from here and here. The usage is rather simple:

  • /some_path/ExposureBlend/exposure_blend.sh *.NEF
    will process all the .NEF files in the current folder and will produce a blend.pfi file that contains the assembled HDR image to be processed with photoflow
  • /some_path/ImageStack/stack.sh *.FITS
    will process all the .FITS files in the current folder and will produce a stack.tif file containing the result of the median blending.

One interesting feature of the second script is that the median blending command can process and stack several high-resolution images without requiring a lot of RAM (only disk space for temporary files).

The bash scripts are relatively simple, and therefore I think they can be easily adapted to other situations/input files. If you are interested, just let me know and I will be more than happy to provide help and assistance!

4 Likes

Image stacking and other features of the linear gamma branch (like support for camera dcp profiles IIRC) make it very attractive. When do you plan to merge it into the main branch?

Can the FITS script be modified to handle raw files?

I have a folder with 27 raw files, that I want to open as an averaged (or median) image. Each file uses the same white balance, but they will need varying amounts of exposure compensation to allow each file to contribute an equal amount to the final blended image.

Well, actually three of the files were shot with a color correcting filter, so those three would need a different white balance, but I can put those in a separate folder.

The exif data won’t help with making automatic exposure compensation as each image was shot using a 30-second shutter speed and a constant f-stop (and same ISO, etc), but the light was fading steadily. So the best approach might be some sort of auto-stretch to fill the the histogram.

The images were shot from a tripod and don’t need aligning.

The FITS script sounds like might already be pretty close to how I’d like to process these raw files?

The stack.sh script can indeed be modified to process RAW files.

Concerning the fading light, I think it would be possible to make a two-step stacking, where the first step is used to analyse the images, compute the individual histogram and then guess the optimal exposure factor to align all histograms together. Maybe somebody knows about some documented technique to do this?

I have the three files open in geany right now. But I haven’t seen where to actually do something like change “fits/FITS” to “ARW”. Can you give a hint as to what to modify?

As far as the fading daylight goes, I’d be happy enough to adjust each layer using Exposure Comp or Levels to make the histograms more or less match. This doesn’t need to be anywhere near exact for this particular stack of raw files.

It is not so easy… tomorrow I will provide a stack_raw.sh script that is better suited for RAW stacking.
It will generate images in the camera linear colorspace, similar to the exposure_blend.sh script.
This way it will still be possible to tweak the WB and color conversion after the stacking.

I have updated the ImageStack scripts here. The compressed folder now contains a new stack_raw.sh script, that can be used for the median stacking of RAW files.

The usage is rather simple: to process a series of .ARW files

/path_to_ImageStack/stack_raw.sh *.ARW

The RAW files will be processed and saved in UniWB and linear camera colorspace, like in the case of the exposure blend script. This will give the possibility to later adjust the WB and color conversion for the median stacked result.

The script will create a stack.tif and a stack.pfi file. The first is the result of the median stacking, while the .pfi file is used to load the stack.tif file and add the WB and color conversion layers.

The script can also do an automatic equalization of the image brightness using the vig_optimize command from Hugin.

The behaviour of the script can be tuned by putting a settings.sh file in the same folder as the RAW files. For example, the following content in the settings.sh file will disable the image alignment and will enable the brightness equalization:

auto_exposure=1
do_alignment=0

Hope this helps!!!