1 Introduction

Machine vision systems are an attractive solution for the inspection process in automated mass production lines due to their high throughput, good reliability, and relatively low cost [1, 2]. In practice, such systems require a highly precise autofocusing capability in order to obtain sufficiently sharp images of the object of interest. Thus, many sophisticated autofocusing schemes have been proposed in recent decades [37]. Generally speaking, these schemes utilize either optics-based (i.e., hardware) approaches [817] or image-based (i.e., software) methods [1831].

However, existing autofocusing schemes generally achieve a satisfactory focusing performance over only a limited range. Accordingly, in a previous study [32], the present group proposed a novel autofocusing microscope with two optical paths capable of providing both a rapid response and a large linear autofocusing range [32]. However, with the continuing trend toward device miniaturization, it is necessary to improve the focusing accuracy of autofocusing microscopes yet further. Consequently, in the present study, the autofocusing performance of the microscope presented in [32] is further improved by replacing the achromatic lenses in the original design with two cylindrical lens assemblies. The performance of the modified microscope is characterized numerically using commercial ZEMAX software and is then verified experimentally using a laboratory-built prototype.

The remainder of this paper is organized as follows. Section 2 describes the structure of the optics-based autofocusing microscope proposed in [32] based on two achromatic lenses. Section 3 introduces the optics-based autofocusing microscope proposed in the present study. Section 4 describes the numerical evaluation of the proposed microscope and compares its performance with that of the microscope proposed in [32]. Section 5 discusses the experimental characterization of the proposed microscope using a laboratory-built prototype. Finally, Sect. 6 presents some brief concluding remarks.

2 Design of original optics-based autofocusing microscope

This section reviews the basic structure and mathematical background of the autofocusing microscope proposed by the present group in [32].

2.1 Conventional autofocusing method with achromatic lens

Figure 1 presents a schematic illustration of the optical path within a conventional optics-based autofocusing microscope containing a single achromatic lens. When the laser beam strikes point A on the sample surface (located at focal plane F of the objective lens), it is reflected from the surface and is then incident on the CCD sensor at point A′. When the sample surface is moved from plane F to plane O (corresponding to a displacement of +δ), the laser beam strikes point C on the sample surface and is then reflected. The reflected beam intersects plane F at point A1 and is then incident on the CCD sensor at point A1′. From basic geometric principles, the following equation can be obtained:

$$\varDelta = \delta \frac{{2df_{2} }}{{f_{1}^{2} }} = \delta \frac{2dK}{{f_{1} }} ,$$
(1)

where Δ is the distance between point A′ and point A1′, f 2 is the effective focal length of the achromatic lens, f 1 is the focal length of the objective lens, d is the radius of the collimated laser beam, and \(K( = f_{2} /f_{1} )\) is the overall magnification of the objective lens and achromatic lens. Equation (1) shows that the shift distance Δ and displacement δ are linearly related.

Fig. 1
figure 1

Schematic illustration of optical path in conventional optics-based autofocusing microscope with achromatic lens [1]

Figure 2 illustrates the shape of the laser spot on the CCD sensor surface given various values of the defocus distance. Note that in the figure, points (X c, Y c) and (x centroid, y centroid) represent the positions of the geometrical image center and the centroid of the image captured by the CCD sensor, respectively. The image centroid coordinates can be expressed as

$$x_{\rm centroid} = \frac{{\sum {\sum {xP_{ij} } } }}{{\sum {\sum {P_{ij} } } }},$$
(2)
$$y_{\rm centroid} = \frac{{\sum {\sum {yP_{ij} } } }}{{\sum {\sum {P_{ij} } } }},$$
(3)

where i and j are the row number and column number of the CCD image, respectively, and P ij is the intensity of the pixel located at the intersection of row i and column j. From Eqs. (1), (2) and (3), it is seen that if the image intensity P ij remains constant over the entire CCD image, a linear relationship exists between the centroid of the image captured by the CCD sensor and the defocus distance, δ. Exploiting this linear relationship, an autofocusing capability can be achieved by driving the objective lens using a position feedback signal based on the centroid coordinates of the detected image [32, 33].

Fig. 2
figure 2

Schematic representation of laser spot on CCD sensor surface given different values of defocus distance [1]

2.2 Original autofocusing microscope with two optical paths

Figure 3 shows the basic structure of the autofocusing microscope proposed by the present group in [32]. As shown, the microscope contains two separate optical paths, namely Path I and Path II. In Path I, the light beam emerging from the beam splitter is passed through an achromatic lens and is then incident on a CCD sensor (referred to hereafter as CCD1). Meanwhile, in Optical Path II, the light beam passes through another achromatic lens and is then incident on a second CCD sensor (referred to hereafter as CCD2). From Eqs. (1), (2) and (3), it follows that for a constant displacement Δ of the incident point on the sensing surfaces of the two CCDs, the defocus distance δ changes in accordance with changes in the focal length f 2 of the corresponding achromatic lens. Therefore, in constructing the microscope, CCD1 and CCD2 are taken as identical components, but the achromatic lenses used in Optical Paths I and II, respectively, are different. Specifically, the focal length of the achromatic lens in Optical Path II is greater than that of the achromatic lens in Optical Path I, i.e.,

Fig. 3
figure 3

Structure of autofocusing microscope comprising two optical paths with achromatic lenses [32]

$$\varDelta = \delta_{\rm I} \frac{{2df_{{2{\rm I}}} }}{{f_{1}^{2} }},$$
(4)
$$\varDelta = \delta_{\rm I} \frac{{2df_{{2{\rm II}}} }}{{f_{1}^{2} }},$$
(5)
$$f_{{2{\rm II}}} > f_{{2{\rm I}}},$$
(6)
$$K_{\rm I} = f_{{2{\rm I}}} /f_{1},$$
(7)
$$K_{\rm II} = f_{{2{\rm II}}} /f_{1}.$$
(8)

Note that Eqs. (4) and (5) refer to Optical Path I and Optical Path II, respectively, and \(f_{{2{\rm I}}}\) and \(f_{{2{\rm II}}}\) are the effective focal lengths of the achromatic lenses in Optical Paths I and II, respectively. Optical Path II results in a greater total magnification K II and therefore provides the means to accomplish autofocusing over a short linear range, but with a high focusing accuracy. By contrast, Optical Path I yields a lower total magnification K I and therefore provides the means to accomplish autofocusing over a longer linear range, but with a reduced focusing accuracy. In realizing the microscope shown in Fig. 3, the two optical paths are combined using a self-written autofocus-processing algorithm in order to achieve a rapid autofocusing capability over a large linear autofocusing range without any loss in the focusing accuracy. (Note that for a more comprehensive description of the proposed system, the reader is referred to [32]).

3 Proposed optics-based autofocusing microscope with cylindrical lenses

Figure 4 illustrates the structure of the autofocusing microscope proposed in the present study, in which the two achromatic lenses in the original microscope are replaced by two cylindrical lens assemblies. As shown, the light beam emitted by the laser (Thorlabs HL6501MG, 658 nm) is expanded and collimated by means of a lens and is then bisected by a knife such that its cross section has the form of a semicircle. The light beam is passed through a beam splitter (BS1), a 45° red dichroic filter and an objective lens, and is then incident on the sample surface. The light is reflected from the surface and passes back through the objective lens, filter and BS1, and is then incident on a second beam splitter (BS2), where it is split into two optical paths, namely Path I and Path II. In Optical Path I, the light beam is passed through a lens assembly comprising two cylindrical lenses, CL1 and CL2, placed at right angles to one another, and is then incident on CCD1 (Basler scA1400-17 fm, pixel size of 7.3 μm). Meanwhile, in Optical Path II, the light beam emerging from BS2 enters a third beam splitter (BS3) and is then passed through a second lens assembly consisting of cylindrical lenses CL3 and CL4 before being incident on a second CCD (i.e., CCD2; Basler scA1400-17 fm).

Fig. 4
figure 4

Structure of proposed autofocusing microscope comprising two optical paths with cylindrical lens assemblies

Importantly, the two cylindrical lens assemblies in the proposed design change the geometry of the laser spot incident on the CCD sensors from a semicircle (see Fig. 2) to a semi-ellipse (see Fig. 5). For comparison purposes with the same standard, the total magnification K of the original microscope and proposed microscope are designed as same as possible. From the two cylindrical lens assemblies of the proposed design, the geometry (or both the long axis and short axis) of the laser spot incident on the CCD sensors can be reshaped flexibly. Although the reshaping can be performed with only one cylindrical lens, it is easier to adjust the geometry of the reshaping and get a better image quality of the laser spot by using the two cylindrical lenses assembly. In addition, it is simple to get a value for the focal length, which is not available by stock lenses. In this study, the parameters of the lens assemblies are designed to satisfy the requirement that the geometry of the semi-ellipse is larger than that of the semicircle, so the variation of the centroid position (x centroid, y centroid) with the sensed displacement of the proposed microscope is greater than that of the original microscope. As a result, it improves both the resolution of the autofocusing microscope (i.e., the variation of the centroid (x centroid, y centroid) position with changes in the sensed displacement) and its focusing accuracy. In this study, we use simulation method to design the proposed microscope. It follows the basic principles of geometrical optics and depends on the designed parameters of the proposed microscope, like focal lengths, apertures, etc. In the future, the proposed microscope will be analyzed by using a mathematical model in order to study the relation between the focusing accuracy and the designed parameters of the proposed microscope.

Fig. 5
figure 5

Schematic representation of laser spot on CCD sensor surface given different values of defocus distance in proposed autofocusing microscope

4 Simulation and analysis

4.1 Simulation of proposed optics-based autofocusing microscope with cylindrical lenses

A series of ZEMAX ray-tracing simulations were performed to examine the focusing performance of the proposed autofocusing microscope and to determine suitable values of the main design parameters (e.g., f 1, f 2, K, K II/K I, and so on). Figure 6 illustrates the optical model of the proposed microscope. Table 1 summarizes the selected values of each design parameter. Figure 7 presents the simulation results obtained for the laser spot shapes on CCD1 and CCD2, respectively, given different values of the defocus position.

Fig. 6
figure 6

ZEMAX optical model of proposed autofocusing microscope

Table 1 Design parameters of proposed autofocusing microscope
Fig. 7
figure 7

Simulation results for laser spot on CCD sensor surface given different values of defocus distance in proposed autofocusing microscope

4.2 Simulation of original optics-based autofocusing microscope with achromatic lenses

The simulations were repeated using the original autofocusing microscope with achromatic lenses (see Fig. 3). Note that both microscopes were designed in such a way as to achieve the same overall magnification; K. Figure 8 shows the optical model of the original microscope. Table 2 summarizes the selected values of the various design parameters. Finally, Fig. 9 presents the simulation results obtained for the laser spot shapes on CCD1 and CCD2, respectively, given different values of the defocus position.

Fig. 8
figure 8

ZEMAX optical model of original autofocusing microscope [32]

Table 2 Design parameters of original autofocusing microscope
Fig. 9
figure 9

Simulation results for laser spot on CCD sensor surface given different values of defocus distance in original autofocusing microscope [32]

4.3 Simulation results

Figure 10 presents the simulation results obtained for the variation of the image centroid position with the defocus distance in both the original autofocusing microscope and the proposed microscope, respectively. It is seen that for both microscopes, the change in the centroid coordinates (x centroid , y centroid ) is linearly related to the defocus distance, δ. In other words, the numerical results are consistent with the theoretical analysis presented in Sect. 2. The relationships between the image centroid coordinates (x centroid, y centroid) and the defocus distance δ in Optical Paths I and II of the proposed and original autofocusing microscopes are given, respectively, as follows

Fig. 10
figure 10

Simulation results for variation of image centroid position with defocus distance in original and proposed microscopes

$${\text{Centroid(}}x_{\rm centroid} ,y_{\rm centroid} )= - 0.5185\delta - 0. 2 6 6 3,$$
(9)
$${\text{Centroid(}}x_{\rm centroid} ,y_{\rm centroid} )= - 1.0254\delta + 0. 4 0 4 9,$$
(10)
$${\text{Centroid(}}x_{\rm centroid} ,y_{\rm centroid} )= - 0.2522\delta + 0. 1 7 0 5,$$
(11)
$${\text{Centroid}}(x_{\rm centroid} ,y_{\rm centroid} ) = - 0.5067\delta - 0.2479.$$
(12)

(Note that the four equations were obtained via a linear curve fitting technique performed using Microsoft Excel. The units of centroid and δ are pixel and μm, respectively.) It is noted that the ratios of the slopes of the linear curves in Eqs. (9) and (10) to those of the linear curves in Eqs. (11) and (12) are equal to 2.06 (=0.5185/0.2522) and 2.02 (=1.0254/0.5067), respectively. In other words, the simulation results show that compared with the original microscope with achromatic lenses, the proposed microscope theoretically achieves both a higher focusing resolution (i.e., the variation of the centroid position (x centroid, y centroid) with the sensed displacement) and an improved focusing accuracy.

5 Experimental characterization of proposed autofocusing microscope

The validity of the proposed autofocusing microscope was verified using a laboratory-built prototype equipped with a human–machine interface (HMI) written in LabVIEW (see Fig. 11). Figure 12 presents a flow chart showing the basic steps in the proposed autofocusing procedure and image processing. In our self-written autofocus-processing algorithm, the resolution of the motion table is equal to 0.1 μm. The objective lens can be moved directly via a linear motor (one step of 1 μm, HF-KP053-B series, Chiuan Yan Tech.) featuring a closed-loop control scheme based upon a feedback signal generated with an optical encoder (resolution of 0.1 μm). Therefore, the resolution of the movement is equal to 1 μm (see the ordinates of Figs. 15 and 17). And the final autofocusing position was measured by using a position feedback signal from the optical encoder. This section covers the minimum background necessary for the image processing. For more comprehensive coverage, the reader is referred to Ref. [1].

Fig. 11
figure 11

Photograph of laboratory-built prototype

Fig. 12
figure 12

a Flow chart of autofocus-processing algorithm and b image processing in proposed microscope

Figure 13 shows experimental images of the laser spots on the two CCD sensors given different values of the defocus distance. Finally, Fig. 14 compares the experimental and simulation results for the variation of the image centroid position with the defocus distance in the two optical paths. Figure 14 shows that for both optical paths, the image centroid position varies linearly with the defocus distance δ over a certain defocus range. In addition, it is observed that the experimental results are consistent with the simulation results (presented previously in Sect. 4). From an inspection of the experimental results in Fig. 14, the linear relationships between the image centroid coordinates (x centroid, y centroid) and the defocus distance δ in Optical Paths I and II are given, respectively, by

Fig. 13
figure 13

Experimental images of laser spot on CCD sensor surface given different values of defocus distance

Fig. 14
figure 14

Comparison of experimental and simulation results for variation of image centroid position with defocus distance

$${\text{Centroid(}}x_{\rm centroid} ,y_{\rm centroid} )= - 0.5479\delta + 2. 3 1 5 8,$$
(13)
$${\text{Centroid(}}x_{\rm centroid} ,y_{\rm centroid} )= - 1.0676\delta - 0. 6 0 9 5.$$
(14)

(Note that Eqs. (13) and (14) were again obtained using a linear curve fitting technique.) The ratio of the slope of the linear curve in Eq. (14) to that of the linear curve in Eq. (13) is equal to 1.95 (=1.0676/0.5479). It is noted that this experimental value is in good agreement with the theoretical value of 1.98 (=1.0254/0.5185) obtained from Eqs. (9) and (10).

To demonstrate the practical feasibility of the proposed microscope, an autofocusing experiment was conducted using a mirror sample given initial defocus distances, δ, ranging from 1,000 to +1,000 μm. Figures 15 and 16 show the experimental results obtained for the variations of the measured autofocusing position and the number of objective lens movement times, respectively, as a function of the initial defocus distance. In general, the results show that the objective lens is moved from the initial defocus distance to the final focusing position (yielding a focusing accuracy of ≤1 μm, repeatability of ±1 μm) with the number of movement times of ≤4.

Fig. 15
figure 15

Experimental results for variation of autofocusing position with defocus distance

Fig. 16
figure 16

Experimental results for variation of number of objective lens movement times with defocus distance

For comparison purposes, the experiment was repeated using the same laboratory-built prototype, but with only Optical Path II activated. Figures 17 and 18 show the results obtained for the variations of the measured autofocusing position and the number of objective lens movement times, respectively, as a function of the initial defocus position. It can be seen that when only Optical Path II is activated, the focusing accuracy is again less than ≤1 μm, but the number of focusing times is increased slightly to ≤6. In other words, the use of two optical paths in the proposed autofocusing microscope results in a more rapid autofocusing response. In addition, the results confirm that the focusing accuracy of the proposed microscope, i.e., ≤1 μm, is better than that of the original microscope proposed in [32], i.e., 2 μm.

Fig. 17
figure 17

Experimental results for variation of autofocusing position with defocus distance given use of Optical Path II only

Fig. 18
figure 18

Experimental results for variation of number of objective lens movement times with defocus distance given use of Optical Path II only

6 Conclusions

This study has proposed a novel optics-based autofocusing microscope with two optical paths, where each path incorporates a cylindrical lens assembly and a CCD sensor. The performance of the proposed microscope has been evaluated by means of numerical simulations and an experimental investigation using a laboratory-built prototype. The results have shown that the proposed microscope has a rapid response (≤4 the number of movement times) and a focusing accuracy of ≤1 μm (repeatability of ±1 μm). As a result, the microscope provides a promising solution for a wide range of automated inspection applications.