# Hamming Code Strategy for Medical Image Sharing
## 3 Hamming Codes
### Using (7,4) Hamming Code  
This shadows generation algorithm will produce two shadows (\(S_{1}\) and \(S_{2}\)) from two medical images \(I_{1}\) and \(I_{2}\). It manipulates the images at pixel level, therefore, one pixel from each original image will be picked sequentially for creating a new pair of pixels of the two shadows. Suppose that pixel \(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}\)] from \(I_{1}\) 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}\)] from \(I_{2}\) are selected as shown in Figure 1, where \(i_{1,1}\), \(i_{1,2}\),..., \(i_{1,8}\) and \(i_{2,1}\), \(i_{2,2}\),..., \(i_{2,8}\) are the bits in those two pixels. Two corresponding pixels \(P^{\prime}_{1}\) and \(P^{\prime}_{2}\) on shadows \(S_{1}\) and \(S_{2}\) are produced as follows:  
**Algorithm:** Shadow generation algorithm  
**Input:**\(P_{1}\) and \(P_{2}\)  
**Output:**\(P^{\prime}_{1}\) and \(P^{\prime}_{2}\)  
**Step 1. ** Assign [\(d_{1}d_{2}d_{3}d_{4}\)] = [\(i_{1,1}\)\(i_{1,2}\)\(i_{1,3}\)\(i_{1,4}\)], and [\(x_{1}\)\(x_{2}\)\(x_{3}\)] = [\(i_{2,1}\)\(i_{2,2}\)\(i_{2,3}\)]. **Step 2. ** Use (7, 4) Hamming code to compute \(c=d*G\) = [\(p_{1}\)\(p_{2}\)\(p_{3}\)\(d_{1}\)\(d_{2}\)\(d_{3}\)\(d_{4}\)]. **Step 3. ** For the codeword \(c\), flip one bit at the position (\(x_{3}\)\(x_{2}\)\(x_{1}\))\({}_{2}\), where \(x_{1}\) is the least significant bit, to output a new 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 4. ** Construct two new pixels \(P^{\prime}_{1}\) and \(P^{\prime}_{2}\) on shadows as the following. \(P^{\prime}_{1}\) = [\(o_{1,1}\)\(o_{1,2}\)\(o_{1,3}\)\(o_{1,4}\)\(o_{1,5}\)\(o_{1,6}\)\(o_{1,7}\)\(o_{1,8}\)]  
= [\(d^{\prime}_{1}\)\(d^{\prime}_{2}\)\(d^{\prime}_{3}\)\(d^{\prime}_{4}\)\(i_{1,5}\)\(i_{1,6}\)\(i_{1,7}\)\(i_{1,8}\)],  
and  
\(P^{\prime}_{2}\) = [\(o_{2,1}\)\(o_{2,2}\)\(o_{2,3}\)\(o_{2,4}\)\(o_{2,5}\)\(o_{2,6}\)\(o_{2,7}\)\(o_{2,8}\)]  
= [\(p^{\prime}_{1}\)\(p^{\prime}_{2}\)\(p^{\prime}_{3}\)\(i_{2,5}\)\(i_{2,6}\)\(i_{2,7}\)\(i_{2,8}\)]. The above procedure runs through every pixel in the original images subsequently and produces the corresponding pixels for the shadows. Moreover, we alternately pick \(P_{1}\) and \(P_{2}\) (i.e., in the previous  
Figure 1: Shadow construction process using (7,4) Hamming code. round \(P_{1}\) was selected from \(I_{1}\), then it will be obtained from \(I_{2}\) in the next round) to make sure that the shadows are very much different from the original images. **Example 3**. : _Suppose that two pixels selected from two medical images are \(P_{1}\) = [0 1 1 0 1 1 0 1] and \(P_{2}\) = [1 0 1 0 0 1 0 1]. To generate two shadow pixels \(P^{\prime}{}_{1}\) and \(P^{\prime}{}_{2}\), the following steps are executed:_  
**Step 1. ** Determine \(d\) and \(x\) from \(P_{1}\) and \(P_{2}\), \(d\) = [0 1 1 0] and \(x\) = [\(x_{1}\)\(x_{2}\)\(x_{3}\)] = [1 0 1]. **Step 2. ** Encode d using (7, 4) Hamming code, we get  
\[c =d*G=\Big{[} \begin{array}{cccccc}0&1&1&0\end{array} \Big{]}*\left[ \begin{array}{cccccc}1&1&0&1&0&0&0\\ 1&0&1&0&1&0&0\\ 0&1&1&0&0&1&0\\ 1&1&1&0&0&0&1\end{array} \right]\] \[=\Big{[} \begin{array}{cccccc}1&1&0&0&1&1&0\end{array} \Big{]}.\]  
**Step 3. ** Since \(x\) = [1 0 1], flip the 5 th bit (from left) of c to get \(c^{\prime}\) = [1 1 0 0 0 1 0]. **Step 4. ** Since \(d^{\prime}\) = [0 0 1 0] and \(p^{\prime}\) = [1 1 0], two pixels \(P^{\prime}{}_{1}\) = [0 0 1 0 1 1 0 1] and \(P^{\prime}{}_{2}\) = [1 1 0 0 0 1 0 1] can be constructed. We can see that the first four bits in \(P_{1}\) have been changed from 0110 to 0010 in \(P^{\prime}{}_{1}\). The pixel \(P^{\prime}{}_{2}\) has also changed since the first three bits have been changed from (101) to (110).