Q4Digital Image Processing
Question
Q.2. (a) Discuss image sharpening by using second order derivative with an example. [8]
(b) Explain why the discrete histogram equalization technique does not, in general, yield a flat histogram. [8]
Answer
Second-order derivative (Laplacian) sharpening highlights fine detail and edges by adding back the Laplacian response to the original image, while discrete histogram equalization cannot produce a perfectly flat histogram because the transformation is a discrete step-function approximation of the ideal continuous, uniform-output mapping.
(a) Image Sharpening Using Second-Order Derivative (Laplacian)
Image sharpening enhances fine detail and edges that were blurred or de-emphasized, and this is commonly achieved using the Laplacian operator, a second-order derivative operator that is isotropic (rotation-invariant) for edges in any direction. The continuous 2D Laplacian is defined as the sum of second partial derivatives with respect to x and y.
In the discrete domain, this is implemented using a small convolution mask. A common 4-connected Laplacian mask is [[0,1,0],[1,-4,1],[0,1,0]], and an 8-connected variant that also includes diagonal neighbors is [[1,1,1],[1,-8,1],[1,1,1]]. Both masks have the property that their coefficients sum to zero, which means the Laplacian response is exactly zero in any region of constant or linearly varying intensity, and produces a large-magnitude response (positive or negative) only where there is a rapid local change in intensity, i.e., at edges or fine detail.
Because the Laplacian is a second derivative, it produces a double response at edges: it swings negative just before the edge, crosses zero at the edge center, and swings positive just after (or vice versa, depending on the direction of the intensity change and the sign convention of the mask used). Sharpening is achieved by subtracting this Laplacian response from the original image (when using a mask with a negative center coefficient), which has the effect of amplifying the intensity difference right at the edge location: the darker side of the edge is made darker and the brighter side is made brighter, increasing local contrast and making the edge appear crisper. The general sharpening formula is g(x,y) = f(x,y) - c * Laplacian(f(x,y)) if the center coefficient of the mask is negative (c = 1 typically), or g(x,y) = f(x,y) + Laplacian(f(x,y)) if the center coefficient is positive.
Worked Conceptual Example
Consider a 1D intensity profile across an edge where pixel values transition from a dark region of value 50 to a bright region of value 200. Applying the Laplacian mask [0,1,0 / 1,-4,1 / 0,1,0] near this transition produces a strongly negative value just on the dark side of the edge (since the center pixel value there is lower than several of its brighter neighbors, giving a large negative center-weighted sum) and a strongly positive value just on the bright side (since the center pixel there is brighter than several of its darker neighbors). When this Laplacian response is subtracted from the original image at each point, the dark-side pixel near the edge is pushed even darker (because subtracting a negative value increases magnitude of darkening relative to original, depending on convention) and the bright-side pixel is pushed even brighter, creating an overshoot on both sides of the edge. This overshoot is precisely what the human visual system perceives as increased sharpness: the edge transition becomes visually steeper and more pronounced than in the original blurred image, while flat regions away from any edge remain completely unchanged since the Laplacian response there is zero.
(b) Why Discrete Histogram Equalization Does Not Yield a Perfectly Flat Histogram
Histogram equalization is a technique that computes a transformation function based on the cumulative distribution function (CDF) of the input image's gray-level histogram and remaps each pixel's intensity through this function, with the theoretical goal of producing an output image whose histogram is uniformly (flatly) distributed across all available gray levels. In the continuous-variable theoretical derivation, if the intensity r is treated as a continuous random variable with a known continuous probability density function p_r(r), one can prove mathematically that the transformation s = T(r) = integral from 0 to r of p_r(w) dw (i.e., s equal to the CDF of r) produces an output variable s that is exactly, perfectly uniformly distributed over its range. This is a clean mathematical result that holds only under the idealized assumption that both the input intensities and the transformation function operate on a continuous, infinitely divisible range of values.
However, real digital images do not have continuous intensity values; they have a finite, discrete set of gray levels (for example, integers 0 through 255 for an 8-bit image, or 0 through 7 for a 3-bit image). In the discrete case, the histogram equalization transformation is computed using a discrete approximation of the CDF: the discrete cumulative distribution is a step function that only changes value at the finite set of gray levels actually present in the input image's histogram, rather than varying smoothly and continuously as in the theoretical derivation. When this discrete, step-shaped transformation function is applied, multiple distinct input gray levels commonly get mapped to the very same output gray level (since the discrete mapping function rounds or truncates its computed CDF values to the nearest available integer output level), while other output gray levels may receive no input pixels mapped to them at all, leaving gaps in the output histogram.
This mapping behavior means the output histogram, rather than being perfectly flat, ends up as an uneven approximation: some output gray levels accumulate disproportionately large pixel counts (wherever several input levels were merged into one output level), while other output levels remain completely empty or nearly so (wherever no rounded mapping landed on them), producing a histogram with visible peaks and valleys rather than a uniform, constant height across all levels. This is fundamentally a rounding and discretization argument: because the transformation function is inherently a coarse, quantized (step-function) approximation of the ideal continuous CDF mapping, and because it operates on and produces only a finite set of integer output values, it cannot achieve the exact redistribution of probability mass across levels that the continuous mathematical proof guarantees. In practice, discrete histogram equalization still substantially improves overall contrast and spreads the histogram out much more evenly than the original, which is why it remains a useful and widely applied enhancement technique, but the resulting histogram is only an approximately equalized version, never a mathematically perfect flat/uniform distribution as the continuous theory would predict.
- Continuous case: r is a continuous random variable, s = CDF(r) is proven to be exactly uniformly distributed.
- Discrete case: gray levels are finite integers, the CDF is a step function evaluated only at those integers.
- Multiple input levels frequently round/map to the same single output level, causing histogram peaks.
- Some output levels receive no mapped input pixels at all, causing histogram gaps.
- Net effect: output histogram is only an approximately flattened, non-uniform distribution, not a perfectly flat one.