# Particle Swarm Optimisation in Practice: Multiple Applications in a Digital Microscope System
## 5 Colour Reproduction Accuracy
A 3 \(\times\) 3 matrix C needs to be found that minimises:  
\[\min_{\rm C}=||\rm{MC}-\rm{R}|| \tag{6}\]  
An inverse matrix can be used to solve MC = R. Add the inverse of M to each side of the equation  
\[\rm{M}^{-1}\rm{MC}=\rm{M}^{-1}\rm{R} \tag{7}\]  
As any matrix multiplied by its inverse matrix is the identity matrix I.  
\[\rm{IC}=\rm{M}^{-1}\rm{R} \tag{8}\]  
The matrix C is not changed when multiplied by an identity matrix. Figure 8:0  
However, as the matrix M and R are not square a Moore-Penrose pseudo-inverse matrix method [44; 45] is commonly used to find the matrix C. Using the openCV [9] function \"inv(DECOMP_SVD)\" to find such a matrix (called a colour correction matrix (CCM) hereafter) resulted in the values shown in Figure 8:1  
\begin{table}
\begin{tabular}{c c c c c c c c c} \hline \hline \multicolumn{2}{c}{**Measured Values**} & \multicolumn{3}{c}{**CCM**} & \multicolumn{3}{c}{**Reference Values**} \\ \hline
**R** & **G** & **B** & & & & **R** & **G** & **B** \\ \hline
0.141 & 0.098 & 0.078 & &? &? &? & &  
A standard PSO search method was used with the exception of 'Outlier Rejection'. Outlier rejection was implemented for each particle by sorting the losses for each colour and eliminating the top losses. The number of outliers can be selected from 0 to 5. The PSO settings used are shown in Figure 8:2  
Loss function: The normalised and gamma corrected measured sRGB values M were multiplied by particles colour correction matrix C. The resulting corrected colours RGB values were subtracted from the normalised and gamma corrected reference values R. The sum of the square of the absolute differences were used as the loss calculation (Equation (10)). Figure 8:3  
The PSO algorithm found a colour correction matrix (Table 8) virtually identical to the pseudo-inverse matrix method when no outliers were allowed. The total colour reproduction error was calculated which is made up of the sum of the absolute errors of each of the sRGB corrected values compared to the reference sRGB values. Pseudo-inverse matrix produced a consistent error of 310. The PSO algorithm produced errors from 308 to 310. Allowing a single outlier in the PSO algorithm reduced the error to 274, an 11.3% decrease in the colour reproduction error. Figure 13 shows colour examples (using the pseudo-inverse matrix) in groups of three. The top of each group is the uncorrected colour, the middle is the required colour and the bottom is the corrected colour. Three examples are highlighted by a yellow border where the colour matching have noticeably improved with the PSO algorithm. \begin{table}
\begin{tabular}{c c c} \hline
1.855 & \(-\)0.750 & \(-\)0.174 \\ \(-\)0.252 & 1.567 & \(-\)0.382 \\
0.079 & \(-\)0.649 & 1.471 \\ \hline \end{tabular}
\end{table} 
Table 6: CCM calculated using pseudo-inverse. \begin{table}
\begin{tabular}{l l} \hline
**Parameter** & **Value** \\ \hline \(NP\) & 50 \\ Velocity Limits & \(-\)0.3 to 0.3 \\ Particles Initial Values & Random number ( \(-\)2.5, 2.5 ) \\ \(c_{1}\) & 0.90 \\ \(c_{2}\) & 0.50 \\ W & 0.9 \\ Outliers & 0/1 \\ Stopping Criteria & Stop if the loss is not changing for 100 cycles \\ \hline \end{tabular}
\end{table} 
Table 7: PSO settings for the distortion correction task. Figure 13: Examples of colour comparisons using pseudo-inverse matrix. \begin{table}
\begin{tabular}{c c c} \hline
1.856 & \(-\)0.751 & \(-\)0.174 \\ \(-\)0.252 & 1.567 & \(-\)0.382 \\
0.078 & \(-\)0.639 & 1.470 \\ \hline \end{tabular}
\end{table} 
Table 8: CCM found using PSO. The PSO algorithm found a colour correction that gave an equal or better result than the pseudo-inverse matrix 100 times out of 100 times it was run. The number of cycles to perform a search varied between 320 and 680.