Histogram Equalization Neighbors
1. **Problem d: Perform histogram equalization** for an image with 16 gray levels ($L=16$) and total pixels $n=360$ with given frequencies $n_i$.
2. **Histogram equalization formula:** The new gray level $s_k$ is computed by the cumulative distribution function (CDF):
$$s_k = \left\lfloor (L-1) \times \sum_{j=0}^k \frac{n_j}{n} \right\rfloor$$
where $\sum_{j=0}^k \frac{n_j}{n}$ is the cumulative probability up to gray level $k$.
3. **Calculate cumulative distribution:**
- $n_0=15$, cumulative $=15/360=0.0417$
- $n_1=0$, cumulative $=0.0417$
- $n_2=0$, cumulative $=0.0417$
- $n_3=0$, cumulative $=0.0417$
- $n_4=0$, cumulative $=0.0417$
- $n_5=70$, cumulative $=0.0417 + 70/360=0.2361$
- $n_6=110$, cumulative $=0.2361 + 110/360=0.5417$
- $n_7=45$, cumulative $=0.5417 + 45/360=0.6667$
- $n_8=70$, cumulative $=0.6667 + 70/360=0.8611$
- $n_9=35$, cumulative $=0.8611 + 35/360=0.9583$
- $n_{10}=0$, cumulative $=0.9583$
- $n_{11}=0$, cumulative $=0.9583$
- $n_{12}=0$, cumulative $=0.9583$
- $n_{13}=0$, cumulative $=0.9583$
- $n_{14}=0$, cumulative $=0.9583$
- $n_{15}=15$, cumulative $=0.9583 + 15/360=1.0000$
4. **Calculate new gray levels $s_k$:**
$$s_k = \left\lfloor 15 \times \text{cumulative} \right\rfloor$$
- $s_0 = \lfloor 15 \times 0.0417 \rfloor = 0$
- $s_1 = 0$
- $s_2 = 0$
- $s_3 = 0$
- $s_4 = 0$
- $s_5 = \lfloor 15 \times 0.2361 \rfloor = 3$
- $s_6 = \lfloor 15 \times 0.5417 \rfloor = 8$
- $s_7 = \lfloor 15 \times 0.6667 \rfloor = 10$
- $s_8 = \lfloor 15 \times 0.8611 \rfloor = 12$
- $s_9 = \lfloor 15 \times 0.9583 \rfloor = 14$
- $s_{10} = 14$
- $s_{11} = 14$
- $s_{12} = 14$
- $s_{13} = 14$
- $s_{14} = 14$
- $s_{15} = 15$
5. **Result:** The histogram equalized gray levels map original levels to new levels:
$$\{0,0,0,0,0,3,8,10,12,14,14,14,14,14,14,15\}$$
---
6. **Problem e: Identify eight neighbors and 4-connected pattern in matrix $f$:**
7. The matrix $f$ is:
$$
\begin{bmatrix}
2 & 2 & 2 & 2 & 2 \\
2 & 1 & 1 & 1 & 2 \\
2 & 1 & 0 & 1 & 2 \\
2 & 1 & 1 & 1 & 2 \\
2 & 2 & 2 & 2 & 2
\end{bmatrix}
$$
8. The center pixel is at position (3,3) with value 0.
9. The eight neighbors are the surrounding pixels:
- Horizontally and vertically adjacent: (2,3)=1, (3,2)=1, (3,4)=1, (4,3)=1
- Diagonally adjacent: (2,2)=1, (2,4)=1, (4,2)=1, (4,4)=1
10. The 4-connected pattern consists of the four neighbors horizontally and vertically adjacent to the center pixel, all with value 1:
$$\{(2,3), (3,2), (3,4), (4,3)\}$$
This pattern forms a cross shape around the center pixel.
**Final answers:**
- Histogram equalized gray levels: $\{0,0,0,0,0,3,8,10,12,14,14,14,14,14,14,15\}$
- Eight neighbors of pixel 0 are the surrounding eight pixels with values 1 or 2.
- The 4-connected pattern is the four neighbors with value 1 adjacent horizontally and vertically to the center pixel.