Skip to main content
NIHPA Author Manuscripts logoLink to NIHPA Author Manuscripts
. Author manuscript; available in PMC: 2015 Jun 14.
Published in final edited form as: J Microsc. 2012 Oct 18;248(3):245–259. doi: 10.1111/j.1365-2818.2012.03669.x

AUTOMATIC SECTION THICKNESS DETERMINATION USING AN ABSOLUTE GRADIENT FOCUS FUNCTION

Daniel T Elozory 1, Kurt A Kramer 1, Baishali Chaudhuri 1, Om P Bonam 1, Dmitry B Goldgof 1, Lawrence O Hall 1,*, Peter R Mouton 2
PMCID: PMC4465598  NIHMSID: NIHMS695431  PMID: 23078150

Abstract

Quantitative analysis of microstructures using computerized stereology systems is an essential tool in many disciplines of bioscience research. Section thickness determination in current non-automated approaches requires manual location of upper and lower surfaces of tissue sections. In contrast to conventional autofocus functions that locate the optimally focused optical plane using the global maximum on a focus curve, the present study identified by two sharp “knees” on the focus curve as the transition from unfocused to focused optical planes. Analysis of fourteen gray-scale focus functions showed, the thresholded absolute gradient function, was best for finding detectable bends that closely correspond to the bounding optical planes at the upper and lower tissue surfaces. Modifications to this function generated four novel functions that outperformed the original. The “modified absolute gradient count” function outperformed all others with an average error of 0.56 μm on a test set of images similar to the training set; and, an average error of 0.39 μm on a test set comprised of images captured from a different case, i.e., different staining methods on a different brain region from a different subject rat. We describe a novel algorithm that allows for automatic section thickness determination based on just out-of-focus planes, a prerequisite for fully automatic computerized stereology.

Keywords: Design-based stereology, automated stereology, thresholded absolute gradient, Z-stack, focal depth

1. INTRODUCTION

Current computerized stereology systems require trained users to carry out several manual steps in order to generate design-based estimates of first- and second-order stereological parameters of biological interest. Existing autofocus functions for brightfield microscopy locate the optimal focal plane, i.e., the plane at which biological microstructures appear at maximal focus as determined by a trained observer (Shen et al., 2008, Liu et al., 2006, Hilsenstein, 2005, Sun et al., 2004, Santos et al., 1997). For the purpose of automatic stereological anlaysis using computerized systems, one prerequisite is location of the optical planes that correspond to the out-of-focus planes above and below the stained tissue sections. A second requirement is that any approach for automatic section thickness determination must be robust across a range of conditions, including healthy vs. diseased tissue; tissue from different species; and, tissues stained with a variety of techniques (Mouton, 2002; Mouton & Gordon, 2010, Mouton, 2011a,b). A critical obstacle to the full automation of feature recognition algorithms to enable automatic recognition of biological structures of interest (Mouton et al., 2005) is the requirement to locate the boundaries between in-focus and out-of-focus optical planes at the upper and lower surfaces of stained tissue sections. Using current, non-automated approaches, section thickness determination is carried out by manual adjustments using the microscope’s fine focusing mechanism to locate “just-out-of-focus” optical planes above and below the cut surfaces of the tissue. Computerization of this process with an autofocus algorithm represents a significant advance toward fully automated applications of design-based stereology to biological tissue.

The goals of this research were three-fold. The first goal was to develop a function to automatically locate the top and bottom surface of a routine section of stained tissue, and then repeat this process at multiple X-Y locations within an anatomically defined reference space. Locating the top and bottom surface enables correct automatic placement of geometric probes for stereology, for example disector, as well as automatic determination of the section thickness. Using a brightfield microscope at high magnification (100x objective), the upper and lower surfaces of the tissue section were defined as the “just out of focus” optical planes, i.e., above and below the first in-focus optical planes. The desired level of accuracy for an automated function was to be within 1.0 μm of the top and bottom “just out of focus” optical planes, on average, compared to the manually measured surface location (ground truth). With a typical step size of 1.0 μm between optical planes in the Z-axis, this level of accuracy translates to ±1 optical plane from the ground-truth plane. No attempt was made to interpolate between Z-stack images to locate a more refined boundary.

The second goal was to develop a method for training the automated surface location algorithm across a range of threshold parameters to optimize the performance of each focus function. The locations of 36 tissue surfaces within 18 Z-stacks were manually identified for use as the training set for these studies. Incorporating a focus function into an autofocus algorithm requires thresholding the focus function output, i.e., focus measure, also known as the focus threshold. Additionally, the focus functions were divided into two categories: 1) functions with a pixel-to-pixel contrast threshold (thresholded functions); and, 2) functions with no contrast threshold (non-thresholded functions). For thresholded functions, the Nelder Mead simplex optimization method (Press, 1988) for two dimensional parameter spaces was used to find the optimal pixel-to-pixel contrast threshold, which was paired with the total image focus threshold to yield the focus function with the lowest average error rate. For non-thresholded functions, the golden ratio optimization method (Press, 1988) was used to locate the best focus threshold.

Finally, because the morphological and histological characteristics of biological microstructures vary within and between tissue sections (Mouton & Gordon, 2010, Mouton, 2011a), focus function threshold parameters typically require retraining for different datasets. The ideal focus function would have thresholds that perform well across datasets, without retraining; for different hardware; across the range of biological variation in microstructures; and for different staining methods used to process tissue sections for computerized stereological analysis. Thus, the third goal of this research was to evaluate the robustness of the threshold selection for different datasets collected across a range of actual conditions.

A significantly less complete version of this work was published in (Elozory et al., 2011). Here, 7 more existing focus functions are evaluated and we introduce 2 new functions. There are 7 functions (vs. 1) fully evaluated for automated surface location. In this paper, an extra test set was acquired from the hypocampus region and which is completely different than the training set. This allows for the much more extensive evaluation done here.

2. MATERIALS AND METHODS

2.1. Data Collection Equipment

These studies were carried out using the Stereologer system (Stereology Resource Center, Inc., Chester, MD) that consists of a Zeiss Axioskop 20 brightfield microscope with a range of low (Zeiss Plan Neofluar 2.5x) to high (Zeiss Plan-Apochromat 100x oil immersion, numerical aperture 1.4) magnification objectives equipped with digital imaging and interfaced to a motorized X-Y-Z stage (ASI, Eugene, Oregon) for both manual and automated modes via the system software. The digital camera (Microfire, Optronics, Goleta, CA) was capable of capturing 800 × 600 pixel images in 8-bit by three channel (RGB) color mode. The charged-coupled device (CCD) for the camera was a single 2/3” 1600 × 1200 pixels array with 7.4 μm × 7.4 μm pixel size using a Bayer mosaic filter array to capture color information. This common Bayer filter placed a mosaic filter over the CCD such that each 2 × 2 pixel square had an RGB (25 Red, 50 Green, 25 Blue) color filter. The Stereologer software was compatible with both iMac G4 platform (32-bit 1.25GHz, OS10.6) and Dell Optiplex GX280 (32 bit 3.20 GHz Intel Pentium4) running Microsoft Windows 7 Enterprise version.

Depth of field (DOF) was calculated to be 0.43 μm using Equation (1), where: λ is the wavelength of illuminating light (0.55 μm for average visible light); η is the refractive index (1.516 for immersion oil); NA is the objective numerical aperture; M is the lateral magnification; and, e is the lateral resolution power (constrained to a minimum of 0.24 μm by Abbe diffraction limit).

DOF=λη(NA)2+eηM(NA) (1)

The second term becomes insignificant at high magnification and high numerical aperture (100x oil immersion, NA 1.4). Finally, the proper choice of objective is used to achieve the practical light microscope minimum DOF. A shallow DOF results in a shallow depth of focus that is desirable as reducing depth of focus is equivalent to enhancing axial resolution (Yuste & Konnerth, 2005), e.g., DOF of less than 1.0 μm is required to achieve 1.0 μm precision.

2.2. Datasets

Tissue for these studies provided by the Stereology Resource Center (SRC, Chester, MD)] included sections stained with two common approaches to reveal microstructures of biological interest: tyrosine hydroxylase (TH) immunocytochemistry to reveal dopaminergic neurons in the rat substantia nigra; and, Nissl histochemistry (cresyl violet) to stain pyramidal neurons in the CA region of the hippocampus. The sections are cryostat and not plastic embedded. The cut section thickness, i.e., block advance, for the tissue was 40 microns, while the final section thickness after all tissue processing was about 20 microns. This tissue shrinkage of about 50% is expected for tissue staining protocols that include a dehydrating alcohol series. A Z-stack was defined as a series of images captured at incremental (0.1 μm) steps in the Z plane. Three separate datasets (Table 1) consisting of Z-stacks of images were acquired at high magnification (100x, 1.4 n.a.) with the X-Y plane and Z-axis perpendicular and parallel, respectively, to the camera axis. The Stereologer captured Z-stacks using the following procedure:

  1. Anatomically defined reference spaces (the substantia nigra and the hippocampus) were outlined by manual user clicks at low magnification (2.5x objective).

  2. After switching to high magnification, the Stereologer automatically selects a series of X-Y locations within the reference space in a systematic-random manner.

  3. The user locates the top and bottom optical planes at each X-Y location by clicking the location of interfaces between unfocused and focused images at the top and bottom of the tissue section.

  4. The user sets step increment and buffer in Z-axis to ensure acquisition of unfocused images above and below tissue.

  5. The Stereologer system automatically acquires Z-stack at that X-Y location.

  6. With user assistance, the Stereologer system collects multiple Z stacks by repeating steps 3, 4 and 5 at different systematic-random locations through the X-Y plane of the reference space.

Table 1.

Characteristics of Datasets Used for Evaluation

Dataset Description Number of
Z-stacks
Number of
Images
Training Set Cryostat 010610 Substantia Nigra
Rat C1 Sec: 05,07,08,09
18 455
Test Set #1 Cryostat 010610 Substantia Nigra
Rat C1 Sec: 05,07,08,09
16 373
Test Set #2 Nissl 041696 Hippocampus
Rat10
18 490

The acquired Z-stacks were divided into three datasets – a training set and two test sets. The training set and test set #1 included Z-stacks from sections through a single brain region (substantia nigra) and stained with TH immunocytochemistry from the brain of a single rat. A second test set (test set #2) included Z-stacks acquired from sections though the brain of a different rat, from a different brain region (hippocampus), and stained with a different procedure (Nissl histochemistry).

2.3. Focus Functions

2.3.1. Common Thresholded Focus Functions

A total of eighteen focus functions were analyzed, including fourteen published functions from the literature of microscopy autofocusing. The remaining four functions resulted from modifications to the thresholded absolute gradient function which had the lowest error in locating the “just out of focus” optical plane as described in the proceeding. The first six functions, as well as all four modified functions, required selection of a threshold. Threshold selection adds a level of complexity, yet enables “fine tuning” of the function. Equation (2), used in the thresholding equations that follow, returns a given value when the given value exceeds the specified threshold.

Threshold(x,T)={x,xT0,x<0} (2)

Six previously developed thresholded focus functions, as shown in Equations (3) through (8), were tested:

AbsoluteGradient:Fag=ijThreshold(I(i,j+1)I(i,j),T) (3)

(Elozory et al., 2011, Groen et al., 1985, Hamm et al., 2010, Krotkov, 1988, Liu et al., 2006, Santos et al., 1997, Sun et al., 2004, Sun et al., 2005, Vollath, 1987)

SquaredGradient:Fsg=ijThreshold((I(i,j+1)I(i,j))2,T) (4)

(Elozory et al., 2011, Groen et al., 1985, Liu et al., 2006, Pech-Pacheco et al., 2000, Santos et al., 1997, Sun et al., 2004, Sun et al., 2005, Vollath, 1987)

BrennerGradient:Fbg=ijThreshold((I(i,j+2)I(i,j))2,T) (5)

(Brenner et al., 1976, Elozory et al., 2011, Firestone et al., 1991, Hamm et al., 2010, Liu et al., 2006, Osibote et al., 2010, Santos et al., 1997, Sun et al., 2004, Sun et al., 2005)

Content:Fcontent=ijThreshold(I(i,j)) (6)

(Firestone et al., 1991, Groen et al., 1985, Liu et al., 2006, Pech-Pacheco et al., 2000, Santos et al., 1997, Sun et al., 2004, Sun et al., 2005)

PixelCount:Fpc=ijPCount((I(i,j),T),wherePCount(x,T)={1,xT0,x>T} (7)

(Groen et al., 1985, Liu et al., 2006, Pech-Pacheco et al., 2000, Santos et al., 1997, Sun et al., 2004, Sun et al., 2005)

ImagePower:Fpower=ijThreshold(I(i,j)2) (8)

(Firestone et al., 1991, Groen et al., 1985, Liu et al., 2006, Pech-Pacheco et al., 2000, Santos et al., 1997, Sun et al., 2004, Sun et al., 2005)

2.3.2. Common Non-Thresholded Focus Functions

A total of eight conventional, non-thresholded focus functions were evaluated, as shown in Equations (9) through (16). These less complex non-thresholded focus functions do not require a pre-selected threshold.

TenenbaumGradient:Ftg=ij(Sx(i,j)2+Sy(i,j))2) (9)

where Sx and Sy are the convoluted images with Sobel operators.

(Bueno-Ibarra et al., 2005, Hamm et al., 2010, Hilsenstein, 2005, Huang & Jing, 2007, Krotkov, 1988, Liu et al., 2006, Osibote et al., 2010, Santos et al., 1997, Sun et al., 2004, Sun et al., 2005, Tenenbaum, 1970)

EnergyLaplace:FeL=ij(L(i,j))2whereListheconvolutedimagewithLaplacemask:[1414204141] (10

(Groen et al., 1985, Huang & Jing, 2007, Krotkov, 1988, Liu et al., 2006, Osibote et al., 2010, Sun et al., 2004, Sun et al., 2005)

Variance:Fvar=1HVij(I(i,j)I)2 (11)

(Elozory et al., 2011, Groen et al., 1985, Huang & Jing, 2007, Krotkov, 1988, Liu et al., 2006, Santos et al., 1997, Sun et al., 2004, Sun et al., 2005)

Normalized:Variance:Fnvar=1HWIij(I(i,j)I)2 (12)

(Elozory et al., 2011, Firestone et al., 1991, Groen et al., 1985, Hamm et al., 2010, Liu et al., 2006, Osibote et al., 2010, Santos et al., 1997, Sun et al., 2004, Sun et al., 2005)

Autocorrelation:Fadcor=ijI(i,j)I(i,j+1)ijI(i,j)I(i,j+2) (13)

(Elozory et al., 2011, Hamm et al., 2010, Hilsenstein, 2005, Liu et al., 2006, Osibote et al., 2010, Santos et al., 1997, Sun et al., 2004, Sun et al., 2005, Vollath, 1987)

StandardDeviationBasedCorrelation:Fsdcor=ijI(i,j)I(i,j+1)HW(I)2) (14)

(Elozory et al., 2011, Hamm et al., 2010, Liu et al., 2006, Santos et al., 1997, Sun et al., 2004, Sun et al., 2005)

Range:Frange=max{ihist(i)>0}min{ihist(i)>0} (15)

where hist(i) is the number of pixels of intensity i.

(Firestone et al., 1991, Liu et al., 2006, Santos et al., 1997, Sun et al., 2004, Sun et al., 2005)

Entropy:Fentropy=ipilog2(pi),wherepi=hist(i)/HW (16)

(Firestone et al., 1991, Krotkov, 1988, Liu et al., 2006, Santos et al., 1997, Sun et al., 2004, Sun et al., 2005).

2.3.3. New Focus Functions

The initial testing of the above 14 functions [Equations (3) through (16)] identified Equation (3), the thresholded absolute gradient, as superior to all others in determining tissue surface location in terms of overall rank based on minimum error. Four modifications were made in an effort to achieve greater performance from this function. Intermediate functions below [Equations (17) through (19)] simplify the descriptions of Equations (20) through (23). Equation (17) is an indicator function that signifies whether the current pixel location (i, j) is high contrast, and returns 1 if this is true or 0 otherwise. High contrast for this function occurs when the absolute value of the difference between the current pixel and either its neighboring pixel to the right or directly below is greater than or equal to the designated threshold value. Equation (18) describes the binary 3 × 3 median filter used in functions represented by Equations (22) and (23). Equation (18) determines the number of the eight immediate neighboring pixel locations with high contrast, while Equation (19) returns the thresholded absolute gradient contrast strength in both the horizontal and vertical direction for a given pixel location (i, j).

Count(i,j,T)={1,I(i,j+1)(i,j)TORI(i+1,j)(i,j)T0,otherwise} (17)
Median(i,j,T)={Count(i1,j1,T)+Count(i1,j,T)+Count(i1,j+1,T)+Count(i,j1,T)+Count(i,j+1,T)+Count(i+1,j1,T)+Count(i+1,j,T)+Count(i+1,j+1,T)} (18)
ModAbsThr(i,j,T)={Threshold(I(i,j+1)I(i,j),T)+Threshold(I(i+1,j)I(i,j),T)} (19)

Equations (20) through (23) represent the four new focus functions introduced by the present work (Elozory, 2011). The modified absolute gradient (MAG) function [Equation (20)] is a rotationally invariant form of the absolute gradient function [Equation (3)]. The modified absolute gradient count (MAGC), Equation (21), is rotationally invariant with a simple count of high contrast pixels, as determined by Equation (17). Equations (22) and (23) reduced spurious noise through applications of a 3 × 3 median filter to the MAG function [Equations (20)] and the MAGC function [Equation (21)].

ModifiedAbsoluteGradient:Fmag=ijModAbsThr(i,j,T) (20)
ModifiedAbsoluteGradientCount:Fmage=ijCount(i,j,T) (21)
FilteredModifiedAbsoluteGradient:Ffmag=ij{Count(i,j,T)=1ModAbsThr(i,j,T),ANDMedian(i,j,T)40,otherwise} (22)
FilteredModifiedAbsoluteGradientCount:Ffmage=ij{1,Count(i,j,T)=1ANDMedian(i,j,T)40,otherwise} (23)

Using a Z-stack of images as input, each of the above functions generated a focus curve. Acquisition of Z-stacks of images started at the optical plane above the top surface of the tissue and proceeded to a focal plane below the bottom surface. A low incremental step-size (1 μm) through the Z-axis ensured identification of the boundary between unfocused and focused regions within an acceptable error rate. For locating the depth of focus of a tissue surface, the just out of focus image was defined as the boundary between unfocused and focused regions, with no interpolation between images.

The primary goal of the present study, to locate the just out of focus planes, is an important distinction compared to traditional approaches, e.g., the work of Osibote et al. (2010), which was designed to locate the optical plane of peak focus. These earlier approaches are based on the idea that focus functions behave like Gaussian curves near their peaks (Nayar & Nakagawa, 1994), and based on the knowledge that the logarithm of a Gaussian is quadratic, enable fitting of a parabolic curve between adjacent images to determine optimal peak focus along the focus curve. In contrast, the just out of focus area of the focus curve targeted by the present study does not approach a Gaussian or any other well-defined function; therefore, no interpolation or curve fitting was carried out.

To locate the just out of focus images, the ideal focus curve should differentiate three regions in each Z-stack:

  1. The unfocused images above the tissue sample.

  2. The in-focus images within the tissue sample.

  3. The unfocused images below the tissue sample.

The two unfocused regions on either side of the in focus region were assumed to behave in a similar manner, i.e., these regions of the focus curve response would be zero with no points of focus in the image. In practice, these regions would be at, or close to, a minimum and relatively flat compared to the in-focus region, with no assumption that these regions would be monotonic. The only requirement for an in-focus region is that the bounding images would have a higher focus measure than every image from the unfocused regions. Note, even the bounding planes of the in focus regions cannot be expected to have the same measure of focus since the number and size of object surfaces cut by the optical plane are expected to vary. Finally, there was no assumption of unimodality in the region and no requirement for all these images to yield higher focus measures than the unfocused images.

2.4. Automated Surface Location Algorithm

We developed an algorithm to locate the top and bottom tissue surfaces of a Z-stack of images using a specified focus function. Within the in focus regions, there is no expectation of symmetry. There are two main reasons: (1) slices contain different structures and so vary from slice to slice, and (2) slices closer to the bottom are imaged through more and more semi-transparent slices above and, hence, have different pixel intensities. The algorithm uses a training set of Z-stacks with manually determined tissue surfaces to optimize the focus function threshold parameters. Pseudo-code is shown in Appendix 1. Automating the thresholded functions requires optimization of a two-dimensional parameter space. The Nelder Mead simplex optimization method (Press, 1988) was selected on the basis of computational simplicity – no need to calculate function derivatives – and ability to adjust the traversal rate by expanding or contracting the step size as needed. Automation of the non-thresholded functions requires optimization in a single dimensional parameter space. The golden ratio optimization method (Press, 1988) was used on the basis of simplicity and efficiency. Once the algorithm was trained and the optimized thresholds determined, Z-stacks were analyzed to find the top and bottom focal planes for automatic section thickness determination. The automated surface locating algorithm started at the top of the Z-stack and moved down the Z-stack one image at a time. Focus of the first image was assessed over the trained focus threshold, and repeated for each consecutive image with each previous image designated as the just-out-of-focus optical plane, i.e., the top surface boundary. Second, the algorithm started from the bottom of the Z-stack and moved up the Z-stack, one image at a time, until the first image with focus measure over the trained focus threshold was located, with the previous image designated as the bottom tissue surface boundary. Except for the first image on either side of the in-focus region, no images within the in-focus region were analyzed.

3. RESULTS

Figures 1 through 5 show the focus curves for each of the fourteen common functions analyzed using a typical Z stack in the training set. Figure 6 indicates the focus curves for the four modified functions for the same Z-stack. All functions were optimized over the training set to minimize deviation from the top and bottom surfaces located in a manual manner (i.e., ground truth). The two vertical bars in every figure represent ground truth and separate each focus curve into three regions: the middle region between the ground truth bars, that is, the in-focus region; and the two out-of-focus regions on either side of the in focus region that include the ground truth bars. When possible to select correct focus thresholds, the range of acceptable thresholds is shaded horizontally across the figure to separate the focus curve at the ground truth bars (see Figure 1, Figure 3b, and Figure 6).

Figure 1.

Figure 1

Thresholded Gradient Focus Curves from a typical Z stack in the Cryostat Training Set (Rat C1 Sec09 XY02). The two red vertical bars depict the manually determined surface depth. The green region depicts the range of threshold values that correctly identify the surface depth by partitioning the Z-stack into a focused region bounded by an unfocused region on either side.

Figure 5.

Figure 5

Histogram Based Functions

Figure 6.

Figure 6

Modified Absolute Gradient Focus Curves. These functions were modified in an attempt to better locate the surface depth. As in Figure 1, the green region depicts the range of threshold values that correctly identify the surface depth by partitioning the Z-stack into a focused region bounded by an unfocused region on either side.

Figure 3.

Figure 3

Non-Thresholded Gradient Focus Curves. As in Figure 1, the green region depicts the range of threshold values that correctly identify the surface depth by partitioning the Z stack into a focused region bounded by an unfocused region on either side.

Of the eighteen focus functions analyzed, the thresholded gradient based functions (Figure 1 and Figure 6) were the only functions to achieve the performance requirements as defined in the first goal of this study. These seven focus functions were each independently incorporated into the automated surface location algorithm, and each trained to find the top and bottom tissue surfaces within an average tolerance of 1.0 μm using the arbitrarily selected training set (Table 2). With trained threshold parameters, all seven functions identified the top and bottom tissue surfaces within 1.0 μm on a test set of similar Z-stacks, Test set #1 (Table 3); and, on a Test set #2 that represents a set of Z-stacks from a different rat brain case study (Table 4).

Table 2.

Automated Focus Determination Training Set Optimization.

Eq. Function Contrast
Threshold
Focus
Threshold
Average
Error
from G.T.
Standard
Deviation
from G.T.
(μm) Rank (μm) Rank
(3) Absolute Gradient 16 700 0.72 1 0.80 6
(4) Squared Gradient 119 197,878 0.89 7 1.56 7
(5) Brenner Gradient 486 130,444 0.75 4 0.79 5
(20) Modified Absolute
Gradient
18 239 0.72 1 0.69 3
(21) Modified Absolute
Gradient Count
18 18 0.75 4 0.68 1
(22) Filtered Modified
Absolute Gradient
17 118 0.72 1 0.77 4
(23) Filtered Modified
Absolute Gradient Count
16 10 0.75 4 0.68 1
(6) Content 96 159,139 4.22 16 2.76 17
(8) Pixel Count 42 13,429 2.56 11 2.65 14
(7) Image Power 80 695,994,640 4.33 17 2.69 15
(9) Tenenbaum Gradient N/A 517,555,008 1.50 10 2.13 8
(10) Energy Laplace N/A 393,364,455 1.17 8 2.23 10
(11) Variance N/A 948 2.86 12 2.63 13
(12) Normal Variance N/A 89,505 2.97 13 2.51 12
(13) Autocorrelation N/A 6,027,949 1.44 9 2.15 9
(14) Standard Deviation
Based Autocorrelation
N/A 758,447,304 4.50 18 2.69 16
(15) Range N/A 180 3.31 15 2.95 18
(16) Entropy N/A 6.8484 3.00 14 2.44 11

Table 3.

Automated Focus Determination, Test Set #1.

Eq. Function Contrast
Threshold
Focus
Threshold
Average
Error
from G.T.
Standard
Deviation
from G.T.
(μm) Rank (μm) Rank
(3) Absolute Gradient 16 700 0.63 4 0.42 2
(4) Squared Gradient 119 197,239 0.69 6 0.53 7
(5) Brenner Gradient 486 130,341 0.78 8 0.48 6
(20) Modified Absolute
Gradient
18 230 0.66 5 0.41 1
(21) Modified Absolute
Gradient Count
18 18 0.56 1 0.43 3
(22) Filtered Modified
Absolute Gradient
17 118 0.59 3 0.43 3
(23) Filtered Modified
Absolute Gradient Count
16 20 0.56 1 0.43 3

Table 4.

Automated Focus Determination Test Set #2.

Eq. Function Contrast
Threshold
Focus
Threshold
Average
Error
from G.T.
Standard
Deviation
from G.T.
(μm) Rank (μm) Rank
(3) Absolute Gradient 16 700 0.42 2 0.71 6
(4) Squared Gradient 119 197,239 1.00 7 0.71 6
(5) Brenner Gradient 486 130,341 0.53 6 0.68 5
(20) Modified Absolute
Gradient
18 230 0.47 4 0.65 1
(21) Modified Absolute
Gradient Count
18 18 0.39 1 0.65 1
(22) Filtered Modified
Absolute Gradient
17 118 0.47 4 0.65 1
(23) Filtered Modified
Absolute Gradient Count
16 20 0.44 3 0.67 4

Ranking the algorithms by both average error rate as well as standard deviation from the ground truth showed that the MAGC function outperformed the others by finding tissue section surfaces within 0.56 μm on average for test set #1, and within 0.39 μm on average for test set #2. Surpassing the tolerance goal of ±1.0 μm for each surface, tissue thickness was also determined within ±1.0 μm on average. Because two surface locations for each Z-stack are required to determine each section thickness measure, the two test sets were combined to determine tissue thickness. On the resulting set of 34 tissues samples, six of the seven thresholded gradient functions yielded an error rate of less than 1.0 μm (Table 5). Once again, the MAGC function had the lowest error rate (0.76 μm).

Table 5.

Automated Tissue Thickness Determination for Test Sets #1 and #2 Combined

Eq. Function Contrast
Threshold
Focus
Threshold
Average
Error
from G.T.
Standard
Deviation
from G.T.
(μm) Rank (μm) Rank
(3) Absolute Gradient 16 700 0.85 3 1.13 6
(4) Squared Gradient 119 197,239 1.41 7 1.13 6
(5) Brenner Gradient 486 130,341 0.94 5 1.04 5
(20) Modified Absolute
Gradient
18 230 0.94 5 0.98 2
(21) Modified Absolute
Gradient Count
18 18 0.76 1 1.00 4
(22) Filtered Modified
Absolute Gradient
17 118 0.88 4 0.96 1
(23) Filtered Modified
Absolute Gradient Count
16 20 0.82 2 0.99 3

Supervised sets of Z-stack images stored as portable gray scale maps (pgm files) on hard disk were used to develop a training method to optimize the automated surface location algorithm. The automation of the thresholded gradient functions required selection of two thresholds: The pixel-to-pixel contrast threshold to determine whether to include the contrast between two pixels in the function summation; and, the total image focus threshold to decide whether an image is in focus or not. Since the Nelder Mead optimization outcome is dependent on the initial selection of simplex coordinates (Press, 1988), the method was run three times for each focus function, with a different initialization each time. The automated surface location algorithm used each of the hundreds of threshold pairs selected by Nelder Mead with each focus function to locate 36 tissue surfaces within 18 Z-stacks consisting of a total of 480 images. This analysis led to seven focus functions that located correct tissue surfaces within the desired error rate tolerance after application of the optimized thresholds.

Test set #2, a set of rat brain coronal sections taken from a different study than the rat brain coronal sections from the training set, was used to analyze the robustness of the optimized thresholds. Importantly, both the histochemical stain (cresyl violet) and reference space (hippocampus) for sections in test set #2 differed markedly in appearance from that of the training set obtained from TH-immunostained sections through the substantia nigra in test set #1. Nonetheless, using threshold parameters optimized on the training set, the same seven focus function that performed well on test set #1 performed to the same level on test set #2 (see Table 4), with the MAGC function outperforming others with an average error rate of 0.76 μm.

To test the statistical significance of these findings, the success rate of all seventeen focus functions were compared to the MAG. Success was defined as automatic identification of a tissue surface within 1 μm of the tissue surface location determined by the user in a manual manner. The seven thresholded gradient functions attained this goal, while the remaining functions did not. When one looks at which of the seven functions is more likely to find the right boundary with the paired t-test one finds the MAGC stands out. The paired t-test (Tamhane & Dunlop, 2000) confirmed that the MAGC function was statistically different than all the other gradient functions, except the modified absolute gradient, with regard to accurate determinations of tissue surfaces locations with a confidence interval of 95% compared to the mean difference from ground truth (Elozory, 2011). Now, if you look at both top and bottom or slice thickness, the MAGC function found the correct tissue thickness relative to ground truth in a more consistent manner than all other functions, with a confidence interval of 99% or more (see Table 6).

Table 6.

McNemar Chi Squared Test Measuring Statistical Significance

McNemar Chi Squared Test (with 1 Degree of Freedom) with Likelihood [confidence
interval (CI, %)] that Modified Absolute Gradient count (Equation 21) is statistically
different from other focus functions with regard to accurate location of tissue
surfaces.
Eq. Function Training Test Set1 Test Set2 Thickness
Test Set
X2 CI X2 CI X2 CI X2 CI
(3) Absolute Gradient 0.25 38 NSD* 0 NSD* 0 0.25 38
(4) Squared Gradient 0.13 28 0.56 55 6.04 99 2.52 23
(5) Brenner Gradient 0.25 38 0.56 55 NSD* 0 0.06 20
(20) Modified Absolute
Gradient
NSD* 0 0.28 40 0.25 38 2.08 85
(22) Filtered Modified
Absolute Gradient
NSD* 0 0.28 40 0.25 38 0.08 23
(23) Filtered Modified
Absolute Gradient
Count
NSD* 0 NSD* 0 0.25 38 0.13 28
(6) Content 22.23 100 24.01 100
(8) Image Power 25.01 100 24.01 100
(7) Pixel Count 25.01 100 19.01 100
(9) Tenenbaum
Gradient
1.23 73 8.03 100
(10) Energy Laplace 0.56 55 1.13 71 19.01 100 8.22 100
(11) Variance 13.35 100 22.01 100
(12) Normal Variance 17.28 100 22.01 100
(13) Autocorrelation 0.28 40 4.69 97
(14) St Dev
Autocorrelation
23.22 100 24.01 100
(15) Range 14.33 100 22.01 100
(16) Entropy 15.31 100 20.01 100
*

NSD = No statistical difference

The distribution of the deviation of the automated location of tissue surfaces from the ground truth is shown in Tables 7 through 10. The deviation is the positive difference between the automated surface location algorithms determination of surface location and the ground truth. This difference is measured in whole micrometers. Since the step size through the Z-stacks was 1 μm, this difference is the number of images from the correct just out of focus image returned by the algorithm. On Test set #1 and Test set #2 the MAGC function was never more than two images away, i.e., within 2 μm, from the ground truth. 94% of the tissue surfaces determined by the MAGC function were within a single image from the ground truth. For thickness determination, this was not the case, since measuring thickness requires measurement of both the upper and lower surfaces, and therefore requires a higher tolerance level. Nonetheless, tissue thickness was determined within 1 μm by the MAGC function 78% of the time, and never greater than 3 μm from than ground truth.

Table 7.

Paired t-Test Measuring Statistical Significance

Paired t-Test with Likelihood [confidence interval (CI, %)] that modified Absolute
Gradient count (Equation 21) is statistically different than other thresholded
gradient functions with regard to accurate location of tissue surfaces.
Eq. Algorithm Training Test Set 1 Test Set 2 Thickness
Test Set
t
(35 df)
CI t
31 df
CI t
(35 df)
CI t (33 df) CI
(3) Absolute Gradient 2.02 97 2.10 98 2.38 99 3.02 100
(4) Squared Gradient 3.02 100 4.00 100 7.32 100 8.07 100
(5) Brenner Gradient 2.71 99 4.61 100 3.42 100 4.31 100
(20) Modified Absolute
Gradient
1.43 92 1.44 92 2.09 98 2.66 99
(22) Filtered Modified
Absolute Gradient
1.00 84 1.79 96 1.78 96 2.66 99
(23) Filtered Modified
Absolute Gradient
Count
1.78 96 1.79 96 2.38 99 3.19 100

df = degrees of freedom

Table 10.

Distribution of Deviation on Test Set #2

Distribution of Deviation of
Automated Surface Location from Manual Surface Location
Test Set #2: 18 Z-stacks (36 Surfaces Located)
Eq. Function 0 μm 1 μm 2 μm >2 μm
Count % Count % Count % Count %
(3) Absolute Gradient 23 64 12 33 0 0 1 3
(4) Squared Gradient 9 25 19 53 7 19 1 3
(5) Brenner Gradient 19 53 16 44 0 0 1 3
(20) Modified Absolute
Gradient
21 58 13 36 2 6 0 0
(21) Modified Absolute
Gradient Count
23 64 12 33 1 3 0 0
(22) Filtered Modified
Absolute Gradient
21 58 13 36 2 6 0 0
(23) Filtered Modified
Absolute Gradient
Count
22 61 12 33 2 6 0 0

4. DISCUSSION AND CONCLUSIONS

The novel finding in this study is the introduction of the MAGC function that allows automatic location of tissue surfaces, which enables automatic placement of geometric probes as well as accurate measurement of section thickness. We note that all methods to determine the just-out-of-focus optical planes using the modified absolute gradient function with a precision equal to +/− 1.0 micron (one optical plane) require the use of a high resolution oil objective-immersion oil combination with depth of focus less than 1 micron. The MAGC function located tissues surfaces within 1 μm of ground truth on average and determined tissue thickness within 1 μm of ground truth on average. To optimize the function parameters, a training algorithm was developed using a set of tissue surfaces identified by a trained user. With optimized parameters, the automated surface location algorithm using the MAGC function meets the criteria for automatic section thickness determination, as required for computerized stereology applications across a range of different studies using different tissues and a variety of staining techniques. The processes automated by the MAGC function are currently performed manually, even in state-of-the-art computerized stereology systems. Automation of these processes using the MAGC function has the potential to dramatically increase throughput of studies to quantify morphometric parameters using unbiased stereological approaches.

Absolute gradient, squared gradient, and Brenner gradient were the only three of the fourteen common functions tested at the start of this study to achieve the goal of locating tissue surfaces with an average tolerance of 1.0 μm relative to ground truth. Furthermore, only two of these conventional functions – absolute gradient and Brenner gradient – measured tissue thickness with an average tolerance of 1.0 μm. Of these two functions, the absolute gradient function achieved the superior performance, as evidenced by the function rankings in Table 2 through Table 5.

Three modifications to the absolute gradient threshold function led to further enhancements in the performance of the absolute gradient function. Addition of pixel-to-pixel comparison in the vertical and horizontal directions improved performance through rotational invariance. For weighting improvement, the squared gradient gave higher weight to relatively high contrast pixels than absolute gradient; nevertheless, absolute gradient performed better than squared gradient. To test whether the performance of absolute gradient could be further improved by eliminated weighting of higher contrast pixels, a simple count function enumerated pixels over the absolute contrast threshold. Under the reasoning that isolated high contrast pixels were most likely “salt and pepper” noise, rather than actual points of focus, a median filter was applied to the intermediary binarized image of the MAG function.

Modifications to the absolute gradient function generated four new functions (see Figure 6), all of which achieved the average tolerance goal of ±1.0 μm for surface location with similar test and training sets. These four functions met the robustness goal by achieving the same tolerance goal for a dissimilar test set; all four modified functions determined tissue thickness within ±1.0 μm average. Thus, the MAGC function achieved higher performance, as assessed by lowest error rate and greatest robustness across different training sets.

The computational complexity to determine focus of an image using the modified functions is Ο(n2), where nis the number of rows or columns of the image. For rotational invariance, the vertical comparison is done in parallel with the horizontal comparison with no increase in complexity. The median filter, however, requires a second pass through the image raster, with the second pass pipelined one row and column behind the first pass, with only a slight constant time increase. With current processing speeds of standard computers, a Z-stack is captured and analyzed in real time, with the step motor speed of the automated stage as the time limiting factor.

With regard to practical application, the Absolute Gradient Focus Function is designed to locate the “just-out-of-focus” focal plane at the upper and lower surfaces of the tissue section with an error that is directly proportional to the resolving power of the objective and the contrast (signal: noise ratio) of stained microstructures in the tissue. While fluorescent immunostaining highlights cells with specific antigens, the approach fails to stain general proteins as required for identification of top and bottom surfaces of cut sections. For this reason the Absolute Gradient Focus Function requires a light general counterstain, e.g., cresyl violet, for automatic measurement of the top and bottom of the sections. Higher resolution objectives, e.g., 100x oil, NA 1.4, provide thinner focal planes and enhanced contrast as compared to lower resolution objectives. For all objectives the advantage of the automatic computerized function over the manual approach is higher measurement precision (higher repeatability) by the same and different investigators, i.e., higher intra- and inter-rater reliability.

Figure 2.

Figure 2

Zoomed in Thresholded Intuitive Focus Curves. Little variation can be seen using full scale so these functions were plotted with the vertical scale magnified to better show curve characteristics.

Figure 4.

Figure 4

Non-Thresholded Statistical Focus Curves

Table 8.

Distribution of Deviation on Training Set

Distribution of Deviation of
Automated Surface Location from Manual Surface Location
Training Set of 18 Z-stacks (36 Surfaces Located)
Eq. Function 0 μm 1 μm 2 μm >2 μm
Count % Count % Count % Count %
(3) Absolute Gradient 17 47 13 36 5 14 1 3
(4) Squared Gradient 17 47 14 39 3 8 2 6
(5) Brenner Gradient 16 44 14 39 5 14 1 3
(20) Modified Absolute
Gradient
15 42 16 44 5 14 0 0
(21) Modified Absolute
Gradient Count
14 39 17 47 5 14 0 0
(22) Filtered Modified
Absolute Gradient
16 44 15 42 4 11 1 3
(23) Filtered Modified
Absolute Gradient
Count
14 39 17 47 5 14 0 0

Table 9.

Distribution of Deviation on Test Set #1

Distribution of Deviation of
Automated Surface Location from Manual Surface Location
Test Set #1: 16 Z-stacks (32 Surfaces Located)
Eq. Function 0 μm 1 μm 2 μm >2 μm
Count % Count % Count % Count %
(3) Absolute Gradient 15 47 14 44 3 9 0 0
(4) Squared Gradient 15 47 12 38 5 16 0 0
(5) Brenner Gradient 12 38 15 47 5 16 0 0
(20) Modified Absolute
Gradient
14 44 15 47 3 9 0 0
(21) Modified Absolute
Gradient Count
17 53 12 38 3 9 0 0
(22) Filtered Modified
Absolute Gradient
16 50 13 41 3 9 0 0
(23) Filtered Modified
Absolute Gradient
Count
17 53 12 38 3 9 0 0

Table 11.

Distribution of Deviation on Combined Test Sets

Distribution of Deviation of Automated Tissue Thickness Determination
from Manual Thickness Determination
Combined Test Sets #1 and #2: 34 Z-stacks
Eq. Function 0 μm 1 μm 2 μm >2 μm
Count % Count % Count % Count %
(3) Absolute Gradient 16 47 11 32 4 12 3 9
(4) Squared Gradient 5 15 17 50 7 21 5 15
(5) Brenner Gradient 12 35 16 47 3 9 3 9
(20) Modified Absolute
Gradient
13 38 12 35 7 21 2 6
(21) Modified Absolute
Gradient Count
16 47 12 35 4 12 2 6
(22) Filtered Modified
Absolute Gradient
13 38 14 41 5 15 2 6
(23) Filtered Modified
Absolute Gradient
Count
14 41 14 41 4 12 2 6

Acknowledgments

The present study is supported by a Small Business Innovative Research (SBIR) from the National Institutes of Health (U.S. Public Health Service), with Dr. Mouton as the Principal Investigator, to develop an automatic approach for the PI’s computerized stereology system (Stereologer), which is commercialized and supported by the Stereology Resource Center, Inc. (Peter R. Mouton, Ph.D., Owner and President. Authors Dmitry Goldgof, Lawrence Hall, Peter R. Mouton, Kurt Kramer are named on a patent application filed by the University of South Florida that covers the work described in this study.

APPENDIX 1.

Algorithm pseudo-code:

  1. Capture images automatically using Stereologer

  2. Start with training Z stacks which have manually determined tissue surfaces

  3. Optimize focus parameters using Nelder mead for thresholded functions and Golden Ratio for non thresholded focus functions.

  4. Determine top and bottom focal planes.

    4.1 Start from top of the stack and move down. Focus of the first image was assessed against the trained focus threshold, and this was repeated for each consecutive image with each previous image designated as the just-out-of-focus image until the threshold is exceeded

    4.2 The algorithm starts from the bottom of the Z-stack and moves up the Z-stack, one image at a time, until the first image with a focus measure over the trained focus threshold was located

REFERENCES

  1. Brenner JF, Dew BS, Horton JB, King T, Neurath PW, Selles WD. An automated microscope for cytologic research a preliminary evaluation. J. of Histochem. Cytochem. 1976;24:100–111. doi: 10.1177/24.1.1254907. [DOI] [PubMed] [Google Scholar]
  2. Bueno-Ibarra MA, Álvarez-Borrego J, Acho L, Chávez-Sánchez M. a. C. n. Fast autofocus algorithm for automated microscopes. Opt. Eng. 2005;44:063601. [Google Scholar]
  3. Dunn OJ, Clark V. Basic statistics: a primer for the biomedical sciences. John Wiley & Sons; Hoboken, N.J.: 2009. [Google Scholar]
  4. Elozory DT. 2011. Using a Focus Measure to Automate the Location of Biological Tissue Surfaces in Brightfield Microscopy. M.S. Thesis, CS & Eng. University of South Florida, Tampa.
  5. Elozory DT, Bonam OP, Kramer K, Goldgof DB, Hall LO, Mangual O, Mouton PR. Automatic location of microscopic focal planes for computerized stereology. Proc. SPIE Progr. Biomed. Opt. Imaging. 2011:7963. [Google Scholar]
  6. Firestone L, Cook K, Culp K, Talsania N, Preston K. Comparison of autofocus methods for automated microscopy. Cytometry. 1991;12:195–206. doi: 10.1002/cyto.990120302. [DOI] [PubMed] [Google Scholar]
  7. Groen FCA, Young IT, Ligthart G. A comparison of different focus functions for use in autofocus algorithms. Cytometry. 1985;6:81–91. doi: 10.1002/cyto.990060202. [DOI] [PubMed] [Google Scholar]
  8. Hamm P, Englmeier KH, Schulz J. Content-based autofocusing in automated microscopy. Image Anal. Stereol. 2010;29:173–180. [Google Scholar]
  9. Hilsenstein V. Robust Autofocusing for Automated Microscopy Imaging of Fluorescently Labelled Bacteria; Digital Image Computing: Techniques and Applications, 2005. DICTA '05. Proceedings 2005.2005. [Google Scholar]
  10. Huang W, Jing Z. Evaluation of focus measures in multi-focus image fusion. Pattern Recognit. Lett. 2007;28:493–500. [Google Scholar]
  11. Krotkov E. Focusing. Int J Comput Vision. 1988;1:223–237. [Google Scholar]
  12. Liu XY, Wang WH, Sun Y. Autofocusing for automated microscopic evaluation of blood smear and pap smear; Intnl Conf. of the EMBS; 2006. pp. 4718–4721. [DOI] [PubMed] [Google Scholar]
  13. Mouton PR. Principles and Practices of Unbiased Stereology: An Introduction for Bioscientists. Johns Hopkins University Press; Baltimore: 2002. [Google Scholar]
  14. Mouton PR. Developmental Neurotoxicology Research. John Wiley & Sons, Inc.; 2011a. Applications of Unbiased Stereology to Neurodevelopmental Toxicology. [Google Scholar]
  15. Mouton PR. Unbiased Stereology: A Concise Guide. Johns Hopkins University Press; Baltimore: 2011b. [Google Scholar]
  16. Mouton PR, Durgavich J, Ingram DK. Automatic estimation of size parameters using verfied computerized stereoanalysis. Image Anal. & Stereology. 2005:41–49. [Google Scholar]
  17. Mouton PR, Gordon M. Stereological and Image Analysis Techniques For Quantitative Assessment Of Neurotoxicology. In: Harry GJ, Tilson HA, editors. Neurotoxicology. 3rd. 3rd Informa Healthcare; New York: 2010. [Google Scholar]
  18. Nayar SK, Nakagawa Y. Shape from Focus. IEEE Trans. Pattern Anal. Mach. Intell. 1994;16:824. [Google Scholar]
  19. Osibote OA, Dendere R, Krishnan S, Douglas TS. Automated focusing in bright-field microscopy for tuberculosis detection. J. Microsc. 2010;240:155–163. doi: 10.1111/j.1365-2818.2010.03389.x. [DOI] [PMC free article] [PubMed] [Google Scholar]
  20. Pech-Pacheco JL, Cristobal G, Chamorro-Martinez J, Fernandez-Valdivia J. Diatom autofocusing in brightfield microscopy: a comparative study; 15th Intnl Conf on Pattern Rec.2000. [Google Scholar]
  21. Press WH. Numerical recipes in C: The art of scientific computing. Cambridge University Press; Cambridge [Cambridgeshire]; New York: 1988. [Google Scholar]
  22. Santos A, Ortiz de Solórzano C, Vaquero JJ, Peña JM, Malpica N, Del Pozo F. Evaluation of autofocus functions in molecular cytogenetic analysis. J. Microsc. 1997;188:264–272. doi: 10.1046/j.1365-2818.1997.2630819.x. [DOI] [PubMed] [Google Scholar]
  23. Shen F, Hodgson L, Price JH, Hahn KM. Digital differential interference contrast autofocus for high-resolution oil-immersion microscopy. Cytometry Part A. 2008;73A:658–666. doi: 10.1002/cyto.a.20558. [DOI] [PubMed] [Google Scholar]
  24. Sun Y, Duthaler S, Nelson BJ. Autofocusing in computer microscopy: Selecting the optimal focus algorithm. Microsc. Res. Tech. 2004;65:139–149. doi: 10.1002/jemt.20118. [DOI] [PubMed] [Google Scholar]
  25. Sun Y, Duthaler S, Nelson BJ. Autofocusing algorithm selection in computer microscopy; IEEE Intnl Conf on Intelligent Robots and Systems..2005. [Google Scholar]
  26. Tamhane AC, Dunlop DD. Statistics and data analysis: from elementary to intermediate. Prentice Hall; Upper Saddle River, NJ: 2000. [Google Scholar]
  27. Tenenbaum JM. 1970. Accommodation in computer vision. Ph.D. Thesis, CS, Stanford University.
  28. Vollath D. Automatic focusing by correlative methods. J. Microsc. 1987;147:279. [Google Scholar]
  29. Yuste R, Konnerth A. Imaging in neuroscience and development: a laboratory manual. Cold Spring Harbor Laboratory Press; Cold Spring Harbor, N.Y.: 2005. [Google Scholar]

RESOURCES