-
Tenengrad 函数是由Sobel算子提取像素点水平方向和垂直方向的梯度值构成,如公式(1)、(2)所示,并为梯度设置一个阈值T调节函数的灵敏度,表达式如下:
$$ F{\text{ = }}\sum\limits_x {\sum\limits_y {G(x,y)} } (G(x,y) > T) $$ (1) 式中:
$G(x,y)$ 为像素点$(x,y)$ 处的梯度。$$ G(x,y) = \sqrt {G_x^2(x,y) + G_y^2(x,y)} $$ (2) 式中:
${G_x}(x,y)$ , 和${G_y}(x,y)$ 为像素点水平方向和垂直方向的梯度值,定义为公式(3)和公式(4):$$ {G_x}(x,y) = f(x,y) * {g_x} $$ (3) $$ {G_y}(x,y) = f(x,y) * {g_y} $$ (4) 式中:f(x,y)为图像像素点;
$ * $ 为卷积符号;${g_x}$ 、${g_y}$ 为Sobel算子水平方向、垂直方向模板。$$ {g_x} = \left[ {\begin{array}{*{20}{c}} { - 1}& { - 2}& { - 1} \\ 0&0&0 \\ 1&2&1 \end{array}} \right] $$ (5) $$ {g_y} = \left[ {\begin{array}{*{20}{c}} 1&0&{ - 1} \\ 2&0&{ - 2} \\ 1&0&{ - 1} \end{array}} \right] $$ (6) -
文中改进 Sobel 算子是增加了两个方向的算子,分别是将水平方向、垂直方向模板旋转45°的模板,改进后的两个方向Sobel算子模板如公式(7)、(8)所示:
$$ {d_1} = \left[ {\begin{array}{*{20}{c}} { - 2}& { - 1}&0 \\ { - 1}&0&1 \\ \;\;\;0&1&2 \end{array}} \right] $$ (7) $$ {d_2} = \left[ {\begin{array}{*{20}{c}} 0&{ - 1}&{ - 2} \\ 1&\;\;\;0&{ - 1} \\ 2&\;\;\;1&\;\;\;0 \end{array}} \right] $$ (8) 将这4个方向的Sobel算子对图像像素点
$f(x,y)$ 进行边缘检测,计算出梯度进行加权获得整个图像的梯度。公式如下:$$ G(x,y) = \sqrt {\alpha \cdot \mathop X\nolimits^2 (x,y) + \beta \cdot \mathop Y\nolimits^2 (x,y)} $$ (9) $$ X(x,y) = {G_x}(x,y) + \frac{{{{{D}}_1}(x,y) - {{{D}}_2}(x,y)}}{2} $$ (10) $$ Y(x,y) = {G_y}(x,y) + \frac{{{{{D}}_1}(x,y) + {{{D}}_2}(x,y)}}{2} $$ (11) $$ {{{D}}_{\text{1}}}{\text{(}}x,y{\text{) = }}f(x,y)*{d_1} $$ (12) $$ {{{D}}_{\text{2}}}(x,y){\text{ = }}f(x,y)*{d_2} $$ (13) 式中:
${G_x}(x,y)$ 为水平方向的边缘梯度;${G_y}(x,y)$ 为垂直方向的边缘梯度;${D_1}(x,y)$ 为${g_x}$ 旋转后的边缘梯度;${D_2}(x,y)$ 为${g_y}$ 旋转后的边缘梯度;$X(x,y)$ 为根据公式(10)计算的图像梯度;$Y(x,y)$ 为根据公式(11)计算的图像梯度;$\alpha $ 和$\beta $ 为梯度加权系数。 -
在某镜面偏心测量设备测量头设计工作中,根据其光学设计以及自动调焦的时间要求,文中首先分析其光学函数变化曲线,然后根据光学变化曲线采用变步长两段式聚焦控制方式。并且采用以图像空间域梯度值作为图像清晰度的评价标准,根据图像清晰度评价结果对调焦机构进行控制,实现了研制目标。
-
为了满足设备测量需求,设计可自动调焦的光学镜头,其光学参数如表1所示。
表 1 光学设计参数
Table 1. Optical design parameters
Parameter Value Wave band/μm 7-15 Focal distance/mm 20-100 Rear intercept/mm 15.41 Incoming pupil diameter/mm 20-100 F/# 1.5 Imaging range/m 0.5- +∞ Transfer function > 0.2 Alignment plane +∞ Focusing rang/mm −25- +30 光路图如图3 所示,通过驱动电机的控制,调教组镜片沿着光轴方向运动,调焦行程−25-30 mm,通过变倍和补偿组的配合运动,能够成像焦距达到0.5 m-+∞。图中,1为前固定组,2为变倍组,3为补偿组,4为后固定组,5为调焦组,6为CCD窗口,7为像面。
从理想清晰度评价曲线和光学传递函数变化曲线中可以看出它们具有相同的变化规律,具有单峰性和峰值两侧具有单调性,并且十字丝图像需要提取十字丝中心位置,只有调焦位置最佳才能提高十字丝中心提取的准确度。为了快速找到正焦位置范围以及最佳调焦位置,文中根据光学设计分析采用粗调和精细调焦相结合的快速搜索方式,首先利用粗调方式大步长找到最佳调焦位置附近,然后利用精调方式找到最佳调焦位置,这样既保证调焦速度,又能保证调焦精度,精准找到最佳调焦位置。
-
根据清晰度评价曲线和光学传函数递变化曲线,需要采用与之相匹配的搜索策略,为了提高搜索速度和准确度,文中采用变步长搜索策略。与传统爬山搜索方式相比,首先变步长搜索方式用大步长快速搜索到调焦目标附近,然后采用小步长精细搜索目标,防止错过目标。爬山搜索方式采用大步长搜索会错失调焦准确位置,采用小步长搜索速度不仅慢,而且在离焦状态下受到的环境噪声和光路噪声影响较大,不易聚焦。所以文中选用变步长搜索方式。具体实现步骤如下:
(1)首先,调焦系统起始位置位于离焦点 P ,设定调焦大步长为D(D>调焦精度),记录当前位置图像的调焦评价函数F;
(2)根据步骤(1)的位置P向前以步长D进行运行,获取两步的调焦函数F1、F2;
(3)如果不满足F<F1,F1>F2, 则沿着步长D继续运行,F、F1、F2分别为最后3个位置的调焦函数;
(4)如果满足F<F1,F1>F2,则调焦系统返回到调焦函数F的位置,以步长d(D>d)向前运行,直到满足F<F1,F1>F2,返回到调焦函数F1的位置P2;
(5) P1
的位置为正调焦位置,自动调焦结束。 -
为了验证文中4个方向Sobel算子梯度加权后的检测效果,文中在偏心测量设备上进行检测实验,使用自适应变步长两段式搜索策略与其他算法进行对比实验,归一化后图像清晰度评价曲线对比图见图4。
图 4 归一化后图像清晰度评价曲线对比图
Figure 4. Comparison diagram of image sharpness evaluation curve after normalization
通过自动调焦系统,利用改进Sobel算子梯度加权的Tenengrad 评价函数与经典Sobel算子的Tenengrad 评价函数、Roberts评价函数、Laplacian评价函数、Prewitt评价函数、Canny评价函数和Log评价函数分别进行边缘检测和调焦控制,从边缘检测图像图5可以看出:文中算法进行边缘检测得到的边缘图像信息保留得最好,并在相同的离焦位置进行自动调焦,绘制出它们的图像清晰度评价函数曲线图,分别进行50次自动调焦实验,发现文中算法平均调焦时间是1 242 ms,自动调焦失败率是2%。通过绘制的图像清晰度评价函数曲线对比图和表2可知改进后的算法调焦位置更加准确,速度也更快,效果更好。
表 2 算法对比结果
Table 2. Algorithm comparison results
Algorithm Focusing time/ms Failure rate Proposed 1242 2% Roberts 1381 12% Laplacian 1410 10% Sobel 1332 8% Prewitt 1266 10% Canny 1120 12% Log 1258 8%
Image sharpness evaluation and variable-step fusion focusing method
-
摘要: 十字丝目标在CCD上的成像,一般受到环境光和光路的影响,不同位置的焦距产生的十字丝图像会存在边缘模糊和离焦的情况,使十字目标的中心点位置提取受到严重影响,传统的Sobel算法忽视边缘信息,并且容易受噪声影响,因此提出改进Sobel算子图像清晰度评价函数与粗细调焦结合的变步长两段式快速搜索自动调焦的方法。该方法首先利用图像的空间域评价图像清晰度,其次利用根据光学设计选用的两段式调焦方式。第一步进行粗调,先快速找到正焦位置附近,然后进行细调,直至找到正焦的位置。实验表明,该方法与其他算法相比,自动调焦失败率为2%,调焦时间为1242 ms,调焦行程在−25~+30 mm之间。通过该算法将图像清晰度评价函数与两段式调焦方式结合进行自动调焦,准确性高,实时性好。Abstract: The imaging of the cross wire target on the CCD is generally affected by the ambient light and the optical path. The cross wire image generated by the focal length of different positions will be blurred and out of focus, and the extraction of the center point of the cross wire target will be seriously affected. The traditional Sobel algorithm ignores the edge information and is easily affected by noise. Therefore, a two-stage fast search auto focusing method with variable-step size is proposed, which improves the image sharpness evaluation function of Sobel operator and combines the coarse and fine focusing. The method first evaluates the image sharpness by using the spatial domain of the image, and then selects the two-stage focusing mode according to the optical design. The first step is coarse adjustment. When the focus position is quickly found, fine adjustment is performed until the focus position is found. Experimental results show that compared with other algorithms, the auto focusing failure rate is 2%, the focusing time is 1242 ms, and the focusing stroke is −25-30 mm. The combination of the image sharpness evaluation function and the two-stage focusing mode through this algorithm has high accuracy and good real-time performance.
-
Key words:
- auto focusing /
- sharpness evaluation function /
- variable-step /
- spatial domain /
- optical design
-
表 1 光学设计参数
Table 1. Optical design parameters
Parameter Value Wave band/μm 7-15 Focal distance/mm 20-100 Rear intercept/mm 15.41 Incoming pupil diameter/mm 20-100 F/# 1.5 Imaging range/m 0.5- +∞ Transfer function > 0.2 Alignment plane +∞ Focusing rang/mm −25- +30 表 2 算法对比结果
Table 2. Algorithm comparison results
Algorithm Focusing time/ms Failure rate Proposed 1242 2% Roberts 1381 12% Laplacian 1410 10% Sobel 1332 8% Prewitt 1266 10% Canny 1120 12% Log 1258 8% -
[1] Fan Junjie, Li Fuqiang, Cai Weijun, et al. Design of focusing mechanism for long array focal plane with heavy load [J]. Infrared and Laser Engineering, 2021, 50(11): 20210270. (in Chinese) doi: 10.3788/IRLA20210270 [2] Zhou Enyuan, Cao Yueqin, Shi Jianping, et al. Design of compact dual-field lens for visible light [J]. Infrared and Laser Engineering, 2021, 50(8): 20210042. (in Chinese) doi: 10.3788/IRLA20210042 [3] Guan Wenlu, Tan Fengfu, Jing Xu, et al. Automatic focusing of cassegrain telescope based on environmental temperature feedback [J]. Optics and Precision Engineering, 2021, 29(8): 1832-1838. (in Chinese) doi: 10.37188/OPE.20212908.1832 [4] Lan Tiancheng, Lan Ronghua, Chen Xiaoxi, et al. Research on liquid crystal lens hill climbing autofocus algorithm [J]. Acta Optica Sinica, 2020, 40(14): 1411003. (in Chinese) doi: 10.3788/AOS202040.1411003 [5] Mo Chunhong, Liu Bo, Ding Lu, et al. A gradient threshold auto-focus algorithm [J]. Infrared and Laser Engineering, 2014, 43(1): 323-327. (in Chinese) doi: 10.3969/j.issn.1007-2276.2014.01.057 [6] Hong Yuzhen, Ren Guoqiang, Sun Jian. Analysis and improvement on sharpness evaluation function of defocused image [J]. Optics and Precision Engineering, 2014, 22(12): 3401-3408. (in Chinese) doi: 10.3788/OPE.20142212.3401 [7] Zou Yutong, Tan Yi, Luo Yihan. Research on image clarity evaluation function based on improved Sobel operator in focusing system [J]. Electronic Design Engineering, 2022, 30(7): 150-155. (in Chinese) doi: 10.14022/j.issn1674-6236.2022.07.031 [8] Ding Guoshen, Qiao Yanli, Yi Weining, et al. Feature extraction and matching of F-SIFT based on spectral image space [J]. Optics and Precision Engineering, 2021, 29(5): 1180-1189. (in Chinese) doi: 10.37188/OPE.20212905.1180 [9] Liu Mengchen, Pang Changtao, Hao Xue. Research of sobel operator in clarity evaluation process of film hole image [J]. Mechanical Science and Technology for Aerospace Engineering, 2020, 39(7): 1071-1076. (in Chinese) doi: 10.13433/j.cnki.1003-8728.20190223 [10] Zhang Huaili, Li Yingchun, Zhang Tinghua. Method of variable speed control for focusing mechanism limited interval based on image definition function [J]. Journal of Applied Optics, 2021, 42(6): 969-974. (in Chinese) doi: 10.5768/JAO202142.0601004 [11] 林兆华. 基于图像处理自动调焦技术在经纬仪中应用的研究[D]. 中国科学院研究生院(长春光学精密机械与物理研究所), 2012. Lin Zhaohua. Study on application of the autofocus technology based on the imaging processing in the theodolite[D]. Changchun: University of Chinese Academy of Sciences (Changchun Institute of Optics, Fine Mechanics and Physics, Chinese Academy of Sciences), 2012. (in Chinese) [12] Zhou R G, Liu D Q. Quantum image edge extraction based on improved sobel operator [J]. International Journal of Theoretical Physics, 2019, 58(9): 1-17. [13] 刘雪超. 基于数字图像处理的自动调焦技术研究[J]. 中国科学院研究生院(长春光学精密机械与物理研究所), 2014. Liu Xuechao. Study on auto-focusing based on digital image processing technology[D]. Changchun: University of Chinese Academy of Sciences(Changchun Institute of Optics, Fine Mechanics and Physics, Chinese Academy of Sciences), 2014. (in Chinese) [14] Yuan Yicong, Hao Junming. An algorithm for judging the depth of image defocusing used for infrared automatic focusing [J]. Infrared, 2021, 42(11): 33. (in Chinese) [15] Wu Helong, Qiu Zheng. Edge detection of SAR image method based on curvelet transformand sobel operator [J]. Ship Electronic Engineering, 2021, 41(5): 101-103, 142. (in Chinese) doi: 10.3969/j.issn.1672-9730.2021.05.023