# A Machine Vision-Based Algorithm for Color Classification of Recycled Wool Fabrics
## 2 Materials and Methods
### PNN-Based Algorithm  
As already mentioned in the process described in this paper, the aim was to provide the target class starting from a given image of a fabric. Therefore, as stated above, each element of the training set consisted of four parameters describing the number of pixels belonging to a given RAL color among the 313 possible varieties. The target set, instead, consisted of a given class (from 1 to 40). Figure 4: Average number of pixels belonging to a given RAL class for the whole set of images processed for the training set. Figure 5: Indexed image and surface of the R channel for fabric with label \(20/6/21\). In more detail, the training set consisted of the following matrix \(\mathbf{Tr}\) (size \(313\times 800\)). \[\mathbf{Tr}= \begin{bmatrix}p^{1}{}_{RAL1}&p^{2}{}_{RAL1}&\dots&p^{800}{}_{RAL1}\\ p^{1}{}_{RAL2}&p^{2}{}_{RAL2}&\dots&p^{800}{}_{RAL2}\\ \dots&\dots&\dots&\dots\\ p^{1}{}_{RAL313}&p^{2}{}_{RAL313}&\dots&p^{800}{}_{RAL313}\end{bmatrix}  \tag{1}\]  
where \(\mathbf{p^{i}}_{RALj}\) is the number of pixels indexed in \(j\)th RAL color for the \(i\)th fabric sample. Such values were normalized using min-max normalization since the image size for all samples was the same. Each column of the target matrix had four values different from zero and the remaining values were equal to zero, since it was decided to limit the number of RAL colors to four. However, increasing the number of indexes in case a researcher aimed to test different solutions was straightforward. The target set was composed by the matrix \(\mathbf{T}\) (size \(1\times 40\)). The \(k\)th column \(\mathbf{T_{k}}\) of \(\mathbf{T}\) was a vector with a value equal to \(1\) in the kth position and \(0\) elsewhere. The chosen network could not be unsupervised (such as, for instance, self-organizing mapping [SOM]) since the goal of the current work was to develop a classification system that considered human-related experience. Therefore, the proper structure was a probabilistic neural network. As recognized in the scientific literature [21; 22], probabilistic neural networks (PNNs) can be used for classification problems. A probabilistic neural network (PNN) is a feed-forward neural network in which connections between nodes do not form a cycle. Therefore, this classifier can estimate the probability density function (PDF) of a given set of data. When an input is presented to such a neural network, a probabilistic layer organizes the learning set by representing each training vector by a hidden neuron that records the features of this vector. During inference, each neuron calculates the Euclidean distance between the input test vector and the training sample, then applies the radial basis kernel function. In this way, it encodes the PDF centered on each training sample or pattern. A second layer, named the summation layer, computes the average of the output of the pattern units for each class. Each class has a single neuron, to which all of the neurons in that class's pattern layer are connected. A third layer, called the competitive layer, selects the maximum value from the summation layer, and the associated class label is determined accordingly. Since the aim here was to produce a vector of probabilities instead of a single class decision, the competitive layer in the PNN was replaced with a linear layer [23]. Figure 6 shows the architecture of the selected PNN. Figure 6: PNN architecture. Once trained, the network is able to correlate the training set elements to the target ones. In other words, the network was able to receive, as input, any vector \(s\) of the four elements (composed by the number of normalized) pixels:  
\[input(PNN)=[p^{s}{}_{RAL1},p^{s}{}_{RAL2},\ldots,p^{s}{}_{RAL313}] \tag{2}\]  
The PNN will provide, as output, a vector of 40 elements where the \(k\)th value \(q_{k}\) indicates the probability that the input vector belongs to that class.