# Efficient Implementation of Matrix-Based Image Processing Algorithms for IoT Applications
## 2 The Algorithm Description
\begin{table}
\begin{tabular}{c c c c c c c c c c} \hline \hline \multirow{2}{*}{**Noiced Image**} & \multicolumn{2}{c}{**DCT Reconstructed**} & \multicolumn{2}{c}{**CS-RANSAC**} & \multirow{2}{*}{**DCT Reconstructed Image (MATLAB)**} & \multicolumn{2}{c}{**CS-RANSAC**} \\  & \multicolumn{2}{c}{**Image (Fixed Point**} & \multicolumn{2}{c}{**Reconstructed Image (Fixed Point 32 Bits )**} & \multicolumn{2}{c}{**DCT Reconstructed Image (MATLAB)**} & \multicolumn{2}{c}{**Reconstructed Image (MATLAB)**} \\ \hline
**PSNR** & **SSIM** & **PSNR** & **SSIM** & **PSNR** & **SSIM** & **PSNR** & **SSIM** & **PSNR** & **SSIM** \\ \hline
20.48 & 0.36 & 23.92 & 0.46 & 26.04 & 0.59 & 24.04 & 0.46 & 28.14 & 0.63 \\ \hline
17.14 & 0.21 & 20.8 & 0.29 & 24.18 & 0.54 & 20.91 & 0.29 & 26.92 & 0.58 \\ \hline
14.29 & 0.15 & 17.87 & 0.21 & 22.21 & 0.62 & 18.03 & 0.21 & 25.41 & 0.71 \\ \hline \hline \end{tabular}
\end{table} 
Table 3: Performance comparison (32-bit fixed-point vs. MATLAB implementation). Figure 7: Performance evaluation for impulsive noise (microcontrollers implementation). One can observe, for medium to high noise, that the execution time is reasonable (about seconds). The execution time can be decreased by using a dual-core Blackfin processor. An implementation based on an accelerator for convolutional neural networks (CNNs) is possible by implementing matrix multiplication using a \(1\times 1\) convolution performed with CNN. ## 6 The Improvement of Processing Time Using CNN Accelerator

The multiplication of two matrices \(\mathbf{A}= \begin{bmatrix}a_{ij}\end{bmatrix} \) and \(\mathbf{B}= \begin{bmatrix}b_{ij}\end{bmatrix} \) with the result \(\mathbf{C}=\mathbf{A}\mathbf{B}= \begin{bmatrix}c_{ij}\end{bmatrix} \) and \(i,j=1\ldots N\) can be performed using a fully interconnected layer as in Figure 8:

The input layer consists of each row in matrix \(\mathbf{A}\) and the output layer contains the elements of the product matrix. For each input element, the weights are the corresponding elements of columns in matrix \(\mathbf{B}\) or zero elements. For clarity, only the weights for one output elements are shown. Figure 9 details the weights for a simple example (\(N=2\)):

\[\mathbf{A}= \begin{bmatrix}a_{11}&a_{12}\\ a_{21}&a_{22}\end{bmatrix} \text{and }\mathbf{B}= \begin{bmatrix}b_{11}&b_{12}\\ b_{21}&b_{22}\end{bmatrix} \text{then }\mathbf{C}=\mathbf{A}\mathbf{B}= \begin{bmatrix}c_{11}&c_{12}\\ c_{21}&c_{22}\end{bmatrix} =\] \[ \begin{bmatrix}a_{11}b_{11}+a_{12}b_{21}&a_{11}b_{12}+a_{12}b_{22} \\ a_{21}b_{11}+a_{22}b_{21}&a_{21}b_{12}+a_{22}b_{22}\end{bmatrix} \]

For more clarity, the weights have been shown individually for each output element. The neural network fully interconnected layer has the output \(c_{11}=a_{11}b_{11}+a_{12}b_{21}+a_{12}0+a_{12}0\) and so on. One can observe this layer outputs exactly the product matrix elements. \begin{table}
\begin{tabular}{c c c c c} \hline \hline \multicolumn{1}{c}{**Noised Image**} & \multicolumn{2}{c}{\
\begin{tabular}{c} **Execution Time CS-RANSAC 32** \\ **Bits Fixed Point** \\ \end{tabular} } & \multicolumn{2}{c}{
\begin{tabular}{c} **Execution Time** \\ **CS-RANSAC MATLAB** \\ \end{tabular} } \\ \hline
**PSNR** & **SSIM** & **Cycles** & **Time** & **Time** \\ \hline
20.48 & 0.36 & 4,675,862,063 & 6.23 & 2.49 \\ \hline
17.14 & 0.21 & 5,662,802,735 & 7.55 & 4.79 \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Execution time—seconds (32-bit fixed-point vs. MATLAB implementation). Figure 8: Neural network fully interconnected layer used for matrix multiplication. The implementation of the fully interconnected layer can be done in CNN by enabling the flatten mode (this mode supports a series of 1 \(\times\) 1 convolution emulating a fully interconnected network with up to 1024 inputs). Matrix multiplication (fixed point) is shown in Figure 10.

Using the above algorithm, a speedup about 30 times can be achieved for integer matrix multiplication, comparing with the implementation on a 32-bit fixed-point microcontroller.