- defect recognition for lumber grading purposes.

I took this as an assignment for my independent study class. The purpose of this project was to develop an image processing software providing capabilities of lumber defects classification. The defect classes are KNOT/HOLE, SPLIT, WANE. Although such classification is somewhat incomplete, it should provide good results in combination with lumber grading method based on imperfect defect classification. Description of this method could be found on the ALPS page. The software employs neural network approach. Below I give a very short explanation of principles used for building this software along with a downloadable example. The example is a stand-alone version of the recognition program.
It runs under Windows 95 and Windows NT 4.0.

Implementation notes: Built-in features of existing ALPS software determine the set and characteristics of input data. Therefore, classification method should take into account properties of these data and the fact that selection of recognition method is limited by available features.

ALPS software provides the next information that can be used in building defect classifier:

1) binary image of defect outlines
2) coordinates of rectangles containing a single defect

Graphical representation of this information is given below.

a) image of the board

b)Input data from ALPS software

c)Overlay of defect rectangles


As it follows from the given pictures, the current version of ALPS software does not separate background from the image of the board that will have certain consequences in quality of classification. Another important factor is that binary image is built using shape approximation by squares as illustrated by the next figure.

This picture shows that any defect sustains some part of shape deformation during detection process and binary image cannot provide reliable information about size of small defects.

Besides, given routines are quite dependent on the manually set threshold level that provides separation of defects from clear wood. Due to non-equality in lighting of the board and variations of clear wood color on the same board, some defects become incorrectly outlined or split into smaller parts that do not carry correct information about actual shape of a defect.

These are the limitations of the existing detection routines that have strong influence on final recognition and classification results.

As soon as input data represent shape of a defect, neural network (NN) approach was chosen to build classifier because NN features provide a well-studied basis for such processing.

Preprocessing: The first step in implementation was to build the core of the system that would provide possibility to view and analyze graphical representation of input data as well as provide conversion to a form more suitable for application with NN classifier.

One of the requirements to this kind of classifier is rotational independence, i.e. any rotation of defect image shouldn't lead to misclassification. (Positional independence assumed as well). Usual approach in is to train NN using input data obtained by rotations of initial image with some step angle, i.e. attempting to provide all possible combinations at which a defect can appear.

Although feasible in other cases, this approach is quite undesirable in lumber processing due to the  intrinsic properties of wood. It is well known that wood has well-expressed fiber structure that goes along long side of a log. Many defects have certain relative position to this lumber structure. For example, a naturally occurring split always goes along fibers as soon as they create weakness in wood. Therefore, assuming that the board edge and defect orientation can somehow be obtained , it would be possible to enhance recognition using these data. Even if board edge data are not specified, determining orientation vector would simplify training of NN. Knowing location of board edge would also significantly enhance recognition for such defect as wane, as this defect naturally occurs only at the edge.

Because of the mentioned above reasons, an algorithm for finding defect orientation vector was designed and built. This algorithm uses best approximation of defect shape by a line, thus providing required orientation parameters. Approximation is made using least mean square method, i.e. going along the longest side of defect rectangle and applying the following rules:

For y=ax+b solution can be obtained by calculating a and b from
the next linear equation system:

value of yi in this case is determined as shape width yi= ymax- ymin for each xi. After orientation vector was found, all further calculation are conducted in new coordinate system where axis Y is oriented along orientation vector Y. Mapping between two coordinate spaces is done using the next formulas shift and rotation space conversion: 

Rotation angle = arctan(B)
From screen (original) coordinates to rotated coordinates

From rotated coordinates to screen coordinates

Another preprocessing routine eliminates fragments of overlapping defects. Elimination of parts from other defects is done by applying a recursive procedure which analyses image inside of bounding defect rectangle. Analysis starts on the edge of the rectangle and continues until a closed contour was found inside or search space has been exhausted.

a) Overlapping of two defects within bounding rectangle

b) Defect after preprocessing

After preprocessing each defect is represented as 25-entries numerical array. First number contains integer value representing maximum size of the defect rectangle. Other 24 entries contain description of defect shape in terms of polar coordinates. They start from the entry corresponding to the 0 angle (in rotated coordinates, all other correspond to gradual increase of angle with 15 degree discreteness.

These values are fed to a 2-level backpropagation network trained using total of 88 distinct samples. The samples for training were chosen by applying LVQ method to the original set of 100 samples and selecting a subset that would provide 100% recognition accuracy. After backpropagation network has been trained, the same 100 sample set was applied to it. Accuracy of recognition was significantly higher than provided by LVQ. Backpropagation network was able to recognize 97 out of 100 correctly. It should be noted that these extra 12 samples were though to recognize using existing set of features as soon as their features are "smeared" among different classes.

Conclusion: Although the program in it's existing condition gives sufficiently accurate results, there is a lot of place for improvement. Additional preprocessing procedures should be added to ensure quality and soundness of preprocessing as well as adding new features to recognition. Neural network approach proves to be well suited for this kind of recognition tasks but set of input data consisting only of grayscale image data significantly reduces recognition capability of any method because of poor board representation. To improve performance, some other method (laser scanning, for example) may be introduced to work in parallel.

Download the software. Two sample images are given.
Help menu provides instructions how to use the program.