## 4 The Proposed Selective Retransmission Mechanism
### Measuring the Image Quality  
When the two proposed DWT-based selective retransmission mechanism is employed in wireless image sensor networks, some packets containing visual information may be lost according to their Data Relevance and the packet error rate in each link from the source to the sink. The received payloads will be used to reconstruct an approximated version of the original image by an inverse DWT, where we consider that the lost information (if any) will be replaced by zeros for simplicity. As some less relevant packets may be corrupted and discarded during transmission, resulting in energy saving when those packets are not retransmitted and not acknowledged, the final image quality will be typically lower than the original image quality.  
The simpler way to assess the quality of an image transmission is to count the number of packets received by the sink. The formulation in Equation (28) presents the average success ratio (\(S_{I}\)) when a 2D DWT is applied only once, where the maximum attainable success ratio is 1.0 when all packets are always retransmitted if lost or no bit-errors occur during transmission. \(V_{0}\) e \(V_{255}\) are the proportion of data received for packets with DR = 0 and DR = 255, respectively.  
\[\begin{split} V_{0}=1\\ V_{255}=\frac{U_{pi}\,I_{\cdot}\prod\limits_{j=1}^{H_{p}}\left(1-Pt _{pj}\right)+Lu_{pi}\,\prod\limits_{j=1}^{H_{p}+1}\left(1-Pu_{pj}\right)}{ \left[\frac{B_{i}*3}{4}\right]}\\ S_{1}=\frac{25\,V_{0}+75\,V_{255}}{100}\end{split} \tag{28}\]  
When we apply a 2-level 2D DWT, we achieve the average success ratio \(S_{2}\), as presented in Equation (29). Note that we only count packets transmitted before hop \(DR\) for \(V_{DR}\) (proportion of data received for packets transmitted in a semi-reliable way), since all packets after it are reliably transmitted to the sink.  
\[\begin{split} V_{DR}=\frac{Q_{pi}\,J_{\cdot}\prod\limits_{j=1}^{ DR}\left(1-Pt_{pj}\right)+Lq_{pi}\,\prod\limits_{j=1}^{DR}\left(1-Ptq_{pj} \right)}{\left[\frac{B_{i}*3}{16}\right]}\\ S_{2}=\frac{6.25\,V_{0}+18.5\,V_{DR}+75.V_{255}}{100}\end{split} \tag{29}\]  
\(S_{I}\) and \(S_{2}\) show the average percentage of received data when compared with the total visual information of the original image, but do not give us a good indication of the quality of the reconstructed image, since the packets' payloads have different relevancies for the reconstruction of the original image. A common approach to measure such quality is the Peak Signal-to-Noise Ratio (PSNR), as defined in Equation (30). The value for \(x\) is the number of bits to represent a pixel: for example, every pixel in a grayscale image may be represented by 8 bits, but more bits are required for RGB color images.  
\[PSNR_{pi}=10\log_{10}\frac{\left(2^{x}-1\right)^{2}}{MSE_{pi}} \tag{30}\]  
performance values. Moreover, the quality of the reconstructed image is simulated when some packets are lost, computing the average success ratio and the equivalent PSNR.  
For the experiments, the transmission of a single uncompressed 128 \(\times\) 128 8-bit grayscale image was considered, as presented in Figure 5. The image size in question was 16,384 bytes plus an image header of 40 bytes, since the transmission of bitmap images was considered, and 40 bytes is the most common size of bitmap image headers. Thus, \(B_{i}\) + \(i_{o}\) = 16,424 bytes. The maximum packet size is 127 bytes (\(s\) = 127 \(\times\) 8 bits), the total protocol headers is defined as 30 bytes (\(k\) = 30 \(\times\) 8 bits), the fragmentation header was defined having 8 bytes (\(f\) = 8 \(\times\) 8 bits) and DR sizes 1 byte, as expected. So, in the mathematical verifications, \(l\) = 88 bytes. We also define \(a\) = 40 bytes.