# Image Transmission over Cognitive Radio Networks for Smart Grid Applications
## 3 Proposed MAC Layer for Image Streaming over CRSNs
### The Proposed Method to Improve the PSNR: SAFE Method  
In the proposed MAC model, we urge to minimize the average time overhead due to both spectral measurement and retransmission. With this aim, the probability of successful transmission of an image within the allowed time domain (\([0,D_{max}]\)) can be raised. If arrival rates of the PUs increase, the probability of collision will be higher. In this condition, retransmission of packets also enlarges and consequently, the number of iterations that needed for spectral sensing goes up. This means that some parts of the image, where were saved in the sending buffer, do not get the opportunity to be sent. In this case, depending on what extent the packet loss rate (PLR) is, the amount of PSNR can be greatly reduced. Zero-padding is an approach that the receiver runs when data loss occurs in the receiving image. Although there are several methods such as filtering and smoothing the image to increase the PSNR, in this case in which multiple consecutive rows of input image were lost, they are not effective approaches. Here, conventional methods not only are not effective but also they can even lead to further reduction of the PSNR. To improve PSNR, our proposed algorithm which is called Scrambling and Filtering based Enhancement (SAFE) is added to solve the issue at the sender instead of the receiver. So, we first rearrange all the pixels within the image in the transmitter before sending it. After receiving the image in unordered pixels, we reconstruct it and apply a \(3\times 3\) smoothing filter to make it smoother. The proposed algorithm is as follows in Algorithm 2.  
```
1. Get an Input Image: \(I_{Sender}=\{I_{Red},I_{Green},I_{Blue}\}with\quad r\times c\quad pixels\)
2. Apply Transmission Function\(T_{g(x,y)}:\hat{I}=T_{g(x,y)}\{I(x,y)\}\) Split\(I\) to \(\{I_{Red},I_{Green},I_{Blue}\}\)
3. Rearrangement of \(\hat{I}\) to make \(D_{S}:D_{S}=\{[I_{Red}(Row_{1}),I_{Green}(Row_{1}),I_{Blue}(Row_{1})]\ldots\) \(\ldots[\hat{I}_{Red}(Row_{2}),\hat{I}_{Green}(Row_{2}),\hat{I}_{Blue}(Row_{2})]\ldots\) \(\ldots[[I_{Red}(Row_{r}),I_{Green}(Row_{r}),I_{Blue}(Row_{r})]\}\)
```  
**Algorithm 2** SAFE  
Now, having data available to send, the transmitter runs SS and selects the best channel calling the proposed MOTS method. Then, it recalls the proposed JOPSS method to choose the optimal values for both packet length of and number of iterations, \(\{X^{*},(\tau_{P}^{i})^{*}\}\), simultaneously. The transmitter gets \(D_{S}\), splits it to multiple frames with \((\tau_{P}^{i})^{*}\)size and sends \(X^{*}\) packets with this size. The procedure will be continued until the transmission of the last bit before the timeout event.  
In the receiver, \(D_{S}^{*}\) is received and it will be ideally \(D_{S}^{*}=D_{S}\), but due to interference and the timeout, some pixels were missed. The receiver is capable to make the image \((\hat{I})^{*}\) from \(D_{S}^{*}\) and reconstructing the image \(I_{Sender}^{*}\) by applying the transfer function \(T_{g(x,y)}^{-1}\) to the obtained image \((\hat{I})^{*}:\)  
\[I_{Sender}^{*}=T_{g(x,y)}^{-1}\{(\hat{I})^{*}\} \tag{27}\]  
Ultimately, the receiver can interpolate and modify the amount of each pixel with 8 adjacent pixels by applying a \(3\times 3\) smoothing filter. Found on the proposed SAFE method, the consecutive rows of black pixels, which resulted from zero-padding the last sub channel of the image due to missed data, are distributed in all sub channels (instead of just one channel). As a result, a noticeable improvement can be achieved. More details are discussed in Section 4.