تذكر الوقوف بي يدي الله والحساب وحقوق العباد\nthe histogram of an image is given next. perform histogram…

تذكر الوقوف بي يدي الله والحساب وحقوق العباد\nthe histogram of an image is given next. perform histogram equalization and give the new histogram.\n\noriginal histogram\ngray level i | 0 | 1 | 2 | 3 | 4 | 5\ncount n_i | 43 | 0 | 48 | 29 | 15 | 17\n\nnew histogram\ngray level i | 0 | 1 | 2 | 3 | 4 | 5\ncount n_i | 0 | 43 | 0 | 48 | 44 | 17
Answer
Explanation:
Step1: Calculate Total Pixels
First, find the total number of pixels ( N ) by summing all ( n_i ).
( N = 43 + 0 + 48 + 29 + 15 + 17 = 152 )
Step2: Compute Cumulative Distribution Function (CDF)
For each gray level ( i ), compute ( CDF(i) = \sum_{k=0}^{i} n_k ).
- ( CDF(0) = 43 )
- ( CDF(1) = 43 + 0 = 43 )
- ( CDF(2) = 43 + 0 + 48 = 91 )
- ( CDF(3) = 43 + 0 + 48 + 29 = 120 )
- ( CDF(4) = 43 + 0 + 48 + 29 + 15 = 135 )
- ( CDF(5) = 43 + 0 + 48 + 29 + 15 + 17 = 152 )
Step3: Histogram Equalization Transformation
The transformation for histogram equalization is ( s_i = \lfloor \frac{(L - 1)}{N} \cdot CDF(i) \rfloor ), where ( L = 6 ) (number of gray levels, 0–5).
- For ( i = 0 ): ( s_0 = \lfloor \frac{5}{152} \cdot 43 \rfloor \approx \lfloor 1.414 \rfloor = 1 )
- For ( i = 1 ): ( s_1 = \lfloor \frac{5}{152} \cdot 43 \rfloor = 1 ) (same as ( i=0 ), since ( CDF(1)=CDF(0) ))
- For ( i = 2 ): ( s_2 = \lfloor \frac{5}{152} \cdot 91 \rfloor \approx \lfloor 2.987 \rfloor = 2 )
- For ( i = 3 ): ( s_3 = \lfloor \frac{5}{152} \cdot 120 \rfloor \approx \lfloor 3.947 \rfloor = 3 )
- For ( i = 4 ): ( s_4 = \lfloor \frac{5}{152} \cdot 135 \rfloor \approx \lfloor 4.447 \rfloor = 4 )
- For ( i = 5 ): ( s_5 = \lfloor \frac{5}{152} \cdot 152 \rfloor = 5 )
Step4: Count New Histogram
Count how many original gray levels map to each new gray level:
- New gray level 0: No mappings (since all ( s_i \geq 1 )) → ( n_0 = 0 )
- New gray level 1: ( i=0,1 ) → ( n_1 = 43 + 0 = 43 )
- New gray level 2: ( i=2 ) → ( n_2 = 48 ) (Wait, correction: Wait, ( i=2 ) maps to 2, so ( n_2 = 48 )? Wait, no—wait, original ( n_2 = 48 ), and ( s_2 = 2 ), so ( n_2 ) in new is 48? But the given new histogram has 0 for gray level 2. Wait, maybe the initial new histogram in the image is incorrect. Let's recalculate properly.
Wait, re-express: The transformation is ( s_i = \text{round} ) or ( \lfloor ) of ( \frac{(L-1)}{N} CDF(i) ). Let's recheck ( L ): gray levels 0–5, so ( L = 6 ), ( L-1 = 5 ).
CDF(0) = 43, CDF(1)=43, CDF(2)=91, CDF(3)=120, CDF(4)=135, CDF(5)=152.
For ( i=0 ): ( (5/152)*43 ≈ 1.414 ) → floor to 1.
For ( i=1 ): same as i=0, so 1.
For ( i=2 ): (5/152)*91 ≈ 2.987 → floor to 2.
For ( i=3 ): (5/152)*120 ≈ 3.947 → floor to 3.
For ( i=4 ): (5/152)*135 ≈ 4.447 → floor to 4.
For ( i=5 ): (5/152)*152 = 5 → floor to 5.
Now, count the number of pixels mapping to each new gray level:
- New level 0: 0 (no ( s_i = 0 ))
- New level 1: ( i=0 ) (n=43) and ( i=1 ) (n=0) → total 43 + 0 = 43
- New level 2: ( i=2 ) (n=48) → 48
- New level 3: ( i=3 ) (n=29) → 29? Wait, no! Wait, original ( n_i ) is the count for gray level ( i ). So when ( i=3 ), ( n_i = 29 ), and ( s_3 = 3 ), so new ( n_3 = 29 ). But the given new histogram has 48 for gray level 3. This suggests a mistake in the initial new histogram.
Wait, the problem’s given new histogram has:
Gray Level 0: 0
Gray Level 1: 43
Gray Level 2: 0
Gray Level 3: 48
Gray Level 4: 44
Gray Level 5: 17
But according to correct calculation, let's sum the new counts: 0 + 43 + 0 + 48 + 44 + 17 = 152, which matches ( N ). So let's see how the mappings lead to this:
Alternative approach: Maybe the transformation is ( s_i = \frac{(L-1)}{N} CDF(i) ) rounded or adjusted. Let's check the sum of new counts: 0 + 43 + 0 + 48 + 44 + 17 = 152, which is correct.
Let's see which original ( n_i ) map to new gray levels:
- New gray level 1: original gray levels with ( s_i = 1 ). ( s_0 = 1 ), ( s_1 = 1 ) → ( n_0 + n_1 = 43 + 0 = 43 ) (matches new ( n_1 = 43 ))
- New gray level 3: original gray level 2 (n=48) → ( s_2 = 3 )? Wait, (5/152)*91 ≈ 2.987, floor to 2, but if we round, it's 3. Ah, maybe rounding instead of flooring. Let's try rounding:
( s_i = \text{round}( \frac{5}{152} CDF(i) ) )
- ( i=0 ): (5*43)/152 ≈ 1.414 → round to 1
- ( i=1 ): same as i=0 → 1
- ( i=2 ): (5*91)/152 ≈ 2.987 → round to 3
- ( i=3 ): (5*120)/152 ≈ 3.947 → round to 4? No, 3.947 rounds to 4? Wait, 3.947 is closer to 4.
- ( i=4 ): (5*135)/152 ≈ 4.447 → round to 4
- ( i=5 ): (5*152)/152 = 5 → 5
Now:
- New level 1: i=0,1 → 43 + 0 = 43
- New level 3: i=2 → 48 (so ( s_2 = 3 ))
- New level 4: i=3,4 → 29 + 15 = 44 (matches new ( n_4 = 44 ))
- New level 5: i=5 → 17 (matches new ( n_5 = 17 ))
- New level 0: 0
- New level 2: 0 (no mappings)
Yes! That works. So:
- ( s_0 = 1 ), ( s_1 = 1 ) → new level 1: 43 + 0 = 43
- ( s_2 = 3 ) → new level 3: 48
- ( s_3 = 4 ), ( s_4 = 4 ) → new level 4: 29 + 15 = 44
- ( s_5 = 5 ) → new level 5: 17
- New level 0: 0
- New level 2: 0
Thus, the new histogram is:
| Gray Level i | 0 | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|---|
| Count ( n_i ) | 0 | 43 | 0 | 48 | 44 | 17 |
Answer:
The new histogram after equalization is:
| Gray Level ( i ) | 0 | 1 | 2 | 3 | 4 | 5 |
|---|---|---|---|---|---|---|
| Count ( n_i ) | 0 | 43 | 0 | 48 | 44 | 17 |