# Hamming Code Strategy for Medical Image Sharing
## 3 Hamming Codes
### Using (7,4) Hamming Code
As we mentioned earlier, \(P_{1}\) and \(P_{2}\) are selected alternately from the medical images \(I_{1}\) and \(I_{2}\) to ensure that changes are spread evenly between the two shadows images. The above algorithm demonstrates how to create two shadow images from two medical images. The original image reconstruction algorithm shows how to reproduce the original images from the two shadows. Suppose that pixels \(P^{\prime}{}_{1}\) and \(P^{\prime}{}_{2}\) are selected from shadows \(S_{1}\) and \(S_{2}\) in turn. The following steps are performed to reconstruct the original images. **Algorithm:** Original images reconstruction algorithm  
**Input:**\(P^{\prime}{}_{1}\) and \(P^{\prime}{}_{2}\)  
**Output:**\(P_{1}\) and \(P_{2}\)  
**Step 1. ** Assign [\(d^{\prime}{}_{1}\)\(d^{\prime}{}_{2}\)\(d^{\prime}{}_{3}\)\(d^{\prime}{}_{4}\)] = [\(o_{1,1}\)\(o_{1,2}\)\(o_{1,3}\)\(o_{1,4}\)] from first four bits of \(P^{\prime}{}_{1}\), and [\(p^{\prime}{}_{1}\)\(p^{\prime}{}_{2}\)\(p^{\prime}{}_{3}\)] = [\(o_{2,1}\)\(o_{2,2}\)\(o_{2,3}\)] from first three bits of \(P^{\prime}{}_{2}\). **Step 2. ** Construct the codeword \(c^{\prime}\) = [\(p^{\prime}{}_{1}\)\(p^{\prime}{}_{2}\)\(p^{\prime}{}_{3}\)\(d^{\prime}{}_{1}\)\(d^{\prime}{}_{2}\)\(d^{\prime}{}_{3}\)\(d^{\prime}{}_{4}\)]. **Step 3. ** Compute the syndrome s = [\(s_{3}\)\(s_{2}\)\(s_{1}\)] = \(c^{\prime}*H^{\rm T}\). **Step 4. ** If s is not equal to [0 0 0], go to Step 5; or else, stop the algorithm and return \(P_{1}\) = \(P^{\prime}{}_{1}\) and \(P_{2}\)=\(P^{\prime}{}_{2}\). **Step 5. ** Find the position of (\(s_{3}\)\(s_{2}\)\(s_{1}\)) in \(H^{\rm T}\), i.e., (\(x^{\prime}{}_{3}\)\(x^{\prime}{}_{2}\)\(x^{\prime}{}_{1}\))\({}_{2}\) and then obtain the correct codeword [\(p_{1}\)\(p_{2}\)\(p_{3}\)\(d_{1}\)\(d_{2}\)\(d_{3}\)\(d_{4}\)]. **Step 6. ** Output the pixels for the original medical images as shown in Figure 2. The pixels \(P_{1}\) and \(P_{2}\) are reconstructed as follows:  
\(P_{1}\) = [\(i_{1,1}\)\(i_{1,2}\)\(i_{1,3}\)\(i_{1,4}\)\(i_{1,5}\)\(i_{1,6}\)\(i_{1,7}\)\(i_{1,8}\)]  
= [\(d_{1}\)\(d_{2}\)\(d_{3}\)\(d_{4}\)\(o_{1,5}\)\(o_{1,6}\)\(o_{1,7}\)\(o_{1,8}\)],  
and  
\(P_{2}\) = [\(i_{2,1}\)\(i_{2,2}\)\(i_{2,3}\)\(i_{2,4}\)\(i_{2,5}\)\(i_{2,6}\)\(i_{2,7}\)\(i_{2,8}\)]  
= [\(x^{\prime}{}_{1}\)\(x^{\prime}{}_{2}\)\(x^{\prime}{}_{3}\)\(o_{2,5}\)\(o_{2,6}\)\(o_{2,7}\)\(o_{2,8}\)]. **Example 4**. : _In Example 3, it outputs two shadow pixels \(P^{\prime}\)1 = [0 0 1 0 1 1 0 1] and \(P^{\prime}\)2 = [1 1 0 0 0 1 0 1]. Now we apply the original image reconstruction algorithm to get back the two original pixels \(P_{1}\) and \(P_{2}\) as follows._  
**Step 1. ** Determine \(d^{\prime}\) = [0 0 1 0] and \(p^{\prime}\) = [1 1 0]. **Step 2. ** The codeword is \(c^{\prime}\) = [1 1 0 0 0 1 0]. **Step 3. ** Compute the syndrome of \(c^{\prime}\), we have  
\[s=[s_{3}s_{2}s_{1}]=c^{\prime}*H^{T}=[ \begin{array}{cccccc}1&1&0&0&0&1&0 \end{array} ]*\left[ \begin{array}{cccccc}1&0&0\\ 0&1&0\\ 0&0&1\\ 1&1&0\\ 1&0&1\\ 0&1&1\\ 1&1&1\end{array} \right]=\left[ \begin{array}{cccccc}1&0&1\end{array} \right]\]  
**Step 4. ** Since s = [0 0 1] is not equal to [0 0 0], go to Step 5. **Step 5. ** Flip the bit located at the position (1 0 1) in \(H^{T}\) (the fifth position from the left in \(c^{\prime}\), i.e., (\(x^{\prime}_{3}\)\(x^{\prime}_{2}\)\(x^{\prime}_{1}\)) = (101), and we have \(c\) = [1 1 0 0 1 1 0]. **Step 6. ** Obtain the original pixels \(P_{1}\) = [0 1 1 0 1 1 0 1] and \(P_{2}\) = [1 0 1 0 0 1 0 1]. It shows that the recovered pixels are correct; thus, the algorithms function correctly as expected. So far, we have only demonstrated how to generate shadows and reconstruct original images, but we have not mentioned exactly which bits are selected to go through the processes. In a pixel, there are three groups of bits that we can select from (a) the least significant bits, (b) the most significant bits, and (c) those bits in the middle. As shown in the experiments, we will show how the selection of the group of bits for our algorithms affects the outcomes significantly.