Q3Digital Image Processing
Question
Q.2. (a) Apply histogram equalisation to the following 4x4 image I1 and show the resultant image I2. I1 = [[1,3,4,5],[5,6,6,6],[7,7,7,7],[5,5,5,5]]. Assume image as a 3-bit image. [8]
(b) An image is represented as: [[5,9,15],[7,(2),17],[31,12,14],[7,12,19]]. Compute the value of the marked pixel (value 2, at row 2 column 2) after smoothing by 3x3 average filter. [8]
Answer
Histogram equalization of the 4x4 3-bit image I1 produces the resultant image I2 = [[0,1,1,4],[4,5,5,5],[7,7,7,7],[4,4,4,4]] via computed histogram, PDF, and CDF; smoothing the marked pixel (value 2) with a 3x3 average filter over the neighborhood sum 112 gives an average of 12.444.
(a) Numerical: Histogram Equalization of a 4x4 3-bit Image
We are given the 4x4 image I1 = [[1,3,4,5],[5,6,6,6],[7,7,7,7],[5,5,5,5]], treated as a 3-bit image, meaning gray levels range from 0 to 7 (2^3 = 8 possible levels). The total number of pixels is 4 x 4 = 16.
Step 1: Compute the histogram (count of each gray level)
Scanning through all 16 pixel values: level 1 appears once, level 3 appears once, level 4 appears once, level 5 appears six times (positions: two in row 1, none in row 2 besides itself, and all four of row 4), level 6 appears three times, and level 7 appears four times. Levels 0 and 2 do not appear at all.
- Level 0: count = 0
- Level 1: count = 1
- Level 2: count = 0
- Level 3: count = 1
- Level 4: count = 1
- Level 5: count = 6
- Level 6: count = 3
- Level 7: count = 4
- Total = 0+1+0+1+1+6+3+4 = 16 (matches total pixel count)
Step 2: Compute the PDF (probability of each level = count / 16)
- PDF[0] = 0/16 = 0
- PDF[1] = 1/16 = 0.0625
- PDF[2] = 0/16 = 0
- PDF[3] = 1/16 = 0.0625
- PDF[4] = 1/16 = 0.0625
- PDF[5] = 6/16 = 0.375
- PDF[6] = 3/16 = 0.1875
- PDF[7] = 4/16 = 0.25
Step 3: Compute the CDF (running cumulative sum of PDF)
- CDF[0] = 0
- CDF[1] = 0 + 0.0625 = 0.0625
- CDF[2] = 0.0625 + 0 = 0.0625
- CDF[3] = 0.0625 + 0.0625 = 0.125
- CDF[4] = 0.125 + 0.0625 = 0.1875
- CDF[5] = 0.1875 + 0.375 = 0.5625
- CDF[6] = 0.5625 + 0.1875 = 0.75
- CDF[7] = 0.75 + 0.25 = 1.0
Step 4: Compute the new (equalized) gray levels
The new gray level for each original level is obtained by multiplying its CDF value by the maximum gray level (7, since this is a 3-bit image with levels 0-7) and rounding to the nearest integer: new_level = round(CDF x 7).
- Level 0: round(0 x 7) = 0
- Level 1: round(0.0625 x 7) = round(0.4375) = 0
- Level 2: round(0.0625 x 7) = 0 (unused level, carried CDF value)
- Level 3: round(0.125 x 7) = round(0.875) = 1
- Level 4: round(0.1875 x 7) = round(1.3125) = 1
- Level 5: round(0.5625 x 7) = round(3.9375) = 4
- Level 6: round(0.75 x 7) = round(5.25) = 5
- Level 7: round(1.0 x 7) = round(7.0) = 7
So the gray-level mapping table is: 0 to 0, 1 to 0, 3 to 1, 4 to 1, 5 to 4, 6 to 5, 7 to 7.
Step 5: Apply the mapping to obtain the resultant image I2
Applying this mapping to every pixel of the original image I1 = [[1,3,4,5],[5,6,6,6],[7,7,7,7],[5,5,5,5]]: pixel value 1 maps to 0, value 3 maps to 1, value 4 maps to 1, value 5 maps to 4, value 6 maps to 5, and value 7 maps to 7.
This resultant image I2 shows the effect of histogram equalization: the previously narrow range of gray levels (1 through 7, clustered mostly around 5, 6, 7) has been remapped to spread more evenly across the available range (0, 1, 4, 5, 7), improving overall contrast. Note also that this exact worked example directly demonstrates the general principle that discrete histogram equalization does not produce a perfectly flat resultant histogram: several distinct input levels (5 and none other individually, but note levels 1 maps with 0's absent count, and levels 3,4 both map to 1) collapse onto the same output level, here levels 3 and 4 both mapping to output level 1, while enumerable other output levels such as 2, 3, and 6 receive no pixels at all, leaving gaps in the resultant histogram.
(b) Numerical: 3x3 Average Filter Smoothing
We are given the image [[5,9,15],[7,2,17],[31,12,14],[7,12,19]] and asked to compute the value of the marked pixel (value 2, located at row 2, column 2 in 1-indexed terms, i.e., row index 1, column index 1 in zero-indexed terms) after smoothing with a 3x3 average filter.
Step 1: Extract the 3x3 neighborhood
The image has 4 rows and 3 columns. The pixel at row index 1 allows a full 3-row window spanning rows 0, 1, and 2 (since the image height of 4 rows accommodates this), and since the image has exactly 3 columns, the full column range (columns 0, 1, 2) is used entirely. Thus the 3x3 neighborhood centered at the marked pixel is the entire top three rows of the image:
Step 2: Sum all 9 values in the neighborhood
Step 3: Divide by 9 to get the average
Therefore, after smoothing with a 3x3 average (mean) filter, the marked pixel originally at value 2 is replaced by the average value 12.444 (approximately 12.44). This large change (from 2 up to 12.444) illustrates how a linear averaging filter is heavily influenced by all values in the neighborhood, including any relatively larger surrounding values such as 31, pulling the smoothed result substantially away from the original low value at the center.
- 3x3 neighborhood at marked pixel = [[5,9,15],[7,2,17],[31,12,14]]
- Sum of neighborhood values = 5+9+15+7+2+17+31+12+14 = 112
- Average = 112 / 9 = 12.444
This numerical example also usefully illustrates the general trade-off inherent in linear smoothing (averaging) filters: the 3x3 average filter successfully reduces the influence of any single unusually high or low pixel value by blending it together with its eight neighbors, which is beneficial for suppressing random (e.g., Gaussian-type) noise that is not extremely large in magnitude relative to its neighborhood. However, because every neighborhood value, including any large outliers such as the 31 present in this particular neighborhood, contributes proportionally to the computed average, a linear averaging filter is not well suited to removing strong impulse (salt-and-pepper) noise, since a single extreme outlier value can still noticeably pull the computed average away from the true, representative local intensity, unlike an order-statistic filter such as the median filter, which would simply discard such an extreme value entirely by virtue of rank ordering rather than including it in a weighted sum.
This pair of worked examples, histogram equalization applied to enhance the overall contrast and tonal distribution of an image, and spatial averaging applied to smooth out noise or fine detail at a single pixel location, together illustrate the two broad categories into which most classical spatial-domain image enhancement techniques fall: point processing (where a pixel's new value depends only on its own original value and the overall image histogram, as in histogram equalization) and neighborhood/mask-based processing (where a pixel's new value depends on the values of its surrounding neighborhood pixels, as in the averaging filter), a foundational distinction underlying the great majority of spatial-domain digital image processing algorithms.