Q5Digital Image Processing
Question
Q.3. (a) Justify the statement that median filter is used to minimise salt-and-pepper noise by the following image (use 3x3 median filter): [[24,22,33,25,32,24],[34,(255),124,(0),64,78],[47,101,10,77,19,69]]. [10]
(b) Write the expression of 2D butterworth high pass filter and discuss its working. [6]
Answer
Applying a 3x3 median filter replaces the salt pixel (255) with median 34 and the pepper pixel (0) with median 32, both computed from their respective sorted 3x3 neighborhoods, demonstrating that median filtering discards extreme outliers via rank ordering rather than being skewed by them as linear averaging would be; the Butterworth high-pass filter formula gives a smooth, order-controlled edge-enhancement response without the ringing of an ideal filter.
(a) Numerical: 3x3 Median Filter on Salt-and-Pepper Noise
We are given the image [[24,22,33,25,32,24],[34,255,124,0,64,78],[47,101,10,77,19,69]] with two marked/corrupted pixels: value 255 at row 2, column 2 (1-indexed; row index 1, column index 1 zero-indexed) representing 'salt' noise, and value 0 at row 2, column 4 (1-indexed; row index 1, column index 3 zero-indexed) representing 'pepper' noise. We apply a 3x3 median filter at each marked location.
Pixel at (row index 1, col index 1), value 255
The 3x3 neighborhood centered here spans rows 0-2 and columns 0-2:
Sorting these 9 values in ascending order: 10, 22, 24, 33, 34, 47, 101, 124, 255. The median is the 5th value (middle position) of these 9 sorted values, which is 34.
Therefore, the median filter replaces the corrupted salt pixel value 255 with the median value 34, a value fully representative of its local surroundings, completely eliminating the extreme bright outlier.
Pixel at (row index 1, col index 3), value 0
The 3x3 neighborhood centered here spans rows 0-2 and columns 2-4:
Sorting these 9 values in ascending order: 0, 10, 19, 25, 32, 33, 64, 77, 124. The median is the 5th value (middle position) of these 9 sorted values, which is 32.
Therefore, the median filter replaces the corrupted pepper pixel value 0 with the median value 32, again a value fully representative of its local surroundings, completely eliminating the extreme dark outlier.
- Salt pixel (255) neighborhood sorted: [10,22,24,33,34,47,101,124,255], median = 34
- Pepper pixel (0) neighborhood sorted: [0,10,19,25,32,33,64,77,124], median = 32
- Median filter output replaces 255 -> 34 and 0 -> 32
This directly justifies the statement that the median filter effectively minimizes salt-and-pepper noise: because the filter output is determined purely by the rank position (the middle value) of the sorted neighborhood values, and extreme outlier values such as 255 or 0 are always pushed to the very ends of the sorted sequence, they are inherently excluded from the middle (median) position and therefore have absolutely no influence on the filter's output value. In sharp contrast, a linear averaging (mean) filter would include these extreme outlier values directly in its sum, and dividing that sum by 9 would still leave the result significantly skewed toward the corrupting extreme value; for instance, averaging the first neighborhood (containing 255) would give a corrupted mean of (24+22+33+34+255+124+47+101+10)/9 = 650/9 = 72.2, still far higher than the representative surrounding values, whereas the median of 34 is a much more faithful, noise-free estimate of the true local intensity. This comparison clearly demonstrates why the median filter, by discarding rather than incorporating outliers through rank-ordering, is markedly superior to linear averaging for removing salt-and-pepper impulse noise.
(b) 2D Butterworth High-Pass Filter
It is also worth noting that if this same 3x3 median filter were applied to every remaining pixel of the six-column, three-row image (not only the two marked corrupted positions), the uncorrupted regions of the image, which vary only gradually and do not contain sharp isolated outliers, would be largely unaffected by the median operation, since the median of a set of gradually varying, mutually similar values is simply a representative typical value from that same set, very close to the original center pixel value. This selective behavior, strongly correcting only the pixels that are genuine outliers relative to their neighborhood while leaving genuinely smooth, noise-free regions essentially unchanged, is precisely what makes the median filter a targeted and effective tool for impulse noise removal without introducing the broad, unnecessary blurring across the entire image that a linear smoothing filter would inevitably cause.
The transfer function of the 2D Butterworth high-pass filter of order n is given by:
where D(u,v) is the Euclidean distance of the point (u,v) from the origin (zero frequency) in the frequency domain, D0 is the specified cutoff frequency, and n is the order of the filter, which controls the sharpness of the transition. This filter attenuates low frequencies (small D(u,v), where the ratio D0/D(u,v) is large, driving H(u,v) toward 0) and passes high frequencies (large D(u,v), where the ratio D0/D(u,v) is small, driving H(u,v) toward 1). Unlike the ideal high-pass filter, which has an abrupt discontinuous cutoff at D0 and consequently introduces visible ringing artifacts (Gibbs phenomenon) around edges in the filtered image, the Butterworth high-pass filter provides a smooth, gradual transition between the suppressed low-frequency band and the passed high-frequency band. The sharpness of this transition is directly controlled by the order n: higher values of n produce a steeper, more rapid transition (approaching ideal-filter behavior and correspondingly reintroducing more ringing), while lower values of n produce a more gradual transition with correspondingly less ringing. This tunable trade-off makes the Butterworth high-pass filter a practical choice for edge enhancement and sharpening tasks, since it can substantially boost high-frequency edge content (similar in effect to the ideal high-pass filter) while avoiding the severe ringing artifacts that a hard cutoff would introduce.
A commonly chosen order for the Butterworth high-pass filter in practice is n=1 or n=2, which are found empirically to offer a good visual balance between adequately sharp separation of low and high frequency content and sufficiently smooth transition to avoid perceptible ringing artifacts in the enhanced image, whereas very high orders (n=10 or above) begin to closely approximate the ideal high-pass filter's abrupt cutoff and correspondingly reintroduce visible ringing near strong edges. The filter is applied by computing the 2D discrete Fourier transform of the input image, multiplying element-wise by this transfer function evaluated over the same-sized frequency grid, and then computing the inverse discrete Fourier transform to obtain the sharpened, edge-enhanced spatial-domain output image, typically combined with the original image via high-frequency emphasis to retain overall background brightness rather than being used as a pure standalone high-pass result.
This result directly demonstrates the fundamental advantage of the median filter over a simple linear averaging (mean) filter for salt-and-pepper noise removal: had a 3x3 average filter instead been applied at these same two marked pixel locations, the extreme outlier values (255 and 0) would have been included in the arithmetic mean calculation, substantially skewing the resulting averaged output away from the true, representative local intensity level and effectively spreading (blurring) the noise's influence across the output rather than removing it - the median filter, by contrast, explicitly ranks all nine neighborhood values and selects only the middle (median) value, meaning a single extreme outlier value (however large or small) is simply discarded from consideration (since it always ends up at one extreme end of the sorted list, never at the middle position) rather than distorting the computed output value, which is precisely why the median filter is specifically well-suited to removing exactly this kind of extreme-value impulse (salt-and-pepper) noise while linear filtering methods are not.