# Searching algorithm of theodolite auto-focusing based on compound focal judgment

- Chun-tong Liu
^{1}, - Zhen-xin He
^{1}Email author, - Ying Zhan
^{1}and - Hong-cai Li
^{1}

**2014**:110

https://doi.org/10.1186/1687-1499-2014-110

© Liu et al.; licensee Springer. 2014

**Received: **16 June 2014

**Accepted: **30 June 2014

**Published: **9 July 2014

## Abstract

Focusing of search judgment is one of the important parts of theodolite image measurement. Traditional hill-climbing search algorithm cannot usually focus accurately due to the interference of the evaluation function of the local extremum affected by measuring environment, such as light illumination. A compound auto-focal judgment combining image definition evaluation function and modulation transfer function (MTF) auxiliary function was introduced to improve the hill-climbing method. Definition evaluation function and MTF values of images were considered to judge the search direction together. Slanted-edge method was improved to calculate the image MTF values accurately based on the auto-selection of slanted-edge area. Lastly, the principle and implementation of the improved algorithm were given. In the theodolite auto-focusing system, the system imaging effect was validated, and different initial position and circumstances were considered using the proposed searching algorithm. The experiment results of theodolite auto-focus system show that the improved hill-climbing search algorithm can effectively eliminate the local extremum disturbance and make the system search focusing accurate and reliable.

## Keywords

## 1 Introduction

There are some special functions of auto-theodolite with auto-leveling and centering, auto-axis rotation, auto-error compensation, auto-focusing, and wireless communication and signal and processing. Signal processing of images using auto-focusing is the basis for the theodolite measurement data communication and processing. With the auto-focusing technology applied universally in the digital imaging system, it has been the research focus to estimate the images definition effectively and quickly. Focusing is the important process to obtain the clear target images in the imaging system.

Compared with the traditional auto-focus technology, the auto-focus technology based on the digital image processing is attractable for its no additional hardware [1, 2]. Its principles are to select the appropriate image clarity evaluation function according to the different environment, to evaluate the collected images, and then to drive the focusing mechanism to arrive at the focal position quickly and accurately according to the specific searching algorithm.

With the development of computer technology and image processing theory, the auto-focus technology based on the image processing has been continuously developed, and it is the trend of the current auto-focus technology. To improve the focus speed, Subbarao et al. put forward the defocus depth method based on the spatial domain convolution and the deconvolution transform, which is realized within the space and improved the focus speed obviously compared with the frequency domain [3]. Kehtarnavaz et al. chose the square gradient function to measure high-frequency component in the defocused image. The rule-based searching method is used to search for the focusing position of the lens, which is applied to the digital camera [4]. Gamadia et al. proposed an auto-focus method under low light, which adopted the image enhancement method to increase the contrast of the image, and the image contrast was measured by designing the focusing evaluation function [5]. For the different contrasts, an auto-focus method which is applied to television cameras was proposed [6]. Li et al. proposed an improved Canny edge detection algorithm and improved the image edge details of the image signal and suppressed the false edge by using the wavelet transform and adaptive median filter [7]. Combining with the defocus depth method, Qi et al. proposed a focus depth method [8]. This method was used to estimate the image defocusing amount in three positions and adjust the camera directly to the focus location nearby, and then search for the best focus position with a small step. With the characteristic superiority of accuracy, this method can improve the focus speed by 37%. Han et al. put forward the Zernike's orthogonal auto-focus algorithm to avoid losing ideal characteristics of the focusing curve and being trapped in the local minima [9].

From the perspectives of the image clarity evaluation function, the focus search algorithm, and the environmental adaptability of the algorithm, there are three research focuses in auto-focus system based on the image processing. They are as follows: to improve the measurement precision of the focusing system, to shorten the time of work, and to enhance its anti-interference ability. At present, the common auto-focus searching algorithms include the hill-climbing algorithm, Fibonacci searching algorithm, and the curve fitting algorithm [10, 11]. Among those algorithms, the hill-climbing algorithm with the inspired selective characteristic has been widely used to search for the best focus point in practical application. However, the hill-climbing search algorithm can only provide the relative indicators of the image sharpness, and the sharpness evaluation is vulnerable to the noise interference, which can make the result appear to the local peaks.

Based on the analysis of the three-point hill-climbing search algorithm and its shortcomings, this article puts forward the auto-focus searching algorithm based on the compound focal judgment, which adds the image modulation transfer function (MTF) with the normal focusing evaluation function to judge the focal position of the image synthetically, which enhances the reliability of the automatic focus and avoids the local peak phenomenon. Meanwhile, to improve the calculation precision of the MTF and the automation of the edge area selection, an improved calculation method of the MTF edge is adopted for the theodolite aiming system. On the basis of the principle analysis, the superiority of this algorithm will be demonstrated in the experiment. Finally, a wireless communication platform is designed experimentally.

## 2 The MTF calculation based on the image

### 2.1 The theoretical basis of MTF

MTF can be used to describe the quality of optical remote sensor and to evaluate the various aspects of imaging, and it can exist in the form of spatial frequency function at the same time, so it is more authoritative to evaluate the quality of imaging system than the method only with a certain amount of digital image, such as resolution. After years of practice, the method of evaluating the quality of the optical system using image MTF has been widely accepted and used [12].

*o*(

*x*,

*y*), and the corresponding intensity in the focal plane is

*i*(

*x*′,

*y*′). It satisfies

*O*(

*u*,

*v*) and

*I*(

*u*,

*v*) are the Fourier transforms of

*o*(

*x*,

*y*) and

*i*(

*x*′,

*y*′);

*u*and

*v*are the frequency values along two axes' directions; OTF(

*u*,

*v*) is the Fourier transforms of PSF(

*x*,

*y*), which is called optical transfer function and it can be described as

where LSF(*x*) is the line spread function of the system; MTF(*u*) is the mold of OTF(*u*); PTF(*u*) is the phase angle of OTF(*u*), which is called phase transfer function.

From (6) and (7), we know that that the light intensity of the image is attenuated in amplitude MTF(*u*) times compared with that of the object. Therefore, MTF contains the transfer ability of the optical system and reflects the imaging quality of the system in the frequency domain comprehensively. The scene’s details are reflected by the high-frequency part; the scene’s gradations are reflected by the mid-frequency part; and the scene’s outline is reflected by low frequency.

### 2.2 The knife-edge method of MTF

As the absolute index of the system focus, the calculating method of MTF based on the image must be high-precision and operability. Knife-edge method is commonly used for MTF calculation based on the image, but it usually needs to select the edge area manually [13], which makes the calculation not be fully automated. Traditional knife-edge method requires the knife-edge line being perpendicular to the pixels, but it is impractical. Rotating a certain angle is a common method to make the knife edge vertical before calculating MTF [14], which increases the algorithm complexity and affects the calculation accuracy due to sawtooth effect caused by the image rotation. The improved knife-edge method is more reasonable and efficient to automatically select the knife-edge area. Meanwhile, the high-precision MTF calculation can be completed for the oblique edge without the image rotation. The MTF calculation steps are given as follows:

*Selecting the knife-edge area automatically*. Detect the edge areas of the collected image to obtain the binary image. Then the binary image is detected by Hough line. From many areas in the original image, the areas with the suitable length and width are selected. The extracted effect of the knife-edge area is shown in Figure 1.

Step 2. *Building distance-gray relationship*. The gray center of each line within the edge area is fitted linearly to get the edge contour line. By calculating the vertical distance between each pixel and the edge contour line, the function between the distance and the pixel grey is obtained to depict the pixel distribution diagram. This step ensures that the algorithm can be applicable to the MTF calculation of the vertical edge and the inclined edge without image rotation.

*Fitting the ESF curve*. Edge spread function (ESF) is the light intensity distribution function of the knife-edge image. LSF is the differential value of ESF. As the pixel distribution is easily influenced by the noise, ESF model should be constructed to fit ESF curve close to reality. The polynomial function, the composite function, and Fermi function are the common function models [15]. Due to the small knife-edge area and the small amounts of edge data, Fermi function is selected to fit ESF curve in this research, which is suitable for the small amounts of data and has the strong ability of noise suppression. Fermi function is expressed as follows:

*The calculation of MTF*. ESF curve can be disposed as follows: derivate to get LSF curve; discrete LSF; make one-dimensional Fourier transform; get the modulus and make it normalized, whose result is the MTF value of response frequency. Generally, the spatial frequency needs to be normalized. The value of 1 represents the cut-off frequency, and 0.5 represents the half of the cut-off frequency, namely, Nyquist frequency. To verify the features of MTF definition, a sequence of target images from the fuzzy defocusing to the clear focusing by charge-coupled device (CCD) camera are shown in Figure 3. MTF curve of these images is shown in Figure 4.For the image sequence, the MTF values of Figure 3a,b,c,d at the Nyquist frequency are 0.0019, 0.0049, 0.0996, and 0.0049, respectively. It proves that the greater the degree of defocus is, the more ambiguous the image will be, the faster the MTF curve will fall, and the smaller the MTF values at the Nyquist frequency will be. Therefore, the MTF values at the Nyquist frequency are available as the accessorial evaluation criterion of image resolution.

## 3 Design of improved auto-focusing algorithm

### 3.1 The choice of focusing evaluation function

### 3.2 Three-point hill-climbing search algorithm

### 3.3 The principle and implementation of the improved focusing algorithm

Step 1. MTF values of the collected images at the Nyquist frequency is MTF_{Nyquist}, and *M* = *α* MTF_{Nyquist} (0.90 ≤ *α* ≤ 1) is stored as the focal judgment standard.

Step 2. Focusing mechanism operates from the nearest position (or the farthest) with a large step *L*_{n}(*n* = 1,2,3…, the *n* th step focal action). Brenner evaluation function values of the collected images are calculated. Comparing the evaluation function values of the three images, if three evaluation function values are increasing, focusing is continued along the original direction with the step length *L*_{n}; if decreasing, focusing is carried out along the opposite direction with the smaller the step length *L*_{n + 1} = *βL*_{n} (0 < *β <* 1; *β* can be determined by the experiment); If equal, focusing is continued along the original direction with the original step length. The above process is ending until *L*_{n} < *ϵ* (*ϵ* is the setting accuracy).

Step 3. When the focusing mechanism stops, the images are collected and the evaluation function values *f*(*m*)(*m* = 1,2,3…, show it had detected the peak point *m P*_{m}) and MTF values *M*_{m} at the Nyquist frequency are calculated, If *M*_{m} ≥ *M*, the place is the focus position, and then the focusing process is completed. If *M*_{m} < *M*, the place is the local peak point, and then the focusing mechanism continues to focus with the step length *L*_{1} according to the initial state. If the focus function value in the new location is greater than the max{*f*(1), *f*(2)… *f*(*m*)}(*m* = 1,2,3…), it has been out of the scope of local peaks, and then focusing mechanism continues along the opposite direction (the direction of the focal length decreasing); otherwise, it moves along the direction of the focal length increasingly.

Step 4. Follow step 2 and carry out focusing. When the maximum is detected, the focusing mechanism is stopped. The movement direction and step length are judged as is described in step 3.

Step 5. Repeat steps 2, 3, and 4 until the *M*_{m} ≥ *M*. The whole focusing process is completed.

## 4 Automatic focusing experiments

### 4.1 Resolution board imaging experiment of automatic focusing system

### 4.2 The contrast experiment of the focusing performance with different initial positions

_{Nyquist}, and select the appropriate value of

*α*; (2) regulate the focusing hand wheel to the close focal position. Four group experiments are designed, and the original positions of the focusing hand wheel are set at 0°, 2°, 4°, and 6° respectively. The before and after automatic focus images of group 1 are compared and analyzed. Figure 10 shows the contrast images.The results show the focusing effect is significant, and the clear images can satisfy the target recognition and measurement requirements of the system. The prism replaces the benchmarking by using the same method and carrying out steps 1 and 2. The contrasted prism images before and after auto-focusing are shown in Figure 11.From Figures 10 and 11, the collected images after focusing are both clear for the different aiming targets, and the method has the strong adjustability for the targets.Brenner function value curves in benchmarking focusing of the four groups are shown in Figure 12.

**The focusing results**

List | 1 | 2 | 3 | 4 | AV | SD |
---|---|---|---|---|---|---|

Brenner | 0.9883 | 0.9994 | 0.9963 | 1.00 | 0.9960 | 0.0093 |

MTF | 0.1364 | 0.1405 | 0.1389 | 0.1416 | 0.1394 | 0.0039 |

It is known that the standard deviation is small, which shows that the four focusing results are very similar. The result is satisfying from the focal images of four group experiments. The standard deviation of the normalized Brenner value and the MTF values shows that the algorithm can be used to realize automatic focus effectively, and it is repeatable and stable under the different defocusing levels. The total focusing time mainly includes image acquisition and processing, the control signal transmission, and the motor running, and delay. Among them, the motor running time is the main factor that affects the system focusing time. To prevent conflict between signals, each running needs 0.2 s delay; the adjustment steps of the machine are related to the initial defocusing state of the system, which may also affect focusing time. In the focusing experiment, the adjustment steps of focus motor are about 21 to 25 s, and the average time of four group experiments is 12 s, which satisfies the time requirements of the theodolite auto-focusing.

### 4.3 The searching algorithm experiment with the environment change

The experimental analysis shows that this algorithm has the strong anti-interference ability in the actual application, which can improve the auto-focusing reliability of theodolite and that of other photoelectric equipments in a complex environment.

### 4.4 Reliability experiment of the proposed MTF estimation method

### 4.5 Wireless communication platform design

## 5 Conclusions

The searching algorithm of theodolite auto-focusing based on compound focal judgment can eliminate disturber effectively, avoid the local undulation of the focusing estimation function, and improve the auto-focusing reliability by combining the common images definition estimation function and MTF value of images. The improved knife-edge method can solve the MTF value of images accurately and automatically to provide the focusing reference. Meanwhile, the proposed searching algorithm supports the theodolite auto-focusing based on the image processing in the theory. The experiment results show that the proposed algorithm can satisfy the theodolite auto-focusing requirements from the perspectives of the focus precision, the focus time, and the focus reliability. The proposed algorithm can be also adopted in other photoelectricity equipments.

## Declarations

## Authors’ Affiliations

## References

- Moscaritolo M, Jampel H, Knezevich F, Zeimer R: An image based auto-focusing algorithm for digital fundus photography.
*Med. Imag.*2009, 28(11):1703-1707.View ArticleGoogle Scholar - Florea C, Florea L: A parametric non-linear algorithm for contrast based auto-focus. In
*International Conference on Intelligent Computer Communication and Processing*. Cluj-Napoca; 2011:267-271.Google Scholar - Chen C:
*Study on strategy of long-range rapid auto-focusing for image-based three dimension measurement system, Thesis*. Shanghai Jiao Tong University, Shanghai; 2009.Google Scholar - Kehtarnavaz N, Oh HJ: Development and real-time implementation of a rule-based auto-focus algorithm.
*Real-Time Imag.*2003, 9: 197-203.View ArticleGoogle Scholar - Gamadia M, Kehtarnavaz N, Roberts-Hoffman K: Low-light auto-focus enhancement for digital and cell-phone camera image pipelines.
*IEEE Trans. Consum. Electron.*2007, 53(2):249-257.View ArticleGoogle Scholar - Hu F, Chang Y, Ma Y, Zhao G: Development of video automatic focus method.
*Acta. Photonica. Sinica.*2010, 39(10):1901-1906.View ArticleGoogle Scholar - Li J, Ma Y, Zhao F, Guo L: A novel arithmetic of image edge detection of Canny operator.
*Acta. Photonica. Sinica.*2011, 40(1):50-54.View ArticleGoogle Scholar - Li Q, Feng H, Xu Z: Method of improving autofocus speed based on defocus estimation.
*J. Optoelectronics Laser*2005, 16(7):850-853.Google Scholar - Han R, Wang J, Nie K, Liu Y: Adaptive autofocus technique under different contrast.
*Acta. Photonica. Sinica.*2011, 41(2):222-227.Google Scholar - Xie X, Zhou J, Wu Q: An adaptive autofocus method using no-reference structural sharpness.
*Opto-Electron. Eng.*2011, 38(2):84-89.MathSciNetGoogle Scholar - Hu T, Chen S, Liu G, Pu Z: Algorithm of rapid auto-focusing with a long-range.
*J. Optoelectronics Laser*2006, 17(4):474-467.Google Scholar - Liao J, Gao X, Liang W: Dynamic MTF analysis and research for aerial camera.
*Acta. Photonica. Sinica.*2011, 44(5):679-683.View ArticleGoogle Scholar - Li T:
*Research on modulation transfer function calculation and remote sensing image restoration based on slanted-edge method, Dissertation*. Zhejiang University, Hangzhou; 2011.Google Scholar - Lu Z:
*The automatic image-based real-time focusing research in pushbroom remote sensing camera, Dissertation*. Changchun Institute of Optics, Fine Mechanics and Physics, Chinese Academy of Science, Changchun; 2012.Google Scholar - Wang Y, Mao J: A simple method for calculating Fermi function with MATLAB and numerical approximation.
*Infrared*2008, 29(8):34-36.Google Scholar - Shi H, Shi Y, Yang S: Evaluation and selection of estimating function for auto-focus system of optical microscope.
*J. Comput.-Aided Des. Comput. Graph.*2013, 25(2):235-240.Google Scholar - Wang J, Chen H, Zhou G, An T: An improved Brenner algorithm for image definition criterion.
*Acta. Photonica. Sinica.*2012, 41(7):855-858.View ArticleGoogle Scholar - Liu J, Gao M:
*Optical design*. National Defense Industry, Beijing; 2012.Google Scholar

## Copyright

This article is published under license to BioMed Central Ltd. This is an Open Access article distributed under the terms of the Creative Commons Attribution License (http://creativecommons.org/licenses/by/4.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original work is properly credited.