Micromanager Script for Tile Scanning with 3 Point Z Correction

[Credits:  Manoj V Mathew
Experiments were conducted at the Central Imaging and Flow Cytometry Facility (CIFF), National Center for Biological Sciences (NCBS), Bangalore, India.]

A couple of months ago a start-up-company approached me seeking help in building a low-cost slide digitizer for pathology applications. One of the issues they faced is the amount of time it took them to scan a single slide, which runs into more than a 1000 tiles at 20X mag. What adds most to this time is the Z drift compensation (software based) which needs to be performed on every tile or every few tiles.

This got me interested in writing a micromanager script for tile scanning with a built in three point Z correction option. In most applications where low magnification is used, like in the case of pathology scanners, it is not the Z drift that is the main culprit. The slide is tilted by a small amount when it is mounted. When tile scanning over the whole slide or a very large ROI using an automated XY stage, this tilt results in the image going out of focus. This tilt can be measured and corrected by providing a variable offset to the Z drive for each tile. This gives very good results even without the need for a time-consuming Z drift compensation algorithm. A hardware based (IR light used to locate the coverslip) would be a better solution for this problem, but then it is expensive.

The script can be downloaded from my GitHub Page.

The script is written to be independent of the hardware you use.The script will work if the micromanager configuration file has the camera, Z drive, and the XY motorized stage loaded.  In our setup I used a Nikon Tie, with an Hamamatsu Flash 4 V2 Camera and Prior Proscan III XY sample stage. The screen shot of the micromanager Hardware Configuration used is shown Figure B1451/1.

Figure B1451/1: Micromanager Hardware Configuration

For the script to work, you should make sure that the XY stage and the Camera are oriented right. If you move the joystick left, the stage should move left, if you move the joy stick up, the stage should move up and so on. If this is happening then the stage is configured right. Now if you check the live image and you see the same thing with respect to the stage movement, then the camera is oriented right as well. If not you might have to rotate your camera, 90 or 180 degrees. Also, make sure that a single axis motion of the stage results in a single axis motion in the camera image. Else the camera is slightly tilted. Make sure to set the microscope port to the one that has the camera connected and that the illumination is set to the required intensity.

Before you run the script enter the following system parameters in the script :

  1. Objective magnification (multiplied by intermediate magnification if used)
  2. Number of columns of pixels in the camera chip
  3. Number of rows of pixels in the camera chip
  4. Pixel size of the camera in micrometers
  5. Percentage overlap required between tiles for seamless stitching (10% usually works)

When you run the script the following happens:

  1. A GUI pops up requesting you to select the folder where you want to store the images. Select a folder to store the tiles. 
  2. The live window turns ON 
  3. A dialog pops up requesting you to move the stage to the bottom right (of the ROI on the slide you want to image) and adjust the focus manually to the optimal focus.
  4. Once you move the stage to the appropriate location and click OK another dialog pops up requesting you to move the stage to the top right (of the ROI on the slide you want to image) and adjust the focus manually to the optimal focus.
  5. Again you move the stage to the appropriate location and click OK another dialog pops up requesting you to move the stage to the top left (of the ROI on the slide you want to image) and adjust the focus manually to the optimal focus.
  6. This marks the three corners of the rectangle (ROI) you intend to image and measures the optimal Z focus at each corner.
  7. From the system parameters and the data obtained from the three corners, the script calculates the following: a. the size of each tile, b. No: of columns of the tile matrix, c. No: of rows of the tile matrix, d. the fixed X and Y stage offset for each tile and e. the linearly variable Z offset for each tile.
  8. The stage and Z drive is offset for each tile and an image is acquired and saved in the specified folder. The images are consecutively named using integers in '.tif' format. The first tile will be named 1.tiff and the last one (No: columns of tile matrix X No: of rows of the tile matrix).tif. 

The images can be stitched using the stitching plugin in FIJI.

For stitching in FIJI select: Plugins->Stitching->Grid/Collection Stitching

In Grid/Collection Stitching use the parameters as shown in Figure B1451/2.

Select Type=Grid:row-by-row. Select Order=Right&Down.

Figure B1451/2: Grid Collection  Parameters

Click OK and configure the stitching parameters as shown in Figure B1451/3.

Figure B1451/4: Image stitiching parameters

The micromanager script computes the column and row sizes of the tile matrix. This is printed while the script executes.

We had some very old blood smears. I imaged few of them using the micromanager script and stitched the tiles using FIJI. A screen shot of one of the stitched images is shown in Figure B1451/3. The figure shows the screen shot of an image of a blood smear slide imaged at 30X (20x Objective and 1.5X intermediate magnification). The image is a stitch of 779 (41x19) tiles, spanning an area of approximately 2cmX1cm of the slide.

Figure B1451/4: Screen shot of a stitched image of 779 (41x19) tiles, spanning an area of approximately 2cmX1cm of the slide

Another such image is in Figure B1451/4. This figure shows the screen shot of an image of a blood smear slide imaged at 15X (10x Objective and 1.5X intermediate magnification). The image is a stitch of 780 (52x15) tiles, spanning an area of approximately 4.5cmX1.5cm of the slide.

Figure B1451/5: Screen shot of a stitched image of 780 (52x15) tiles, spanning an area of approximately 4.5cmX1.5cm of the slide

It can be seen from both the above images that the 3 point Z correction algorithm has maintained the Z focus. It was observed that the Z focus was maintained for the entire area of a standard slide. However, the ability to stitch very large tile matrices was limited using the FIJI plugin. For stitched image sizes greater than 4GB the stitching plugin gives an error. So tiling more than around 800 tiles was difficult. This can be improved by reducing the bit depth of the camera while acquisition or downsampling post acquisition.