Color spectra algorithm of hyperspectral wood dyeing using particle swarm optimization

To improve the accuracy and practicality of the intelligent color-matching application of wood dyeing technology, Fraxinus mandshurica veneer was selected as the dyeing material. First, based on the Friele model and Stearns–Noechel model, the model parameters were cyclically assigned to calculate the optimal fixed parameter values and predictions. Then, particle swarm algorithm was used to optimize two algorithm models, the obtained reflectance curve was fit, and the color differences were calculated according to the human eye-based CIEDE2000 color difference evaluation standard formula. Last, the two formulas to predict the color difference and spectral reflectance were compared. First, the two optimization algorithms were compared according to the size of the fitted color difference value, and then, the most accurate optimization algorithm was selected. When the model parameters were fixed, the average fitted color difference was 0.8202. After optimizing the Friele model, the average fitted color difference was 0.7287, and after optimizing the Stearns–Noechel model, the average fitted color difference was 0.6482. It was concluded that the improved Stearns–Noechel model based on particle swarm method was more accurate than the Friele model for wood color matching.


Introduction
To achieve efficient use of plantation forests, the computer-assisted dyeing and color-matching technologies are used to improve inferior materials and imitate valuable materials (Guan 2011;Guan et al. 2010). Using the method based on Bayesian normalization algorithm and Levenberg-Marquardt (LM) algorithm to improve the traditional BP neural network has improved the accuracy of the simulation concentration and the generalization of the network (Nie et al. 2008), but the network convergence speed has not been significantly improved, and the training sample size is  1 3 chloride are added to make the dyeing solution and single plate dyeing experiment. The veneers of different colors can be dyed according to different mixing ratios, the color value of each dyed veneer and raw materials is detected, and the color difference is fitted according to the reflectance curve, and the feasibility of the simulation wood dyeing prediction scheme is realized through optimization algorithm experiments.

Particle swarm optimization
Particle swarm optimization algorithm is an intelligent algorithm. Its principle is to imitate the best advantage of bird swarms or fish swarms to find a suitable position in the swarm. The fitness is the evaluation factor of its algorithm, where each particle has its corresponding fitness (Lin et al. 2013). Considering that this point is suitable for fitting the spectral reflection curve, this algorithm is selected for optimization and correction. The fitness function is as follows: where fit p represents the fitness value of the pth individual in the particle group, and N represents the number of monochrome types participating in color matching, where

Friele model and determination of optimal parameter Q
The computer-assisted color matching of wood veneer dyeing mainly studies the optical model algorithm of multi-dye component mixed color matching and single group distribution color. The different dyes are mixed according to a certain concentration ratio. In theory, there is a certain additive relationship. Therefore, it is assumed that there is an intermediate function f [R( )] about the spectral reflectance. When a single-component dye is mixed at different mass concentrations, where R m ( ) represents the reflectance of the mixed dye liquor at a wavelength of λ; R i ( ) represents the reflectance of each single-component dye at a wavelength of λ; c i represents the concentration ratio of each component dye, ∑ c i = 1, n = 3. In 1952, Friele conducted many experiments according to formula (2) and finally obtained the function formula about R( ) , namely the Friele model (Friele 1952). This paper investigated the color mixing dyes based on the Friele model and used MATLAB combined with the least square method to achieve full spectrum color matching. The Friele model is: where R( ) represents the reflectance at a wavelength of λ; Q is a variable parameter value. The core link of the Friele model is to determine the Q value in the algorithm and predict the initial formulation of fixed parameters.
In this paper, experiments on 82 mixed color samples were used to solve the Q value when the minimum matching color difference was reached, and the optimal parameter Q value was 0.415.

Formula prediction with fixed parameters
This paper used the reflection spectrum matching algorithm (Yang et al. 2018;Li et al. 2014) to calculate the initial formula based on the target spectral data. To achieve the color spectrum matching, it was required to achieve the same spectral reflectance curve as the standard sample reflectance curve: where R m ( ) is the reflectance of the standard sample at a wavelength of λ; R s ( ) is the reflectance of the matched sample at a wavelength of λ.
The initial formula was solved according to the reflection spectrum matching algorithm, the minimum value of the color difference was calculated by the least square method, and the spectral reflectance curve was fitted to minimize the difference between the standard sample spectral reflectance curve and the matching sample spectral reflectance curve, which is where n = 3 , and the deviation was calculated by the method of least squares. According to the color measurement range of the chromatograph (400-700 nm), the wavelength interval is 20 nm, according to the formula: constituting monochromatic dyes in the concentration ratio data The least square method was used to solve the equations to get C = (F T × F) −1 × F T × F m , and obtain the spectral dye concentration formula.

Optimization of Friele model prediction equation
To make the experimental equation more accurate, this study combined the particle swarm algorithm to modify and improve the original model, cyclically calculate the parameters to obtain the optimal value, and fit the spectral reflectance curve to calculate whether the color difference is greater than 1. The specific process is shown in Fig. 3.

Spectral color-matching algorithm
The reflectance of the raw material measured by the hyperspectral, that is, the reflectance of the standard sample, is recorded as R m ( ) . It is assumed that at a specific wavelength, the following equation holds where R m ( ) represents the reflectance of the dye solution at a wavelength of λ, that is, the reflectance of the standard sample; R i ( ) represents the reflectance of each component dye at a wavelength of λ; c i represents the concentration ratio of each component's dye, ∑ c i = 1. To achieve color spectral matching, the spectral reflectance of the calculated sample (matching sample) is the same as that of the standard sample, and the dye solutions are mixed with different concentration ratios and different colors, that is, where R s ( ) is the reflectance of the matched sample at a wavelength of zero.
The deviation is determined by the least square method. According to the color measurement range of the chromatography (400-700 nm), the wavelength interval is 20 nm, according to the formula: The column vector F m represents the f [R m ( )] value of the standard sample; the column vector A represents the concentration ratio of different monochromatic dyes; the matrix represents the f [R i ( )] value of the monochromatic dye.
The above conversion matrix form is expressed as: Because Δ tends to be extremely small, the partial derivatives to the concentration ratio are all zero, and thus, The concentration ratio A of monochrome dyes of different colors can be obtained.

Determination of Stearns-Noechel model parameter M
In 1944, Stearns and Noechel proposed a model of colored fiber reflectance addition and color mixing in Duntley through a large number of experiments and used black and white wool fibers for color mixing experiments (Ma et al. 2018). They proposed an empirical equation called Stearns-Noechel model: where M is a variable and R( ) is the reflectance at a wavelength of λ.
From Eq. (13), the relationship between the reflectance R( ) and the intermediate function f [R( )] can be derived as follows: According to Eq. (14), the determination of the value of the unknown parameter M in the equation is the first problem to be solved.
The specific idea of solving the value of unknown parameter is the reflectance of the mixed dye obtained by the color measurement, using MATLAB to cyclically assign the parameter M, fitting the spectral reflectance, and combining the spectral reflectance to find the optimal value of M when the color difference is the smallest. In this experiment, the optimal parameter M value was calculated based on the 14 groups of three-color mixed dyes with different concentration ratios, that is,

Optimizing the prediction formula of the Stearns-Noechel model
To make the final experimental equation more accurate, the original model was modified and improved in this study. The specific experimental process is shown in Fig. 4. As shown in the flowchart in Fig. 4, the spectral color-matching algorithm based on the Stearns-Noechel model corrects the fitted reflectance curve to obtain the dyeing formula, that is, the concentration ratio of each monochrome dye and the fitted color difference value. Among them, where c j indicates the concentration of the j th dye, R s ( ) indicates the spectral reflectance of the formula, R m ( ) indicates the spectral reflectance of the standard sample, Δc indicates the difference in the proportion of the dyes in each component, and Δf indicates the difference between the formula reflectance and the standard  Fig. 4 Calculation of the color difference using optimized algorithm model 1 3 sample reflectance. To improve the accuracy of the correction, Δc is a correction variable that reduces Δf to 0; thus, The basic idea of the particle swarm optimization algorithm is that the algorithm based on particle swarm optimization initializes the particle swarm parameters after determining the fitting correction coefficient, randomly generates particle swarm concentration c j (j ∈ [1, N]) in the feasible solution space, and then corrects the individual particle position, and adjusts the generation according to the particle swarm algorithm. The concentration formula is then subjected to color difference fitting. Finally, the color difference value within the specified range was obtained and the monochrome density ratio and the fitted color difference value were outputs.
The algorithm steps are as follows: (1) Determine the standard color and solve the correction coefficient a 1 , a 2 , a 3 through polynomial fitting; (2) Initialize the particle swarm algorithm parameters. Randomly generate an initial population of c = {c 1 , c 2 , ..., c N } in the feasible solution space based on the actual problem, and calculate the fitness value of each particle through the fitness function, of which c j (j ∈ [1, N]) randomly generated concentration formulas to be sought; (3) Correct the individual particle position and perform the particle swarm algorithm adjustment on the formula generated in Step (2) to generate a new concentration formula; (4) Check the end condition, set the end condition to | | | fit p | | | < Error or reach the maximum number of iterations, and check whether the end condition is met. If not, repeat Step (3).

Calculation of color difference
According to Eq. (5), f [R s ( )] was obtained, and Eq. (3) was used to calculate R s ( ) in reverse, which was the reflectance of the initial formula fitting color at the wavelength of λ. R m ( ) was also obtained. Different illuminations adversely affect color difference evaluation of textile images in dyed fabrics. Therefore, an integrated particle swarm optimization based on rotating forest (RF) and sparse least square support vector regression (RF-PSO-SLSSVR) was proposed to establish an accurate illumination correction model (Zhou et al. 2019). In addition to the lighting conditions, the factors affecting chromatic aberration also need to be classified. In addition to the lighting conditions, the factors affecting chromatic aberration also need to be classified. To mitigate the problem of low classification accuracy in solid color printing and dyeing, a color difference classification model based on the differential evolution (DE) improved whale optimization algorithm (WOA) for extreme learning Δc machine (ELM) optimization, and the model has strong generalization ability (Zhou et al. 2020). At the same time, the color difference classification is based on the establishment of a color difference classification model for printing and dyeing products, and a gray wolf algorithm optimization support vector machine based on the differential evolution model is proposed (Zhou et al. 2018). This method has high classification accuracy, good stability, and generalization ability. Thus, the experimental results were evaluated using the CIEDE2000 color difference evaluation standard. The CIEDE2000 color difference formula is a color evaluation formula proposed by the International Commission on Illumination in 2000. It introduced different parameters to adjust the weight of the color differences of ΔL , ΔC , and ΔH in the total color difference. Because of the difference between the color evaluation measurement data and the visual result, there is a difference between the color evaluation method and the shape. The evaluation method is shown in formula (17): where K L , K C , K H are correction coefficients related to the experimental conditions, S L , S C , and S H are weight coefficients for correcting the uniformity of the color space, R T is a rotation function that corrects the deflection of the elliptical principal axis of the tolerance in the blue region of the color space, L = L * brightness, chroma, The fitted color difference values of different mixed dye mass ratios are calculated according to formula (17). Table 2 shows the fitted color difference based on the spectrum, Table 3 shows the fitted color difference based on the optimized Friele model, and Table 4 shows the fitted color difference based on the optimized The sample area of natural wood is selected, as shown in Fig. 5A-C representing the detection area selected from the red wing wood, black sour wood, and black wing wood samples, respectively, and the veneer renderings obtained by dyeing according to the sample area. Using hyperspectral equipment to detect the sample veneer, the spectral reflectance curve of each sample veneer is shown in Fig. 6. Table 5 shows the reflectance data of the sample veneer and the dyed veneer. Fitting the reflectance curve according to the reflectance data is shown in Fig. 7. It can be seen from the error comparison of fitting reflectance curve in Fig. 7 and data analysis in Table 5 that the revised model used in this paper can effectively improve the color-matching efficiency and accuracy compared to the original model. From the color difference results, when the parameter values were fixed, the average fitted color difference was 0.8202. After improving and optimizing the Friele model, the average fitted color difference was 0.7287. After improving and optimizing the Stearns-Noechel model, the average fitted color difference was 0.6482. The color difference result was ideal and close to the real formula, indicating that the color-matching effect of the dyeing was greatly improved after the model was improved. By a comparison, the particle swarm improved Stearns-Noechel model was more accurate for wood color matching than the Friele model. performance was improved, which was close to the real formula. The optimized Stearns-Noechel algorithm enhanced the dyeing efficiency and accuracy. The color-matching result was more accurate, which is applicable to the wood dyeing industry and has good potential for the practical production.  Open Access This article is licensed under a Creative Commons Attribution 4.0 International License, which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons licence, and indicate if changes were made. The images or other third party material in this article are included in the article's Creative Commons licence, unless indicated otherwise in a credit line to the material. If material is not included in the article's Creative Commons licence and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder. To view a copy of this licence, visit http://creat iveco mmons .org/licen ses/by/4.0/.