Automatic Classification of Wood Defects Using Support Vector Machines Irene Y.H. Gu1 , Henrik Andersson1 , and Ra´ ul Vicen2 1
Dept. of Signals and Systems, Chalmers Univ. of Technology, 41296, Sweden
[email protected],
[email protected] 2 Dept. of Signal Theory and Communications, Univ. of Alcal´ a, Spain
[email protected]
Abstract. This paper addresses the issue of automatic wood defect classification. We propose a tree-structure support vector machine (SVM) to classify four types of wood knots by using images captured from lumber boards. Simple and effective features are proposed and extracted by first partitioning the knot images into 3 distinct areas, followed by applying an order statistic filter to yield an average pseudo color feature in each area. Excellent results have been obtained for the proposed SVM classifier that is trained by 800 wood knot images. Performance evaluation has shown that the proposed SVM classifier has resulted in an average classification rate of 96.5% and false alarm rate of 2.25% over 400 test knot images. Our future work includes more extensive tests on large data set and the extension of knot types. Keywords: wood knot classification, wood defect detection, wood defect inspection, support vector machine, feature extraction, machine vision.
1
Introduction
This paper addresses the issue of automatic classification of wood defects. There has been a growing interest in research and development of automatic wood defect detection and classification methods and systems, especially in wood-rich countries such as Scandinavian. Currently, most lumber board inspections (such as detecting defects including freckle, bark, pitch pockets, wane, split, stain, hole and various types of knots) and wood grading are still performed by trained human experts. Long hours exposing to wood inspection would cause eye fatigue hence low efficiency and accuracy in the inspection. It is found [1,2] that human visual inspections rarely achieved better than 70% performance in grading lumbers largely due by eye fatigue. The growing number of new imaging techniques, available databases of wood images, and sophisticated techniques in computer vision have made online automatic wood inspections an ever approachable reality, further more, with a performance that well exceeds those of human inspectors. Many promising techniques have been studied and developed on automatic detecting and classification of wood defects in the last decade. For example, [3] proposed a genetic algorithm for the classification of 10 types of defects (birds L. Bolc, J.L. Kulikowski, and K. Wojciechowski (Eds.): ICCVG 2008, LNCS 5337, pp. 356–367, 2009. c Springer-Verlag Berlin Heidelberg 2009
Automatic Classification of Wood Defects Using Support Vector Machines
357
eye and freckle, bark and pitch pockets, wane, split, blue stain, stain, pitch, dead knot, live knot, and hole). Using a database containing color images from 2958 board faces where each defect is characterized by a feature vector of size 182, the online system has resulted 80% classification rate. [5,4] proposed a recognition system of defects on lumber boards using simple RGB color percentile features calculated from arbitrary rectangular regions. Several defect recognition stages, starting from sound wood elimination, defect identification, to classification of knots, color defects and splits, are used. Each stage reduces the amount of image data needed to be processed by the subsequent stages. The final stage is quality grading, which collects the information on recognized defects on each board surface, and determines the quality grade according to the grading rules. The system uses a non-supervised clustering-based approach for detecting and recognizing defects in lumber boards. A self-organizing map (SOM, a special type of artificial neural network) is employed for discriminating between sound wood and various types of defects. Human involvement needed for training is minimal. The method has achieved low false alarm rate. Further improvement has been made in [7] for the classification of wood defects. Four different types of knots (encased, leaf, edge and sound knots) were included in their study. The classifier employs supervised and non-supervised artificial neural networks (self organized neural network - SONN and fuzzy SONN) as well as feedforward perceptron where the knot features are obtained from Gabor filters. The system using fuzzy SONN has resulted in a classification rate of 91.17%, and of 85% for the perceptron on the test knot set, however, the false alarm rate is not mentioned. Despite their promising in classifying wood defects, many challenging and open issues remain to be solved. On the other hand, support vector machines (SVMs) [8,9] have drawn increasing interest lately for pattern classification. SVM classifiers have the sound mathematic background One of the attractions of SVM classifier is that it has a solid mathematical foundation, the statistical learning theory. Unlike artificial neural network classifiers that minimize the error for the training set, a SVM classifier is designed to minimize the generalization error, i.e., the error on the test set under the structural risk minimization (SRM) principle. There is a guarantee of the upper error bound on the test set based on statistical learning theory. Further more, the complexity of a SVM classifier can be controlled and is associated with the so-called VC dimension. Despite many advantages of statistical learning and SVMs, they have not been used for wood defect or wood knot classification. Motivated by the above, we propose an automatic wood defect classification method based on support vector machines (SVMs). A tree structure SVM classifier is employed for classifying four different types of wood knots, including sound knots, dry knots, pin knots, black and rotten knots. To the best of our knowledge, this is the first reported work on using SVMs for wood knot classification. Simple features are examined for characterizing each type of wood knots. The SVM classifier has been trained by using 800 wood knot images from Sweden, as well as by using some mixture of wood knot images from Sweden and Finland.
358
I.Y.H. Gu, H. Andersson, and R. Vicen
Despite using simple features in our system, the proposed SVM classifier has yielded an excellent performance [10]. The remaining paper consists of the description of wood types, knot images and their related properties (in Section 2), a brief description of theory of SVMs (in Section 3), feature selection and extraction methods (in Section 4), the structure of the SVM classifier (in Section 5), experimental results and performance evaluations (in Section 6), and finally conclusions (in Section 7).
2
Wood Knot Types
In this section we briefly describe five wood knot types that will be studied in the paper. Although there are many more possible types of wood knots, readers are referred to [11] for more details and their specification. Fig.1 shows typical image examples for these five types of wood knots, namely, sound knots, dead knots, black knots, rotten knots and pin knots. As can be seen from the figure, their images differ in color, shape, texture and size. Sound knots are usually considered as harmless, formed from tree branches. Images of typical sound knots may have some circular shaped curves reflecting the age of the branches, also have slightly dark colors and different textures as compared with the background wood, as shown in Fig.1(a). Dead knots are formed when a tree branch ceased to function. An image of a dead knot usually shows a darker circular shaped curve where the interior area of knot has a slightly darker color than the normal wood color, see Fig.1(b). Black knots are dead knots where the interior of a knot is also dark colored, see Fig.1(d). Rotten knots are considered as harmful. Images of rotten knots usually show a dark interior area with a darker circular shape boundary, see Fig.1(d). Pin knots are small dark knots, usually with a diameter no more than 7mm (see Fig.1(c)). Since black knots and rotten knots in a lumber board are usually considered as unsuitable to use, and would usually be cut off when processing the wood board, we shall treat them as one class in our classification system.
3
Statistical Learning and SVM Classifiers
A special characteristic of a SVM is that, instead of dimension reduction commonly employed in pattern classification, the input space is nonlinearly mapped by Φ(·) onto a high dimensional feature-space, where Φ(·) is a kernel satisfying Mercer’s condition. As classes are more likely to be linearly separable in the high dimensional space rather than in a low dimensional space. Let N input training samples and their class labels be (xi , di ), xi ∈ Rm0 (i.e. m0 dimensional input-space) and di ∈ Y (i.e. the decision-space). A nonlinear mapping function Φ(·) is first applied which maps the input-space Rm0 into a highdimensional feature-space F : Φ : Rm0 → F , xi → Φ(xi ). Then, another function
Automatic Classification of Wood Defects Using Support Vector Machines
359
Fig. 1. Image from different types of wood knots. From top to bottom: Rows (a)-(d): sound knots, dead knots, black knots and rotten knots, and pin knots.
f (·) ∈ F is applied to map the high-dimensional feature-space F onto a decisionspace, f : F → Y, Φ(xi ) → f (Φ(xi )). The best function f (·) ∈ F that may correctly classify a unseen example (x, d) from a test set is the one minimizing the generalization error, R(f ) = l [f (Φ(x)), d] dP (Φ(x), d), where l(·) is the loss function, and P (Φ(x), d) is the probability. An error is occurred if f (Φ(x)) = d. Since P (x, d) is usually unknown, we cannot directly minimize R(f ). Although there exist many f (·) ∈ F that give nearly perfect classification on the training set, f (·) will be chosen among them, such that it results in the minimum error on the test set, based on the structural risk minimization (SRM) principle. For all δ > 0 and f ∈ F, it is shown that the bound of the generalization error for a SVM classifier is
δ h(ln( 2N h + 1) − ln( 4 ) (1) N N where the empirical error is Remp (f ) = N1 i=1 l (f (Φ(xi )), di ), and h is the VC dimension for the function class F. (1) holds with a probability of at least (1 − δ) for N > h. Choosing a nonlinear mapping function Φ in a SVM is associated with selecting a kernel function. Kernel functions in a SVM must satisfy Mercer’s condition [8].
R(f ) ≤ Remp (f ) +
360
I.Y.H. Gu, H. Andersson, and R. Vicen
Soft-Margin C-SVMs A soft-margin C-SVM is used for the wood knot classification as it can handle linearly nonseparable classes. A C-SVM allows some training error Remp (f ) in order to achieve less error on the test set. Roughly speaking, optimal solution to a SVM classifier is associated with finding the maximum margin (∝ 1/||w||2 ), where a margin is the shortest distance between the separating boundary and a correctly classified training sample that is nearest to the separating boundary. A soft-margin SVM can be described by the quadratic optimization problem, N 1 w2 + C ξi (2) minw,b,ξ 2 i=1 subject to the condition that all training samples being classified satisfy, di ( w, Φ(xi ) + b) ≥ 1 − ξi ,
ξi ≥ 0, i = 1, 2, · · · , N
(3)
where C ≥ 0 is a regularization parameter determined empirically, ξi are the slack variables. This leads to the Lagrangian optimization problem (primal form), L(w, b, α, ξ, μ) =
N N 1 w2 + C ξi − μi ξi − 2 i=1 i=1
−
N
αi [di ( w, Φ(xi ) + b) − 1 + ξi ]
(4)
i=1
where μi is the lagrange multiplier to enforce the positivity of ξi . Using the kernel k(·, ·), an important concept in SVMs, a dual form equivalent to (4) is ⎧ ⎫ N N ⎨ ⎬ 1 maxα αi − αi αj di dj k(xi , xj ) ⎩ ⎭ 2 i,j=1 i=1 (5) N αi di = 0, C ≥ αi ≥ 0, i = 1, 2, · · · , N subject to : i=1
The optimal solution satisfies the KKT (Karush-Kuhn-Tucker) conditions [8] and can be obtained by solving the (convex) quadratic programming (QP) problem. Finally, the decision function for a soft-margin SVM classifier is, N s αi di k(x, xi ) + b f (x) = sgn i=1
where Ns is the number of support vectors xi , where they are either on the margin (correct classified training samples) or inside the margin (incorrectly classified training samples).
Automatic Classification of Wood Defects Using Support Vector Machines
361
Fig. 2. Block diagram of a SVM classifier for a two-class case
Fig.2 shows the block diagram of a SVM classifier where x is the input vector drawn from the test set, and xi , i = 1, · · · , Ns , are the support vectors drawn from the training set. Despite the block diagram structure of the SVM looks similar to a RBF neural network, it is worth mentioning their fundamental differences: First, the weights αi di to the SVM outputs contain lagrange multipliers αi (associated with the constrained optimization in SVM learning that minimizes the generalization error), while the weight in the RBF neural network are selected for minimizing the empirical error. Second, for a general multilayer neural network, activation functions are used in the hidden layer to achieve the nonlinearity, while a SVM employs a kernel function k(·, ·) for nonlinearity, and the kernel is only dependent on the dot product of x from the test set and the support vectors.
4
Feature Selection and Extraction for Wood Knots
Each wood knot sample is described by a rectangular image area containing the knot (referred to as the ”knot image” in the subsequent text), and is then characterized by a feature vector. Selecting features for knots is one of the most essential steps towards a successful classification. Observing images from different types of knots indicates: – color and texture of knots are essential for human inspections. Since colors of wood knots may vary significantly in respect to different wood type, wood origins (countries or regions), camera type and settings and lighting conditions, it is therefore essential that the relative color differences (as reference to their background wood) rather than the absolute colors are exploited. – knot sizes are in most cases not essential features, with an exception for pin knots (featured by its small size), as knot sizes within each knot type can vary significantly.
362
4.1
I.Y.H. Gu, H. Andersson, and R. Vicen
Partition Each Knot Image into 3 Areas Based on the Outer Boundary
The following basic idea is exploited for defining features: Noting that each knot image is chosen to be rectangular, while the shape of a wood knot is usually ellipse, round, or with a smooth boundary. Therefore, each knot image contains a small exterior area outside the wood knot that belongs to the background, and can be used as the reference of the ”normal wood” color (or, reference texture) related to the given lumber board. We divide each knot (rectangular) image into 3 areas: the interior area of knot (i.e., the knot area), the exterior area (i.e., a small background area) and the boundary area (set to be the thick outer boundaries of a knot). To detect the outer boundary of a knot, a simple edge detection algorithm is first applied to a knot image, followed by edge chaining where nearby edge points with similar edge directions are connected. Outer edge curves that are long (exceed certain lengths) are picked out as the outer boundary curves. Since the outer boundary of wood knot is assumed to be closed, unconnected outer boundaries are then closed by using e.g. B-spline, assuming a smooth wood boundary. It is worth mentioning that: (a) for weak edges, double edge curves may present; (b) edge positions from a simple edge detection algorithm may not exactly correspond to the peak position of an edge profile, if it is not carefully tuned. Observing that for some knot types (e.g., black knots and rotten knots), the color difference between the boundary points and the interior area of a knot is one of the important characteristics. Therefore, edge curves that are selected as the outer boundary curves shall be widened. Ideally, for double edge curves, the width of a corresponding widened boundary curve would be set as the distance between the double edges so that the area between the double edges can be included (see Fig.3). Otherwise, an outer boundary curve would be extended in both sides of the edge peak location to prevent the possible misplacement of the exact peak position. To simplify the processing for these two occasions, a lowpass filter is applied to yield widened edge profiles. In such a way, a widened outer boundary curve would always include the true boundary profile from the wood knot.
Fig. 3. Double edges are detected for a weak edge. Region 2 is the area of interest for characterizing the wood boundary. A widened boundary for double edges should therefore include regions 1, 2 and 3.
Automatic Classification of Wood Defects Using Support Vector Machines
4.2
363
Feature Definition, Average Pseudo Colors and Order Statistic Filters
Once the closed outer boundary of a knot is obtained, a set of image pixels that belong to the interior, exterior or a boundary area can then be determined. For each area in the knot image, a simple feature vector is then defined, x = [x1 , x2 , x3 , x4 ]T
(6)
where x1 is the knot size, x2 , x3 and x4 are the average normalized pseudo colors for the interior, exterior and outer boundary area of knot, respectively. Pseudo colors in each area is normalized by the maximum value in the corresponding area (i.e. interior, exterior, or boundary) selected from the entire training set. 4.3
Order Statistic Filter for Computing Average ”Pseudo Color”
First, let us define the (normalized) ”pseudo color”. Let the color of an image pixel si be I(si ). A pseudo color is a filtered image color G(si ) = h ∗ (I(si )), where I is the original image, h is a filter kernel, and ∗ is the linear convolution. To compute the average pseudo color of an area, an order statistic filter (OSF) is used. Let the area (either interior, exterior or widened boundary area) contains N image pixels. Let the pseudo color of pixels si be G(si ), i = 1, · · · , N . The pseudo color values are first sorted in an ascending order, resulting in a sequence G(s(1) ) ≤ G(s(2) ) ≤ · · · ≤ G(s(N ) ). A nonlinear order statistic filter (or, L-estimator) is the applied, yielding an average (normalized) pseudo color as follows: αj G(s(j) ) (7) F (G(s(1) ), G(s(2) ), · · · , G(s(N ) ) =
j
1/L, if i = (N − L + 1)/2 , and L is empirically determined. (7) 0, otherwise is computed for each area, and then assigned to the corresponding xi in (6). The principle of choosing the filter for generating the pseudo color is as follows: For each knot color image contains 3 component images (e.g., R,G,B), a lowpass filter shall be selected so that the filtered color image contains sufficient averaging texture and knot boundary information, while most fine details of wood structure lines are smoothed out. Further, the image becomes a onecomponent image. Ideally, the filter could also be desired to correct the wood color due to the origins of wood and the type of wood, and due to lighting conditions. To simplify the processing, and to limit the scope of this paper, a simple filter is used. Fig. 4 shows an example of a wood image consisting of 3 component images. Observing the 3 component images indicates that (a) Red color images are somewhat blurred (equivalent to apply a lowpass filter) where the fine details of the knot are smoothed out, however, the average texture and contrast of the knot against its background are maintained. (b) Green color images contain some more detail structure of knots, although the images are also where αi =
364
I.Y.H. Gu, H. Andersson, and R. Vicen
Fig. 4. Three component images from a sound knot
blurred (or, lowpass filtered). (c) Blue images have a rather low contrast. Since the important knot features used in our method are based on the averaging area features in the interior/exterior/boundary of knots and their relative differences, we decide to simply use the red component image for our experiments, as this would satisfy our requirement. 4.4
Knot Size
For knot size feature in (6), it is estimated by counting the number of pixels on the outer boundary curve. Since a pin knot significantly differ from other types of knot in size, knot size feature is used for distinguishing pin knots from the remaining types of knot without exploring other features.
5
Topology Selection for the SVM Classifier
As shown in Fig.5, a tree structure SVM classifier is proposed for classifying different types of wood knots.
Fig. 5. Using a tree-structure SVM for wood knot classification
Automatic Classification of Wood Defects Using Support Vector Machines
365
The basic idea of using a tree-structure SVM classifier is to divide a large classifier into a few smaller and simpler ones. Since pin knots significantly differ in size from the remaining types of knots, the classifier would only require to use the size feature x1 to distinguish between pin knots and the remaining knots. After that, the feature vector in the remaining levels of classifier would reduce to [x2 , x3 , x4 ]T . Based on the observation that dead knots clearly differ from the remaining 3 types by having a darker boundary curve against the interior and exterior area, the 2nd level of classifier is to distinguish black and non-black knots. In the last level, ”not recognized knot” type is also defined so that knots do not belong to the 4 designed classes would not be classified.
6
Experimental Results and Performance Evaluations
First, wood knot images required were manually cut from color images captured from lumber boards. A total of 1200 knot images were used, of 800 for training and 400 for testing. For each knot image, a feature vector is then extracted. For each ”average pseudo color” feature, it is then normalized by using the maximum value of the corresponding feature in the training samples. The same normalization factor is then saved, and subsequently applied to the corresponding feature in the test set. Matlab SVM toolbox from OSU [14] was used. A C-SVM, with a Gaussian 2 RBF (radial-basis function) kernel k(x, y) = exp( −x−y ), was chosen. The γ two parameters (C, γ) were determined prior to the training process. A simple grid-search method in [12] and leave one out cross-validation were used to find the best parameters (C, γ). The optimal parameters obtained from such a way are (C, γ)=(3, 6),(6, 6.5) and (5, 6.5) corresponding respectively to 2nd, 3rd and 4th level in the tree-structure SVM. Once (C, γ) were determined, the SVM is then re-trained with the fixed (C, γ) using the entire training data (see Fig.6).
Fig. 6. Block diagram: RBF kernel SVM learning, then classifying x from a test set
6.1
Training SVM Classifiers
Two classifiers were trained both using 800 knot images (200 for each type): classifier-1 was trained using features from knot images in Sweden, while for
366
I.Y.H. Gu, H. Andersson, and R. Vicen
classifier-2 training, 200 sound knot images consisted of 184 from Sweden and 14 from Finland [13]. 6.2
Testing SVM Classifiers
Tests were then performed by 400 knot images (100 for each type). For classifier1, knot images in the test set were from Sweden. However, for classifier-2, 100 sound knot images were from Finland [13], and the remaining 300 were from Sweden. Tables 1 and 2 summarize the test results from these two classifiers. To further evaluate the performance, false alarm rate was also tested and included. Table 1. Test results from SVM classifier-1, using all Swedish wood images. Pc : classification rate; PF A : false alarm rate. knot type pin dead sound black/rotten total number 100 100 100 100 classification 97 96 95 98 0 4 2 3 false alarm
average (%) Pc =96.5 PFA =2.25
Table 2. Test results from SVM classifier-2, using mixture of Swedish (S) and Finnish (F) wood images. Pc : classification rate; PF A : false alarm rate. knot type
pin dead sound black (S) average (%) (S) (S) (F) /rotten(S) total number 100 100 100 100 classification 97 96 96 98 Pc =96.75 0 5 2 2 PFA =2.25 false alarm
Observation the performance in Tables 1 and 2, our tests showed that using the simple feature vector and the tree-structure SVM classifiers have yielded good performance.
7
Conclusion and Future Work
The proposed tree-structure SVM classifiers has been tested for classifying four different types of wood knots by using simple and efficient features. Evaluation of our test results over 400 images yielded an average classification rate of 96.5% and a false alarm rate of 2.25%. Future work includes refining the methods, more extensive tests using larger wood data sets, and also on extending the classifier to include more wood knot types and other wood defects.
Acknowledgement The Swedish wood images were kindly provided by Ros´ens Maskin AB, Sweden.
Automatic Classification of Wood Defects Using Support Vector Machines
367
References 1. Gr¨ onlund, U.: Quality improvements in forest products industry. Dissertation, Lule˚ aUniversity of Technology, Sweden (1995) 2. Huber, H.A., McMillin, C.W., McKinney, J.P.: Lumber defect detection abilities of furniture rough mill employees. Forest Products Journal 35, 79–82 (1985) 3. Estevez, P.A., Perez, C.A., Goles, E.: Genetic input selection to a neural classifier for defect classification of radiata pine boards. Forest products journal 53(7), 87–94 (2003) 4. Silv´en, O., Niskanen, M., Kauppinen, H.: Wood inspection with non-supervised clustering. Machine Vision and Applications 13(5-6), 275–285 (2003) 5. Silv´en, O., Kauppinen, H.: Recent Development in Wood Inspection. Internation Journal of Pattern Recognition and Artificial Intelligence 19(1), 83–95 (1996) 6. Kauppinen, H., Silv´en, O.: The Effect of Illumination Variations on Color-Based Wood Defect Classification. In: Proc. IEEE Int’l conf. ICPR, pp. 828–832 (1996) 7. Chacon, I.M., Alonso, G.R.: Wood defects classification using a SOM/FFP ap˙ proach with minimum dimension feature vector. In: Wang, J., Yi, Z., Zurada, J.M., Lu, B.-L., Yin, H. (eds.) ISNN 2006. LNCS, vol. 3973, pp. 1105–1110. Springer, Heidelberg (2006) 8. Shawe-Taylor, J., Cristianini, N.: An Introduction to Support Vector Machines and Other Kernel-based Learning Methods. Cambridge University Press, Cambridge (2000) 9. Sch¨ olkopf, B., Smola, A.J.: Learning With Kernels - Support Vector Machines, Regularization, Optimization and Beyond (2001) 10. Andersson, H.: Automatic classification of wood defects using support vector machines, MSc thesis, Chalmers Univ. of Technology, Sweden (2008) 11. F¨ ooreningen Svenska S˚ agverksm¨ an FSS, Nordiskt tr¨ a (Nordic trees), Markaryds Grafiska (1999) ISBN: 91-7322-251-8 12. Hsu, C.-W., Chang, C.-C., Lin, C.-J.: A practical guide to support vector classifcation (2007), http://www.csie.ntu.edu.tw/~ cjlin/papers/guide/guide.pdf 13. Finnish sound wood knots, http://www.ee.oulu.fi/research/imag/knots/KNOTS/ 14. Matlab SVM toolbox from OSU, http://svm.sourceforge.net