I use the following programs to do work involving image stacking.
The free of charge Hugin panorama stitcher uses the executable "align_image_stack" program, this program can be copied to some directory and be use as a standalone command-line program.
The free of charge ImageMagick program.
The free of charge ImageJ program
The free of charge Bioformats package for ImageJ needed to open LZH compressed TIFF files
My favorite way of removing outliers and removing the noise works as follows. I move the image files, say, im1.tif im2.tif etc. to a directory where I have put the executable "align_image_stack". There I open a command prompt and give the command:
align_image_stack -a al -C -t 0.3 -c 20 im1.tif im2.tif im3.tif im4.tif im5.tif im6.tif ...
The option -a sets the prefix, the choice "al" means that the remapped files will be al0000.tif, al0001.tif etc. The -C command will cause the remapped files to be cropped to the same size. The -t 0.3 sets the tolerance of the maximum allowed deviation of the control points the program will use for alignment, 0.3 means 0.3 pixels distance (default value is 3 if you don't give this command).
The lowercase -c command allows you to set the number of control points per sector of the image, the default value is 8, if you choose 20 you end up with hundreds of control points in total, usually this works very good. Finally you specify the files, the alignment is done in the sequence you specify (this can be important for HDR alignment, in that case you don't want to put the darkest image next to the brightest).
It can happen that the automatic alignment doesn't work well, in that case you can add the option -p test.pto. If you then start the Hugin program you can open the test.pto file and check out the control points, modify them and use the Hugin program to do alignment and remapping. In case you have a large number of files in the stack, there can be a small gradual drift in alignment and then you should use the Hugin program and add control point linking images that are far away from each other in the sequence.
The next step is to use the remapped files to remove the noise and outliers. The best way to proceed is to first normalize the images to have exactly the same exposure. The camera exposure changes in discrete steps due to changes in lighting which creates complications if we want to use the minimum and maximum to remove marginal outliers. To correctly normalize the exposures, you can transform to linear colorspace using ImageMagick. You open a command prompt and give the command:
convert al0000.tif -colorspace RGB lin0.tif
and you do that for all the files. Then you can open these files using ImageJ. If you start ImageJ, go to the plugins menu and click on the bioformats imprter, you can open the files lin0.tif, lin1.tif etc. You need to remove the alpha channel, you do that by selecting the 4th channel of each image and then in the image menu, you go to "stacks" and select "delete slice". The images will then become visible, this is due to ImageJ not handling alpha channels correctly. Then, in the Analyze menu you can select measure. Before you do that you can use the "set measurement..." to select all the items that you want to measure (mean, standard deviation modal value, median etc. etc.)
By measuring the average brightness values you can calculate by what factor you should normalize each picture. You then implement that by choosing in the "process" menu the option
"math" and then you select multiply or divide.
If you are done, you save the images (not using BioFormats but by selecting the "file" tab in the menu and hitting "save"). Then because ImageJ does not handle channels and layers correctly in this case when dealing with LZH compressed tiff images, you'll have the different channels appearing as different layers. You can easily correct for that using ImageMagick by giving the command:
convert lin0.tif -combine lin0.tif
To remove the outliers, you compute images containing the maximum and minimum gray values in the stack. To compute the maximum, you give the command:
convert lin*.tif -evaluate-sequence Max mx.tif
To compute the minimum, you give the command:
convert lin*.tif -evaluate-sequence Max mn.tif
Then, you want to compute the average of the files such that for each point in the images you are calculating the average but with leaving out the minimum and the maximum. This is equivalent to summing up all the files lin*.tif and subtracting from that mx.tif and mn.tif and then dividing the result by the number n of files minus 2. If we put 1/(n-2) = w, then the following ImageMagick command needs to be given:
convert lin*.tif mx.tif mn,.tif -poly "w,1,w,1,w,1,......-w,1,-w,1" avl.tif
So, you give each of the lin*.tif files a weight of w, while the files mx.tif and mn,tif get a weight of -w, the "1" in the command sets the power to 1, as we're not going to raise the gray values to any power here.
Finally, you need to transform av.tif back to sRGB, you do that by giving the command:
convert avl.tif -set colorspace RGB -colorspace sRGB av.tif
So, you need to first tell ImageJ that avl is a linear colorspace image and then you can tell it to convert it to sRGB and store the result in av.tif.