1 Introduction

A neural network is a mathematical model that simulates the activity of biological neural systems (the nervous system). Neural networks can be trained just as living organisms (Aggarwal 2018). There are many types of neural network used to provide solutions for various tasks (from data mining to the autonomous driving of vehicles). An overview of several of the most common types of neural networks and examples of them can be found in Praveen Joe and Varalakshmi (2015), Chen et al. (2018), Savareh et al. (2018) and Manero et al. (2018).

An image recognized by a neural network is formed by picture elements (pixels). The total number of pixels is the number of pixels in the width of the image x the number of pixels in the height of the image. An image used by a neural network for object recognition may be black and white (binary image), grey scale or colour. Pixels in black and white images may only have two values (0 and 1). Each pixel of an 8-bit grey scale image may have a discrete value of 0 (black) to 255 (white). Colour images (8-bit colour depth) are formed using a 3D matrix (the number of pixels in width × number of pixels in height × number of colour channels). Red–green–blue (RGB) colour pictures have three colour channels (red, green and blue).

Pixel values are not directly applied to the neural network input, but are first modified in convolutional kernels (filters). Both the principle of a simple neural network for object recognition and the principle of a convolutional kernel are shown in Fig. 1.

Fig. 1
figure 1

Common neural network and Laplacian kernel: a principle of common neural network for object recognition (P1–P4 denotes pixel 1 to pixel 4; iN1–iN4 denotes input neurons 1–4; iW1,1 to iW4,2 denotes link weight between input and hidden neurons; hN1 and hN2 denotes hidden neurons 1 and 2; hW1,1 to hW2,2 denotes link weight between hidden and output neurons; oN1 and oN2 denotes output neurons 1 and 2); b principle of convolution Laplacian kernel (filter)

Neural networks are also applied to wood species recognition. According to Cunderlik and Smira (2013), wood species can be identified through their: macroscopic properties (the width of the earlywood, latewood, the presence of heartwood and sapwood, pith rays, vessels, resin canals, colour, smell, density and hardness) and microscopic properties, which may be observed using a stereomicroscope, transmission microscope or electron microscope. A wood species may also be identified based on its chemical composition (content and chemical composition of wood components, especially lignin, cellulose, hemicellulose and extractives). Details on the chemical composition of wood and use in identification were described by Avila-Calderon and Rutiaga-Quinones (2015), Huron et al. (2017) and Carvalho et al. (2017).

Neural networks used for the identification of wood species were studied in several scientific works. For example, Khalid et al. (2008), Esteban et al. (2009) and Yadav et al. (2013) studied neural networks for the identification of wood species based on microscopic elements. Jones et al. (2006) described a neural network for the identification of wood species based on its chemical composition (i.e. for the prediction of the chemical composition of wood), and Li et al. (2015) developed a neural network that predicts the chemical composition of bamboo. All the neural networks described above were capable of identifying the wood species (or predicting its chemical composition) with a high level of accuracy (over 90% in most cases). A neural network for wood species classification based on the speed of ultrasound transmission was developed by Jordan et al. (1998). Although the neural network was 100% accurate, the accuracy test used only 39 samples. Shustrov (2018) compared four neural network architectures (AlexNet, VGG-16, GoogLeNet and ResNet-50) for fir, pine and spruce wood recognition. For high quality image patches, AlexNet and GoogLeNet exhibited an accuracy of over 90%, VGG-16 over 80% and ResNet-50 over 70%.

In addition to wood species recognition, neural networks are commonly used for the automatic identification of wood knots, wood veneer surface defects and the prediction of wood properties. Neural networks for the recognition of wood knots and wood veneer surface defects were designed by Wei et al. (2009), Mohan et al. (2014) and Urbonas et al. (2019). Neural networks designed by the cited authors exhibited an accuracy of 70–95%. Nguyen et al. (2019) designed a neural network for prediction of the color change of heat-treated wood during artificial weathering. This neural network is capable of predicting the color change of heat-treated wood with only minimal deviation from the measured experimental data. Another example of the application of neural networks to the wood processing engineering is a neural network designed by Fu et al. (2017), which is used to predict the elastic strain of wood.

No published scientific study has examined both the impact of image type (grey scale and colour) and the colour temperature of light used to illuminate the surface of the wood sample on the accuracy of wood species recognition by a neural network (despite the fact that the colour temperature of light outdoors changes significantly during the day, and interior lights commonly use sources of light with varying colour temperature).

The aim of this study is to design a neural network (with an accuracy of at least 97%) for the recognition of selected wood species: European beech (Fagus sylvatica L.), European larch (Larix decidua Mill.), Norway spruce (Picea abies (L.) Karst) and Scots pine (Pinus sylvestris L.) from photographs taken from the tangential plane, which will be independent of the light colour temperature (in the range of 2700–6500 K). Another aim is to find an algorithm, which will enhance the accuracy of the neural network to take it above 99%.

2 Materials and methods

The flowchart in Fig. 2a shows the design, training, validation and testing of the neural network for wood species recognition (independent of the light colour temperature).

Fig. 2
figure 2

Flow diagram and method used to obtain samples: a flow diagram describing the design of the neural network for wood recognition; b method used to obtain samples from the tree trunks and an illustration of the transverse, radial and tangential planes of wood

The following samples were used to train the neural network: European beech (Fagus sylvatica L.), European larch (Larix decidua Mill.), Norway spruce (Picea abies (L.) Karst) and Scots pine (Pinus sylvestris L.) sawed into prism-shaped logs measuring 100 × 100 × 50 ± 0.5 mm so that the two surface areas of 100 × 100 mm represent the tangential plane. The manner that the samples were obtained from the trunk of the tree is shown in Fig. 2b. The surfaces of the tangential plane were planed and sanded using an orbital sander and 80 grit sandpaper. A total of 32 samples were obtained from each wood species (each sample having 2 tangential plane surfaces measuring 100 × 100 mm).

The method used to photograph the samples is shown in Fig. 3a. The samples were photographed in groups of four and placed as shown in Fig. 3a (the tangential plane surface of the photographed side of the samples measured 200 × 200 mm). The photographs were taken in a darkened laboratory (the surrounding light intensity was less than 0.1 lx) with a dark background behind the samples (Fig. 3a). The surface of the samples was illuminated using a light source with an adjustable light intensity and light colour temperature (in the range from 2700 to 6500 K): YEELIGHT Smart LED Bulb, YLDP05YL (YEELIGHT, Qingdao City, China).

Fig. 3
figure 3

Experimental device and method used to crop the photographs: a experimental device used to take sample photographs; b method used to crop the photographs (16 images from one photograph of 4 samples); numbers 1–16 denote the serial number of the cropped photograph

Each group of 4 samples was photographed while illuminated by 5 different light colour temperatures (2700, 3500, 4000, 5500 and 6500 K). At first, a photograph was taken from one side of the tangential plane, subsequently the samples were turned over and a photograph was taken of the other side of the tangential plane. Sixteen photographs were taken of each wood species at each colour temperature (with the tangential plane surface measuring 200 × 200 mm).

The light intensity at the surface of the samples was measured using a photometer EXTECH HD450 (EXTECH Instruments, Nashua, NH, USA). The average surface light intensity was 763 ± 106 lx. The photographs were taken using a SONY RX0 (SONY Corporation, Tokyo, Japan) camera. Camera setting: automatic mode (no zoom, sample surface 1 × 1 mm corresponds to 5 × 5 pixels in the photograph).

The photographs were then cropped as shown in Fig. 3b (16 images measuring 40 × 40 mm or 200 × 200 pixels were obtained from one photograph of 4 samples measuring 200 × 200 mm).

Once the photographs were cropped, images unsuitable for training of the neural network for wood species recognition (such as images with knots or splits) were discarded. Images with knots or splits are suitable for training a neural network used for wood defect recognition but not for a neural network used for wood species recognition.

The photographs used for the training, validation and testing of the neural network were those taken with light colour temperatures of 2700, 4000 and 6500 K (the number of images is listed in Table 1).

Table 1 Number of images of beech, larch, spruce and pine wood taken at 2700, 4000 and 6500 K colour temperature used to train, validate and test the neural network

Seventy percent of the images of each wood species was used to train the neural network, and 15% of the images was used for the validation and testing, as indicated in Table 2.

Table 2 Number of images used to train, validate and test the neural network

The images were processed as specified in Table 3 prior to being used to train, validate and test the neural network. Table 3 specifies the number of pixels in the image after processing (equal to the number of neurons in the input layer of the neural network).

Table 3 Image processing methods and the number of pixels after processing

The method used to average the images is shown in Fig. 4. After this modification, an image that measured 200 × 200 pixels was divided into cells that measured 5 × 5 pixels. Then, an average value was calculated for each cell (the calculated value represented a single value of the modified image). After averaging, the modified image measured 40 × 40 pixels. Sharpen and emboss kernels used to modify images are shown in Fig. 5. An example of spruce prior to modification and after modification using sharpen and emboss kernels is shown in Fig. 6.

Fig. 4
figure 4

Image processing by averaging (avg. denotes average value)

Fig. 5
figure 5

Kernels used for image pre-processing: a sharpen kernel; b emboss kernel

Fig. 6
figure 6

Images of spruce wood: a RGB photograph; b RGB photograph processed using a sharpen kernel; c RGB photograph processed using an emboss kernel; d grey scale photograph; e grey scale photograph processed using the sharpen kernel; f grey scale photograph processed using the emboss kernel

Photographs taken at colour temperatures of 3500 and 5500 were processed in an identical way. These photographs were used for additional tests of the neural network. The additional test measured the accuracy of the neural network for wood species recognition, the surface of which is illuminated by light with values of colour temperature that were not used in the training of the neural network. The number of images used in the additional test of the neural network is indicated in Table 4.

Table 4 Number of images used for additional test of the trained neural network

The neural network was created with MATLAB 2019a software, in the Neural Network Toolbox 10.0 environment. Neural network type: Neural Net Pattern Recognition (three-layer feed-forward network, with sigmoid hidden neurons and softmax output neurons). The structure of the neural network is shown in Fig. 7. The number of input neurons corresponded to the number of pixels (Table 3), and the number of output neurons corresponded to the number of wood species to be identified (4). The number of neurons in the hidden layer was 10, 20, 50 or 100. The neural networks were trained using scaled conjugate gradient backpropagation. Scaled conjugate gradient backpropagation is one of the most used algorithms for neural networks training. This algorithm was created and described in detail by Møller (1993).

Fig. 7
figure 7

Structure of the neural network design (the number of input neurons depends on the type and method of image processing—it varies from 1600 to 120,000 and the number of hidden neurons varies from 10 to 100)

The basic parameters and the abbreviated labels for the proposed neural networks for grey scale and RGB images are listed in Tables 5 and 6.

Table 5 Basic parameters and abbreviations for neural networks designed for grey scale images
Table 6 Basic parameters and abbreviations of the neural networks designed for RGB images

3 Results and discussion

The accuracy of the neural networks designed is indicated in Tables 7 and 8. Five neural networks reached a total accuracy that was equal to or higher than 98.0% (Tables 7, 8). Based on the tables above, it may be concluded that the neural networks with the highest accuracy were those trained using images processed by averaging to 5 × 5 and then by emboss kernel. Net_G_5 × 5_EM_100 (grey scale images, averaging 5 × 5, emboss kernel, 100 hidden neurons) exhibited the highest accuracy.

Table 7 Accuracy of the neural networks designed for grey scale images
Table 8 Accuracy of the neural networks designed for RGB images

Three neural networks trained using grey scale images (Table 7) achieved an accuracy of over 98% and another eight over 95%. Two neural networks trained using RGB images (Table 8) achieved an accuracy of over 98% and another fourteen over 95%.

The data in Tables 7 and 8 suggests that the most accurate neural networks are those which were trained using grey scale images modified by averaging (5 × 5) and emboss kernel. Another four neural networks were designed, trained, validated and tested in order to verify whether the accuracy of a neural network can be enhanced by an averaging process that includes the division of a 200 × 200 pixel image into cells measuring 10 × 10 pixels, the calculation of the average value (the essence of this averaging is similar to that in Fig. 4) and subsequent processing with emboss kernel. The basic parameters and abbreviated names of these neural networks are listed in Table 9. The accuracy of these neural networks is shown in Table 10. The most accurate (98.8%) of these neural networks was the Net_G_10 × 10_EM_100 (grey scale images, averaging 10 × 10, emboss kernel, 100 hidden neurons) network. On the one hand, the difference in accuracy when compared to the Net_G_5 × 5_EM_100 (grey scale images, averaging 5 × 5, emboss kernel, 100 hidden neurons) network (98.7%) is negligible. On the other hand, the Net_G_10 × 10_EM_100 neural network has only 400 input neurons and is 5739 kB (as opposed to 1600 input neurons and 192,020 kB for the Net_G_5 × 5_EM_100). Thus, by averaging the images (10 × 10), the accuracy of a neural network is not significantly reduced, yet the number of input neurons decreases as does the size of the neural network and the hardware requirements.

Table 9 Basic parameters and abbreviations of the neural networks designed for grey scale images processed using 10 × 10 averaging and by emboss kernel
Table 10 Accuracy of the neural networks designed for grey scale images processed using 10 × 10 averaging and emboss kernel

The data in Tables 7 and 8 suggests that the most accurate neural networks are those which have between 50 and 100 hidden neurons (neural networks for grey scale images recognition) and between 20 and 50 hidden neurons (neural networks for RGB images recognition). However, this general conclusion is dependent on other factors (mainly on the method of images pre-processing).

The most exact method of assessment of the accuracy of a neural network is through the use of the confusion matrix. Confusion matrices of neural networks with an accuracy of 98.0% and higher are shown in Fig. 8. Figure 8 shows that the highest levels of accuracy in the recognition of the wood species were found in the Net_G_10 × 10_EM_100 (grey scale images, averaging 10 × 10, emboss kernel, 100 hidden neurons) and Net_G_5 × 5_EM_100 (grey scale images, averaging 5 × 5, emboss kernel, 100 hidden neurons) 98.8% and 98.7%, respectively. This is a very high level of accuracy compared to the neural networks for wood species recognition designed and trained by other authors. For example, Yadav et al. (2013) designed a neural network for hardwood recognition with a maximum accuracy of 92.6% (and this network required inputs in the form of images taken under a microscope); Esteban et al. (2009) designed a neural network used to recognize two species of Juniperus wood based on macroscopic properties with an accuracy (of the testing set) of 92.0%, and Khalid et al. (2008) designed a neural network for the recognition of 200 wood species based on microscopic images with an accuracy of 95% (this may appear to be a quite remarkable value considering the number of recognizable wood species, but the neural network was only tested on 7–11 samples of each wood species). A comparison of results obtained (Tables 7, 8, 10) with the accuracy of the neural networks: AlexNet, GoogLeNet, ResNet-50 and VGG-16, yields interesting results. The aforementioned neural networks were trained to recognise three wood species (fir, pine and spruce) by Shustrov (2018). According to this author, the GoogLeNet (96.1%) and AlexNet (92.3%) exhibited the highest level of accuracy, while VGG-16 and ResNet-50 had an accuracy of only slightly over 80 and 70%, respectively. However, Khalid et al. (2008), Esteban et al. (2009) and Yadav et al. (2013) did not specify the colour temperature of the light in the photographs used for the training and testing of the neural network (however, it is highly probably that each author took the photographs with a single light colour temperature). Consequently, the 21 neural networks designed in this study achieved a higher level of accuracy (over 96.1%) than GoogLeNet (Tables 7, 8) despite the fact that the neural networks recognized four wood species with illumination by three different light colour temperatures.

Fig. 8
figure 8

Confusion matrices of neural networks: a Net_RGB_No_EM_20; b Net_RGB_5 × 5_EM_50; c Net_G_5 × 5_No_100; d Net_G_5 × 5_EM_50; e Net_G_5 × 5_EM_100; f Net_G_10 × 10_EM_100 (neural networks abbreviations are explained in Tables 5, 6)

It is very useful to compare the accuracy of the designed neural networks (Tables 7, 8, 10) with the accuracy of convolutional neural networks used in the recognition of everyday objects. According to Blanco (2017), convolutional neural networks achieve an accuracy of 95.4–96.4% in the recognition of everyday objects. A substantially larger variance in the accuracy of object recognition by neural networks AlexNet, GoogLeNet and ResNet-50 (0–99.2%) was reported by Sharma et al. (2018). This comparison proves that the designed and trained neural networks Net_G_10 × 10_EM_100 (grey scale images, averaging 10 × 10, emboss kernel, 100 hidden neurons) and Net_G_5 × 5_EM_100 (grey scale images, averaging 5 × 5, emboss kernel, 100 hidden neurons) exhibit a very high level of accuracy in the recognition of wood species.

All of the above-mentioned neural networks (Table 7, 8, 10) were trained, validated and tested using photographs taken at light with a colour temperature of 2700, 4000 and 6500 K. The Net_G_5 × 5_No_100 (grey scale images, averaging 5 × 5, no kernel, 100 hidden neurons), Net_G_5 × 5_EM_50 (grey scale images, averaging 5 × 5, emboss kernel, 50 hidden neurons), Net_G_5 × 5_EM_100 (grey scale images, averaging 5 × 5, emboss kernel, 100 hidden neurons), Net_RGB_No_EM_20 (RGB images, no averaging, emboss kernel, 20 hidden neurons), Net_RGB_5 × 5_EM_50 (RGB images, averaging 5 × 5, emboss kernel, 50 hidden neurons) and Net_G_10 × 10_EM_100 (grey scale images, averaging 10 × 10, emboss kernel, 100 hidden neurons) neural networks underwent additional testing with photographs of the wood species under investigation taken at colour temperatures of 3500 and 5500 K in order to verify whether the trained neural networks are even capable of recognizing wood species at colour temperatures that they were not trained for. The accuracy of the above-mentioned neural networks in the additional test is shown in Table 11. The above-mentioned table proves that the highest level of accuracy was reached by the neural networks trained for grey scale images adjusted with averaging and emboss kernel Net_G_5 × 5_No_100 (grey scale images, averaging 5 × 5, no kernel, 100 hidden neurons), Net_G_5 × 5_EM_100 (grey scale images, averaging 5 × 5, emboss kernel, 100 hidden neurons) and Net_G_10 × 10_EM_100 (grey scale images, averaging 10 × 10, emboss kernel, 100 hidden neurons). The confusion matrices for the neural networks with the highest levels of accuracy (over 97%) for the additional test are shown in Fig. 9.

Table 11 Accuracy of neural networks designated for the additional test
Fig. 9
figure 9

Confusion matrices of neural networks for the additional test: a Net_G_5 × 5_EM_100; b Net_G_10 × 10_EM_100; c Net_G_5 × 5_No_100 (neural networks abbreviations are explained in Tables 5 and 9)

A comparison of Table 11 with Tables 7, 8 and 10 demonstrates that neural networks trained using grey scale images are (compared to neural networks trained with RGB images) significantly less vulnerable to a decrease in accuracy when attempting to recognize photographs taken at colour temperatures for which they were not trained. The confusion matrices in Fig. 9 demonstrate that all three neural networks (Net_G_5 × 5_EM_100 (grey scale images, averaging 5 × 5, emboss kernel, 100 hidden neurons), Net_G_10 × 10_EM_100 (grey scale images, averaging 10 × 10, emboss kernel, 100 hidden neurons) and Net_G_5 × 5_No_100 (grey scale images, averaging 5 ×, no kernel, 100 hidden neurons)) exhibit the lowest level of accuracy in pine wood recognition. The reason is that convolutional neural networks (as opposed to humans) only recognize wood species based on the surface structure and texture.

An efficient algorithm to improve the accuracy of the neural network used for wood species recognition was suggested by Martins et al. (2013) and applied by Shustrov (2018). This algorithm is based on the recognition of several photographs from a single piece (e.g. a board) of wood in the neural network. The algorithm described considers those wood species that the neural network recognized most often to be the most probable one (e.g. if a neural network (correctly) recognized pine wood from 5 photographs of a pine wood board four times and once it (incorrectly) recognizes larch wood, the algorithm classifies the board as pine wood). Shustrov (2018) applied this algorithm (he always used 25 photographs of different parts of the same board for recognition) to enhance the accuracy of GoogLeNet, AlexNet, ResNet-50 and VGG-16. By applying this algorithm, GoogLeNet and AlexNet achieved an accuracy of 99.4% and 98.6% respectively; however, the ResNet-50 network did not even achieve an accuracy of 80%.

The advantage of the algorithm described is that it may substantially improve the accuracy of the neural network. The only disadvantage is that in order to apply it, it is necessary to use several photographs of different parts of a single piece of wood (e.g. a board) which is not always technically feasible if the board is too small.

The inputs to the neural networks in this study were photographs of the surface measuring only 40 × 40 mm (which is usually negligible in comparison to the size of wooden boards in practice). In the light of the above, the aforementioned algorithm may be applied to enhance the accuracy of neural networks (which exhibited the highest accuracy in the additional tests): Net_G_5 × 5_EM_100 (grey scale images, averaging 5 × 5, emboss kernel, 100 hidden neurons), Net_G_10 × 10_EM_100 (grey scale images, averaging 10 × 10, emboss kernel, 100 hidden neurons) and Net_G_5 × 5_No_100 (grey scale images, averaging 5 × 5, no kernel, 100 hidden neurons). This algorithm (illustrated in Fig. 10) considers the wood species recognised by the neural network at least 3 times out of 5 photographs of the same piece of wood (in different parts) to be the most probable species of wood. The accuracy of this algorithm used with neural networks Net_G_5 × 5_EM_100 (grey scale images, averaging 5 × 5, emboss kernel, 100 hidden neurons), Net_G_10 × 10_EM_100 (grey scale images, averaging 10 × 10, emboss kernel, 100 hidden neurons) and Net_G_5 × 5_No_100 (grey scale images, averaging 5 × 5, no kernel, 100 hidden neurons) is shown in Table 12.

Fig. 10
figure 10

Algorithm to improve the accuracy of wood species recognition

Table 12 Accuracy of designated neural networks (improved using an algorithm to increase accuracy) during additional testing

Table 12 demonstrates that the highest accuracy (99.99%) with the use of the above-mentioned algorithm is exhibited by neural networks Net_G_5 × 5_EM_100 (grey scale images, averaging 5 × 5, emboss kernel, 100 hidden neurons) and Net_G_10 × 10_EM_100 (grey scale images, averaging 10 × 10, emboss kernel, 100 hidden neurons) in supplementary materials, file S1 Net_G_5 × 5_EM_100 and S2 Net_G_10 × 10_EM_100. MATLAB code for image (200 × 200 pixels size) processing to input for the Net_G_5 × 5_EM_100 and Net_G_10 × 10_EM_100 neural networks is in supplementary materials, file S3.

4 Conclusion

The presented study deals with neural networks designed, trained, validated and tested (for the recognition of selected wood species: pine, beech, larch and spruce wood) independent of the colour temperature of the light illuminating the sample surface. The data obtained has demonstrated that:

  1. 1.

    Neural networks trained to use grey scale images and neural networks trained to use RGB images exhibit approximately the same level of accuracy in the recognition of photographs if they are taken using the same light colour temperatures as those used for the training of these neural networks.

  2. 2.

    Neural networks trained to use grey scale images exhibit a substantially higher level of accuracy (96.4% to 97.9%) than neural networks trained to use RGB images (85.8–88.1%) in the recognition of photographs taken at different light colour temperatures than those used in the training of these neural networks.

  3. 3.

    The most accurate (over 97%) neural networks, used for wood species recognition from photographs taken at varying colour temperatures of light other than the training photographs, were those trained with grey scale images adjusted by averaging (5 × 5 or 10 × 10) and emboss kernel with 100 neurons in the hidden layer.

  4. 4.

    Neural networks trained using photographs taken illuminated with light at colour temperatures of 2700, 4000 and 6500 are capable of recognizing a wood species even from photographs taken at different colour temperatures with a very high level of accuracy (almost 98%).

  5. 5.

    The accuracy of neural networks (especially those trained with grey scale images adjusted by averaging and emboss kernel) can be substantially enhanced (up to 99.99%) by using an algorithm, where 5 photographs of a single piece of wood (e.g. a board) are taken and the wood species is subsequently recognized based on the identical classification of at least 3 photographs (out of the 5 photographs).

The data obtained has demonstrated that for wood species recognition (based on photographs taken at an unknown light colour temperature), the most accurate neural networks are those designed to use grey scale photographs adjusted by averaging and emboss kernel. By applying a suitable algorithm (as described above), it is possible to increase the accuracy up to 99.99%, which is higher than all known neural networks (in wood species recognition).