Active focus stabilization for fluorescence microscopy by tracking actively generated infrared spots

Keeping a sample in focus remains a challenging, yet important, task in optical microscopy. Even a minimal discrepancy in Z-position can cause severe disturbances for time-lapse, scanning or TIRF-based experiments. Focus drift can arise from a range of sources, such as vibrations, mechanical instabilities, samples that are not flat or thermal fluctuations of the microscope’s components. Various techniques and systems have been proposed to address or circumvent these problems. They can be divided into two major categories: active and passive methods. Active methods accept that there is drift and compensate it using a control loop. Image-based methods [1, 2] rely on complex software that analyzes images and compares them with in-focus images captured beforehand. Sensor-based methods use additional sensing circuits to detect drift. Passive methods use optical components [3, 4] to monitor the sample-objective distance and include a range of mechanic practicalities, from using a weight to push down the sample to avoiding a perturbing airflow over the system. Optical z-drift correction systems use an infrared light source that is reflected on the cover glass-sample interface and captured by a detector. These detectors range from quadrant detectors [5] to cameras (e.g. Leica’s Adaptive Focus Control) and line sensors (e.g. Nikon’s Perfect Focus System). In these systems, a spatial disturbance between the sample and objective influences the position of the reflected light, which is then mitigated by moving the sample or objective towards the desired focus position. These systems are rapidly becoming standard equipment on new motorized microscopes, though may be more challenging to engineer in existing systems. In this paper we present a z-drift correction system that was implemented both on a popular commercial microscope body (Olympus IX-71) and on a bespoke modular microscope system, though which should also be compatible with systems from other manufacturers.


Introduction
Keeping a sample in focus remains a challenging, yet important, task in optical microscopy. Even a minimal discrepancy in Z-position can cause severe disturbances for time-lapse, scanning or TIRF-based experiments. Focus drift can arise from a range of sources, such as vibrations, mechanical instabilities, samples that are not flat or thermal fluctuations of the microscope's components.
Various techniques and systems have been proposed to address or circumvent these problems. They can be divided into two major categories: active and passive methods. Active methods accept that there is drift and compensate it using a control loop. Image-based methods [1,2] rely on complex software that analyzes images and compares them with in-focus images captured beforehand. Sensor-based methods use additional sensing circuits to detect drift. Passive methods use optical components [3,4] to monitor the sample-objective distance and include a range of mechanic practicalities, from using a weight to push down the sample to avoiding a perturbing airflow over the system.
Optical z-drift correction systems use an infrared light source that is reflected on the cover glass-sample interface and captured by a detector. These detectors range from quadrant detectors [5] to cameras (e.g. Leica's Adaptive Focus Control) and line sensors (e.g. Nikon's Perfect Focus System). In these systems, a spatial disturbance between the sample and objective influences the position of the reflected light, which is then mitigated by moving the sample or objective towards the desired focus position. These systems are rapidly becoming standard equipment on new motorized microscopes, though may be more challenging to engineer in existing systems.
In this paper we present a z-drift correction system that was implemented both on a popular commercial microscope body (Olympus IX-71) and on a bespoke modular microscope system, though which should also be compatible with systems from other manufacturers. Figure 1 shows the concept of our automated out-of-focus system, which is based on the in-situ real-time focus detection method of Binh et al. [6]. The main idea is to illuminate the sample with two light beams that are reflected from the glass surface carrying the sample, and to relate the relative motion of these beams to the sample position. We obtain these two beams by passing collimated infrared laser light through a double-hole mask. The beams are sent into the microscope body, onto the sample, where they will reflect on the coverslip, or any other glass-other refractive index surface. As sample and glass surface are close enough together and move more or less in unison, there's no drawback to this. The reflected beams are captured by an industrial CMOS camera.

Concept
The horizontal distance between the detected spots is proportional to the z-position of the cover glass. The control software then adjusts the stage position to regain focus by restoring the distance between both spots. Our software determines the positions of the reflected spots by simply calculating the 'center of mass' of each spot (after initial filtering to avoid artifacts, see below). Moreover, our system is designed to eliminate any residual light originating from reflections in the beam path.
In regular correction techniques that employ a single infrared beam that is detected by a quadrant detector, the shape of the spot is of the utmost importance. Any distortions (also not focus-drift related) of this beam profile will directly result in a focusing error as the center-of-mass algorithm is largely influenced by imperfections at the border of the spot. Our technique, with the double-hole mask, will result in a smaller misconception of the z-postion, as long as the disturbance influences both beams in a similar way.

Description of the System
We provide a full description of the setup components and alignment procedure. This setup is developed with the eye on being compact and straight-forward to construct and use. We also provide software for automatically detecting and correcting z-drift, including a user-friendly GUI. Figure 2 gives a schematic overview of the hardware that is used to construct the autofocus system.

Setup
The light source is a 3.0 mW, 830 nm infrared laser with an elliptical beam profile, mounted in a pitch/yaw adaptor for tilting the laser on two axes. This wavelength is chosen to avoid the color channels used for fluorescence detection. The double-hole mask is positioned in a rotation mount to tilt the laser in the long axis of the elliptical beam. These holes are 600 μm apart and 500 μm wide. Figure 3 shows this mask and its dimensions.
Two mirrors M1 and M2 can flexibly position the two beams, so that they can be guided towards the objectivesample interface. Component ND1 is a neutral density filter that reduces the power of the laser to less than 1 mW (safety category 2), while still retaining a clear signal on the detector. Lenses L1 and L2 both have a focal A 50/50 beam splitter passes the light coming from the laser into the direction of the microscope. The two beams will be reflected on the glass-other refractive coverslip that holds the specimen. Upon reflection, the light is send back towards the 50/50 beam splitter. This light is then split again, this time with the aim to detect the two beams on a camera.
As the infrared laser provides a reasonably coherent source, pattering artifacts can arise in this process due to interference. However, as these occur at rather high spatial frequency, they can easily be filtered in postprocessing. Component ND2 is a laser line filter in order to compensate for imperfections in the beam splitter (e.g. low-intensity secondary laser lines) and D1 and to filter out ambient light, that may come from the fluorescence path.
An extended version of the system is shown in the red dashed frame in Figure 2. This extension is required if extra reflections occur on the camera that might disturb or overwrite the spots to be measured. These reflections may originates from several sources: imperfections in optical components (beam splitter, dichroics), infrared light reflected off of lenses shared with the fluorescence path.
Mirror M3 is used to center the beams on the iris, to maximally filter out light noise. Lenses L3 and L4 both have a focal length of 50.0 mm and are in a 4f configuration. The spatial filter is placed in the (back)focal plane of the two lenses and is the primary component for eliminating reflections. Lens L5 focusses the two parallel infrared laser beams on the IDS camera window. The distance between this imaging lens and the sensor chip of the IDS camera influences the shape of the spots and the distance between them. Figure 4a shows the graphical user interface (GUI) of the software, and Figure 4b shows the actual spots on the camera window.  The Focus tracking window offers two functionalities: (de)activating the camera, and (de)activating the focus tracking algorithm. The current distance between the two spots on the camera is defined as Current position (in pixels). The ideal z-position of the stage (i.e. when in focus) is defined as Focus position. When focus tracking is enabled with the Track focus button, the software aims at keeping the distance between the detected spots constant. It adapts to reach this state by moving the stage or objective up and down when the sample is drifting.

Software: GUI
The Settings window allows the user to set Exposure time, Min.deviation and Step size. Depending on the intensity of the reflecting laser beams, the exposure time can be set as desired with the Exposure time button. The exposure time also determines the speed at which the autofocus system can detect and correct disturbances in the relative position of the spots.
The Min.deviation button refers to the least difference (in pixels) there should be between the current position and the focus position in order for the stage or objective to move. The Step size button represents the relation of the z-position of the stage and the distance between the spots on the IDS camera. If the distance between the lobes changes with 1 pixel, the stage will move (focus pos − aim) * step size µm. This step size changes depending on the magnification of the objective and lenses that are used in the system. The higher the magnification, the smaller the working distance and focus depth.
Since the user can set these parameters as desired, it is easy to adapt the software to work for different samples, objectives or microscopes.
The Stages window has the absolute positions of the stage in the x-, y-and z-direction. It also provide buttons to move the stage up and down. The Calibrate button sets the absolute x-, y-and z-value to zero. This button should be used as a calibration step before finding the correct focus position. It allows the user to set a neutral position, where the objective is relatively far away from the camera but the spots are clearly visible. When the system is not able to find its focus back within a reasonable time, it returns to this position to start correcting the stage.
The autofocus system is compatible with different hardware components. Currently, we support IDS cameras for spot detection but others can be easily added. Moreover, we can control anything that is used through Micromanager but also different kinds of stages, as long as they are motorized.

Results
We validated our z-drift correction system by visualising the mitigation of temperature-dependent drift on a fluorescence microscope. As a sample we used sparcely disperced 200 nm Tetraspeck beads. The microscope itself consists of: an Olympus IX71 inverted microscope body, Hamamatsu ORCA-Flash4.0 LT+ Digital CMOS camera, Spectra X light engine (Lumencor), a dichroic turret wheel mounting a Chroma ZT561RDC dichroic filter with a Chroma HQ572lp emission filter. This microscope supports a wide range of objective lenses. We use an UMPlanFI 50× objective, with a numerical aperture of 0,80 and a working distance of 0,66 mm. We have 542 nm illumination light at a power of 50%; the exposure time is 0,1s.
We will visualize z-drift as a result of a change in temperature. For this purpose, we use a time lapse experiment, imaging every second, while the temperature is varied between 32°C and 45°C using the Okolab H301-T-UNIT-BL-PLUS stage top incubator.
When the autofocus sytem is activated, we first have to determine the focus position, find good spots and set the step size correctly for the microscope and the objective. For this, we take a z-stack of images ( Figure 6) to relate the number of pixels with the deviation in z-position of the stage.
We use a step size of 0,1 µm/pixel. The minimal deviation is set to 2 pixels. As Figure 5 shows, the sample clearly moves out of focus when the temperature is changing. With our system, the focus position is recovered by adapting the stage. During the experiment, also xy-drift occuers, for which our system does not compensate.
Similar results were achieved with a UPlanSApo 10× objective with a numerical aperture of 0,40 and a working distance of 3,1mm. Moreover, a variant of the same tracking system has also been implemented on the SIM.

Conclusion
We have described and built an automated out-of-focus detection and correction system that is inexpensive, easy to build, and compatible with any microscope that has an actuated stage or objective. This system keeps a sam-  ple in focus during time-lapse experiments where z-drift occurs. Extending the system with different hardware components is quite easy as new stages or cameras just need to be added to the API.
For more sensitive systems, it would be easy to synchronize both the laser and the camera so that there is only infrared light when really needed. Also, the rest of the measurement protocol, e.g. so that infrared light does not leak into the main image acquisition. The software could be extended to reacquire different focus positions so that, when they have been stored once, the microsope can be back to them. Moreover, we could improve the software to support scanning.

A List of Components
This section gives an overview of the necessary components to build this system, together with their reference number, their price and a description of the component. This extra list has a price of €313,54. The total price of the system is €1.797,89.

B Alignment Procedure
We have the freedom to align the system as desired. It is an easy alignment procedure, that is described in the following guide. Activating the crosshair may help centering the beams on the camera window.
1. Align the infrared laser: Make the elliptical infrared light beam as bright as possible using the tilting mount, center it using a detector card and a spatial filter.
2. Align the rotation mount and mask together so that the two spots are centered and as bright as possible (Figure ??). Use a detector card and a spatial filter.