Focus stacking for photomicroscopy

A common problem with photomicrography is a section that is not totally flat so parts of it are out of the plane of sharp focus. For example here is a section with a wrinkle where a blood vessel altered the consistency of the wax and led to poor flattening of the section on the slide:microscope section with an out of focus wrinkle

When looking through the microscope we can compensate by focusing up and down, and we can do much the same with digital image processing using a “focus stack”. Here are some photos I took of the same section without moving the stage, but with a series of focus steps from furthest to nearest (I am showing every second image, to save space whilst giving you the idea… starting with image 1 above…

focus stack 3
focus stack 3
focus stack 5
focus stack 5
focus stack 7
focus stack 7
focus stack 9
focus stack 9

I have combined these images using the free (GNU License) package Combine ZP – here is the final output

Focus stack using CombineZP
Focus stack using CombineZP

Combine ZP uses a number of different algorithms to process the stacks. Depending on your starting images the stacking may be better or worse with different algorithms, or the algorithms may produce artefacts. You can get Combine ZP to try all the settings with one command – the output images will appear in a folder where you can view them and select the one that looks best. Processing may take a few minutes, but you can do something else whilst the computer does its work.

Combine ZP is windows only, but there are lots of alternatives – https://en.wikipedia.org/wiki/Focus_stacking has a list of packages for various operating systems. Photoshop has the capacity to do focus stacks, but it is expensive if you do not have it already, and I find it often has difficulties with micrographs where the contrast levels may be low. Affinity Photo can do image stacks, and is free (at the time of writing 2024) to students and staff at UniMelb. Helicon Focus is not free but is an excellent package that is very fast in stacking and easy to use. There are several free plugins for ImageJ, Enfuse is a part of the cross platform & open source Hugin package for panorama stitching and HDR merging that can give good results. Hugin also has ability to stitch together montages of micrographs to help you cope with specimens that are larger than the field of view of your objective lens.