I’m exploring some of the applications of my new OpenFlexure microscope, and I’ve gotten focus-stacking images with different z-heights to work. Here’s what I have so far! These are very much starting points, and I’m probably missing some optimization steps along the way. But hey, not bad for 30 seconds of captures and 20 seconds of processing time on a modern budget laptop!
Results!
I took 40 z-stacked images of my sample, a cross section of a pine stem. Here are a couple of the unmodified images, one from the beginning, middle-ish, and end of the z range:
You can sort of see where different parts of the image are in focus for each of the above frames. One has the dark-green edge of the sample in focus, one has the finer cells on the top of the image, etc.
Here’s my composite, focus-stacked image:
Discussion
Way cool! I’ve got the whole thing in much better focus overall, and I can see lots of it at once! I notice that near the edges of the image there’s some blurring, and I suspect this is due to the spherical aberration of my objective lens. When I looked at all of my original images I noticed the edges of the image distorting a bit, and I don’t think my focus stacking software is compensating for this. As far as I know, the software is just doing some nifty Laplace transforms to figure out which parts of each frame are in-focus vs out of focus based on (assumed) Gaussian distribution blurring, and not compensating for non-ideal optics. I suppose one could fix this with fancier math, but I’m just going to get a planar 40x objective lens and try that instead. More to follow on that!
I should explicitly credit the open-source github repo focus-stack for having very easy-to-use software that made doing this much easier than I expected. Kudos!
Hardware
- OFM microscope, bare-bones with the “low cost” optics variant (re-positioned raspi camera 2 lens)
- Prepared slide of pine stem cross section
Microscope Settings
I used the “Stack and Scan” feature to capture 40 full-resolution images 50 z-steps apart. Your milage may vary with the z-step size, depending on your objective lens setup and how much Z range you want capture from your specimen.
The time to take all of my Z captures was about 30 seconds, but would be faster if I hadn’t turned up my settle time from the default.
Compute
- $500 2023 laptop running Windows 11 (nothing special, I don’t think I even used GPU acceleration).
- WSL2 running Ubuntu 24.04.1 LTS
Software
- Current OFM software running on the OFM’s raspi
- Github software under MIT license: GitHub - PetteriAimonen/focus-stack: Fast and easy focus stacking
Speed bumps
The released binaries for focus-stack are compatible with Ubuntu 20.04, but not compatible with my 24.* version. I had to build the binaries from source to run on Linux. If you’re running Windows, I suspect the released Windows binaries will do what you want. Luckily this wasn’t too hard and didn’t require any weird WSL compatibility tricks.