﻿ 基于数学形态学的木材单板节子识别改进算法
 林业科学  2015, Vol. 51 Issue (9): 90-95 PDF
DOI: 10.11707/j.1001-7488.20150912
0

#### 文章信息

Chen Yongping, Guo Wenjing, Wang Zheng

An Improved Algorithm of Veneer Knot Image Recognition Based on Mathematical Morphology

Scientia Silvae Sinicae, 2015, 51(9): 90-95.
DOI: 10.11707/j.1001-7488.20150912

### 作者相关文章

1. 中国林业科学研究院林业新技术研究所 北京 100091;
2. 中国林业科学研究院木材工业研究所 北京 100091

An Improved Algorithm of Veneer Knot Image Recognition Based on Mathematical Morphology
Chen Yongping1, 2, Guo Wenjing1, Wang Zheng1
1. Research Institute of Forestry New Technology, CAF Beijing 100091;
2. Research Institute of Wood Industry, CAF Beijing 100091
Abstract: [Objective] Knot is an important evaluation index in the classification of wood veneer. The quantity of veneer knots and the maximum knot area can, to some extent, determine the grade of a wood veneer. Whereas by now, the classification of wood veneer processed in China mainly depends on visual inspection, which is of low efficiency. Therefore, quick identification and area assessment are performed to the surface knot of wood veneer with image recognition. Instead of artificial sorting is automatic classification by computer smart control, which can significantly promote the classification efficiency of wood veneer and is of great significance for the development and progress of wood industry. [Method] The wood veneer with knots are selected as object in this study. Bases on the preliminary results of image identification, an improved identification calculation for wood veneer knots using mathematical morphology is proposed. In order to solve the problem of missing characteristic quantity of partial knots or identification of non-knot characteristic quantity existing in the image identification of wood veneer, this work can be divided into 5 steps, those were, original image extraction, graying processing, image segmentation, margin inspection of characteristic quantity and knot identification. Firstly, images of wood veneer are collected, and grey level transformation is performed for the images for sequential image identification. Secondly, according to the knots in the gray images and different gray scope in the background, the image is split with the gray threshold chosen by the maximum entropy principle, so as to preliminarily separate the knots from the background. Then the interference characteristics outside the knots preliminarily selected are removed with morphological algorithm, thus the outer contour of knots can be accurately presented. Finally, outline assessment is performed for the characteristics detected, to prevent other factors such as crack and dirt being separated from the background due to their dark color and considered as knots. [Result] This study shows that, there are some interference characteristics around the knots after image segmentation, the relationship between interference characteristics and knots can be cut off by morphological expansion, and the corrosion operation after expansion can maintain the real size of knots. By comparing the morphological opening-and-closing operations, it is found that the knots processed by morphological closing operation can be more easily identified. The identification accuracy can be improved by performing ellipse fitting and outline condition restriction for the characteristic profile inspected, to prevent the identification of non-knots. Furthermore, knots can be preliminary assessed by calculating the characteristic profile points and the matching degree of ellipse, and the knots outline restriction is mainly used for filtering the influence of rectangular objects (such as crack) that can be fitted into ellipse. [Conclusion] The knots quantity and relative size on the surface of wood veneer can be obtained by visual inspection, in the practical production processes, after interfacing with hardware, the real size of knots can be obtained according to the relative position of image collecting equipment and collecting objects and the resolution of images collected, etc. by combining the system assessment results, thus to realize the automatic classification of wood veneer.
Key words: wood veneer    knot    image recognition    image segmentation    mathematical morphology    automatic classification

1 材料与方法 1.1 试验材料

1.2 试验方法

1.2.1 图像采集与处理

1)图像采集与灰度化处理 在图像处理算法中，大多是在灰度图像上进行，因此需要把彩色图像转换为灰度图像。试验首先用扫描仪采集待甄别木材单板的表面彩色图像，然后对采集到的彩色图像进行灰度化处理。图像灰度化处理的基本原理和方法如下：在RGB颜色模型中，当R，G，B 3个颜色分量值不同时，表现为彩色图像；灰度图像是R，G，B 3个分量相同的一种特殊的彩色图像，其取值范围均为0～255。灰度图像的描述与彩色图像一样，仍然反映了整幅图像的整体和局部的色度和亮度等级的分布和特征。图像的灰度化处理中，实际常用的方法是根据RGB和YUV颜色空间的变化建立亮度Y与R，G，B 3个颜色分量的对应关系。在YUV色彩空间中，亮度也就是灰阶值Y和色度U，V是分离的；如果只有Y分量而没有U，V分量，表示的图像就是黑白灰度图像，并以此亮度值表达图像的灰度值。YUV与RGB相互转换的公式(姜柯等，2013)为：

 $Y = 0.299R + 0.587G + 0.114B$ (1)

2)运用一维最大熵法的灰度阈值选择图像分割是图像处理中的一个重要问题，因本研究目标节子和背景占据不同灰度级范围，故可运用最大熵原理选择灰度阈值对图像进行分割。其基本思路是：利用图像的灰度分布密度函数定义图像的信息熵，根据假设的不同或视角的不同提出不同的熵准则，然后通过优化该准则得到熵值。在灰度范围为[0，L-1]的图像中，熵函数定义(吴鹏，2014)为：

 $\varphi \left(t \right)= \lg {p_t}\left({1 - {p_t}} \right)+ \frac{{{H_i}}}{{{p_i}}} + \frac{{{H_{L - 1}} - {H_t}}}{{1 - {p_i}}}$ (2)

3)根据阈值T对灰度图像进行分割 设原始图像为f(x，y)，按照一维最大熵的计算方法在该图像中找到特征值(上述步骤中所求得的阈值T)，根据特征值将图像分割为2部分，分割后的图像(王游等，2013)为：

 $g\left({x，y} \right)= \left\{ \begin{gathered} {b_0} \cdots f\left({x，y} \right){\text{ < }}T \hfill \\ {b_1} \cdots f\left({x，y} \right)\geqslant T \hfill \\ \end{gathered} \right.$ (3)

1.2.2 形态学运算

1.2.3 节子的识别

2 结果与分析

2.1 节子的初步识别

 图 1 原始图像 Fig. 1 The original image
 图 2 灰度图像 Fig. 2 The gray image

 图 3 灰度直方图 Fig. 3 The gray scale histogram
 图 4 二值化图像 Fig. 4 The binary image

 图 5 形态学开闭运算处理结果 Fig. 5 The opened and closed operation of mathematical morphological

2.2 节子的最终判定

 图 6 节子识别结果 Fig. 6 The detection of veneer knot defect image

Goodness of fit算法主要计算连通区域轮廓点和拟合椭圆的匹配度(选择之前连通区域的轮廓点，计算每个点到拟合椭圆的最小距离的平方值，汇总后除以轮廓点总数，再取开方)，匹配度大于某个数值(这里选择为3)判定非节子；拟合椭圆长轴长度/短轴长度主要用于过滤一些长形物体比如裂隙等的影响，根据节子普遍的外形，选定长轴/短轴>2判定为非节子。至此，图 6中⑦根据Goodness of fit算法距离大于3，图 6中⑤长轴/短轴>2，识别为干扰特征量非节子；同时，图 6中离缝明显长轴/短轴>2，识别为干扰特征量非节子。

3 结论

1)二值化处理后的图像在节子周围可能会存在一些干扰特征量，通过数学形态学运算，可切断干扰特征量和节子之间的联系，使节子更容易被识别出。

2)检出的特征轮廓在进行椭圆拟合后辅以符合节子外形的条件限制(如拟合椭圆的长轴/短轴比、拟合椭圆和被检出特征外轮廓点的匹配度)可以提高检测精度，从而过滤掉木材单板中裂隙、污痕、腐朽等其他特征量因颜色较深被检出的影响。

3)根据图像采集设备与待采集对象的相对位置、采集图像的分辨率等情况，能得出节子的真实大小，结合系统判断结果和外部设备的接入，可实现木材单板的自动分等。

 [1] 姜柯,李艾华,苏延召. 2013. 结合边缘纹理和抽样推断的自适应阴影检测算法.西安交通大学学报, 47(2):39-46.(Jiang K, Li A H, Su Y Z.2013. An adaptive shadow detection algorithm using edge texture and sampling deduction. Journal of Xi'an Jiaotong University, 47(2):39-46[in chinese]).(1) [2] 李朝锋,潘婷婷. 2009. 基于形态学开闭运算和梯度优化的分水岭算法的目标检测方法.计算机应用研究, 26(4): 1593-1594.(Li C F, Pan T T.2009. Object detection method based on morphological opening-and-closing operation and gradient optimization. Application Research of Computers, 26(4): 1593-1594[in chinese]).(1) [3] 田俊霞,穆国燕. 2002. 基于边界特征的一维最大熵图像分割算法的研究与实现. 计算机工程与科学, 24(6): 46-47.(Tian J X, Mu G Y.2002. Research and implementation of one-dimensional maximum-entropy threshold images segmentation based on edge feature. Computer Engineering & Science, 24(6): 46-47[in chinese]).(1) [4] 王树文, 闫成新, 张天序, 等. 2005. 数学形态学在图像处理中的应用.计算机工程与应用, 40(32): 89-92.(Wang S W, Yan C X, Zhang T X, et al. 2005. Application of mathematical morphology in image processing. Computer Engineering and Applications, 40(32): 89-92[in chinese]).(1) [5] 王游,石成英,高明贺,等. 2013. 基于直方图阈值改进方法的缝隙图像二值化研究.现代电子技术, 36(6): 97-99.(Wang Y, Shi C Y, Gao M H, et al. Research on gap image binarization based on histogram threshold improved method. Modern Electronic Technique, 36(6): 97-99[in chinese]).(1) [6] 吴鹏. 2014. 萤火虫算法优化最大熵的图像分割方法.计算机工程与应用, 50(12): 115-118.(Wu P.2014. Image segmentation method based on firefly algorithm and maximum entropy method. Computer Engineering and Applications, 50(12): 115-118[in chinese]).(1) [7] 闫蓓,王斌,李媛. 2008. 基于最小二乘法的椭圆拟合改进算法. 北京航空航天大学学报, 34(3): 295-298.(Yan P, Wang B, Li Y.2008. Optimal ellipse fitting method based on least-square principle. Journal of Beijing University of Aeronautics and Astronautics, 34(3): 295-298[in chinese]).(1) [8] 张大坤, 罗三明. 2010. 形态学中闭运算功能的扩展及其应用.计算机工程与应用, 46(27): 185-187.(Zhang D K, Luo S M.2010. Function extension of morphological closing operation and its application. Computer Engineering and Applications, 46(27): 185-187[in chinese]).(1) [9] 张新明,张爱丽,郑延斌,等.2011.改进的最大熵阈值分割及其快速实现. 计算机科学, 38(8): 278-283.(Zhang X M, Zhang A L, Zheng T B, et al. Improved two-dimensional maximum entropy image thresholding and its fast recursive realization. Computer Science, 38(8): 278-283[in chinese]).(1) [10] 张怡卓,佟川,李想. 2012. 梯度算子与灰度阈值融合的实木地板节子识别方法研究.Research of solid wood floor knot recognition based on gradient operators and gray level threshold, 林业科技, 37(1):18-20.(Zhang Y Z,Tong C, Li X.2012. Forestry Science & Technology, 37(1):18-20[in chinese]).(1) [11] Cavalin P, Oliveira L S, Koerich A L, et al. 2006. Wood defect detection using grayscale images and an optimized feature set. Industrial Electronics, IECON 2006-32th Annual Conference on, 3408-3412.(1) [12] Duan R, Li Q, Li Y. 2005. Summary of image edge detection. Optical Technique, 3(3): 415-419.(1) [13] Funck J W, Zhong Y, Butler D A, et al. 2003. Image segmentation algorithms applied to wood defect detection. Computers and Electronics in Agriculture, 41(1): 157-179.(1) [14] Maini R, Aggarwal H. 2009. Study and comparison of various image edge detection techniques. International Journal of Image Processing (IJIP), 3(1): 1-11.(1) [15] Pham D T, Soroka A J, Ghanbarzadeh A, et al. 2006. Optimising neural networks for identification of wood defects using the bees algorithm.Industrial Informatics, 2006 IEEE International Conference on, 1346-1351.(1) [16] Ruz G A, Estévez P A, Perez C A. 2005. A neurofuzzy color image segmentation method for wood surface defect detection. Forest Products Journal, 55(4): 52-58.(1) [17] Zhi W, Saixian H. 2004.An adaptive edge-detection method based on Canny algorithm. Journal of Image and Graphics, 9(8): 957-962.(1)