# Efficient Implementation of Matrix-Based Image Processing Algorithms for IoT Applications
## 2 The Algorithm Description
\(\mathbf{D=\Phi,D=0,N=0\) /*define a set \(\mathbf{D}\) with \(D\) elements chosen from input vector \(\mathbf{x}_{b}\)*/  
while(\(D<T\) and \(n<N_{max}\)) /*\(T\) is the maximum number of elements in \(\mathbf{D}\)*/  
/*\(n\) index of current iteration, \(N_{max}\) maximum number of iterations*/  
\(n=n+1\)  
_randomly choose \(\mathbf{S}\)_ with \(\mathbf{S}\) numbers from \(0\) to \(N-1\) /*define set \(\mathbf{S}\) with \(\mathit{S}\)elements*/  
\(\mathbf{A=W^{-1}\)[null elements on row \(i\in\mathbf{S}\) /*A is DCT matrix with rows index in set \(\mathbf{S}\)*/  
/* all rows with index in \(\mathbf{S}\) are zero*/  
function \(\mathbf{X}_{{}_{b}}=\mathit{CSrec}(\mathbf{y},\mathbf{A},\mathit{k})\) /*determine the best k DCT coefficients /* / /*to reconstruct the input (remove noise and compress it)*/  K = \(\Phi,\mathbf{e}=\mathbf{y}\) /*define a set K with the indexes of maximum values of \(\mathbf{\left|A^{\tau}e\right|*/}\) /*eis the error between observations \(\mathbf{y}\) and reconstructed */ /*observation \(\mathbf{y}_{\mathit{\pm}}\)*/ for i = 1 to k /*p is the index of maximum element of \(\mathbf{\left|A^{\tau}e\right|*/}\) / K = K \(\cup\)p /*add p in the set K*/ / \(\mathbf{A}_{\mathit{k}}=\mathbf{A}\)[null elements on column ] /*K /*A\({}_{\mathit{k}}\) is matrix with matrix \(\mathbf{A}\) columns indexes in K*/ \(\mathbf{X}_{{}_{b}}=\mathit{pseudoint}(\mathbf{A}_{\mathit{k}}^{\tau} \mathbf{A}_{\mathit{k}})(\mathbf{A}_{\mathit{k}}^{\tau}\mathbf{y})\)*/ /*determine reconstructed vector \(\mathbf{y}_{\mathit{\pm}}\)*/ \(\mathbf{e}=\mathbf{y}-\mathbf{y}_{\mathit{\pm}}\) /*error*/ end for \(\mathbf{X}_{{}_{b}}=\mathbf{X}_{{}_{b}}\)[null elements of index i \(\in\) K /*determine the best k DCT coefficients \(\mathbf{X}_{{}_{b}}\)*/ /*as elements of \(\mathbf{X}_{{}_{b}}\) with index in K*/ end function (b) ```
**function B = pseudoint(\(\mathbf{A}\))**  
\(\alpha=\mathsf{1}/\max\) element of \((\mathbf{A}\mathbf{A}^{\tau})\)**  
\(\mathbf{A0}=\alpha\mathbf{A}^{\tau}\) /*initial inverse matrix*/ \(while(err<e\) and iter<\(\mathit{NR}_{\_{\_}{\max}})\) /*update inverse matrix until*/ /*the error is smaller than \(e\)*/ /*or themaximum number of iterations /*iter exceeds \(\mathit{NR}_{\_}{\_}{\_}{\max}\)*/ \(\mathbf{A1}=\mathbf{A0}+(\mathbf{1}-\mathbf{A0}.\mathbf{A}).\mathbf{A0}\) /*determine inverse \(\mathbf{A1}\)*/ \(err=\max\) element of \(\{(\mathbf{A}.\mathbf{A1}.\mathbf{A}-\mathbf{A}),(\mathbf{A1}.\mathbf{A1}- \mathbf{A1})\}\) /*compute error*/ \(iter=iter+1\) /*increments the number of iterations*/ \(\mathbf{A0}=\mathbf{A1}\) /*update \(\mathbf{A0}\)*/ end while \(\mathbf{B}=\mathbf{A1}\) /*saveinverse*/ end function (c)
```

**Figure 1**. The CS-RANSAC algorithm. (**a**) CS-RANSAC algorithm (**b**) Compressive sensing function (c) Pseudo-inverse function. ## 3 The Algorithm Performance Evaluation

This section describes the performance of the above-described algorithm in terms of the quality of the reconstructed image. The selected parameters of the algorithm were: \(\mathbf{B}=\mathbf{4}\), \(\mathbf{S}=\mathbf{15},\mathbf{k}=\mathbf{3}\). The image size was set to 512 pixels in height and 512 pixels in width [18] (for both type of implementations--MATLAB and microcontrollers). Gaussian noise, salt and pepper noise (impulsive), and multiplicative noise (speckle) were successively added to the test images. Additionally, the image was blurred. The performance of the algorithm was evaluated using the peak signal to noise ratio \(\mathbf{PSNR}=\mathbf{0}\mathbf{log_{10}}\frac{\mathbf{\log_{10}}}{\frac{\mathbf{\log_{10}}}{\mathbf{ \log_{10}}}\frac{\mathbf{\log_{10}}}{\bm



Table 1 summarizes the performance of the CS-RANSAC algorithm compared with DCT denoising at the same level of sparsity. One can observe that the performance is better for the CS-RANSAC algorithm both for PSNR and SSIM criteria.