Sharpening makes edges and fine detail more pronounced. It does not remove noise, and it usually amplifies it. The standard method is unsharp masking, named after a darkroom technique that subtracted a blurred (“unsharp”) copy of the photograph.
The Idea: Add Back the Details
Blurring removes fine detail, so the difference between an image and its blurred copy is the detail. Add some of that detail back:
- is a Gaussian-blurred copy (Gaussian Filtering and Convolution).
- controls the strength: leaves the image unchanged, larger values exaggerate edges.
- controls the size of the detail that is boosted: a small sharpens fine texture, a large boosts broad edges and local contrast.
Rearranging gives two equivalent views:
so it is a “double-weight identity minus a blur”, and because convolution is linear it collapses into one kernel, , where is the identity (impulse) kernel (Linear Shift-Invariant Filters).
Example with a box blur and : the center weight is and the eight others are :
The weights sum to 1, so flat regions keep their brightness. Only places where a pixel differs from its neighbourhood change.
Why It Works
In a flat region the blur equals the image, so the detail is zero and nothing changes. Across an edge the detail is positive on the bright side and negative on the dark side, which makes the bright side brighter and the dark side darker. The edge looks steeper, so it appears sharper.
The detail image is a band-pass response. It is the negative of a difference of Gaussians (one level blurred by , the other not blurred at all), and a difference of Gaussians approximates the Laplacian (Scale Space and Difference of Gaussians), so the detail behaves like a negative Laplacian: it responds only to local change.
Pitfalls
| Issue | Why |
|---|---|
| Noise is amplified | Noise lives in the fine detail that is being boosted. Blur lightly first, or keep small (Image Noise). |
| Halos | Large overshoots on both sides of a strong edge, creating bright and dark bands. |
| Clipping and overflow | The result can leave . Compute in float and clip before converting back (Data Types in Image Processing). |
| Confusion with denoising | Sharpening makes noise worse. Removing noise needs smoothing or a Median Filter. |
import numpy as np
from scipy.ndimage import gaussian_filter
def sharpen(img, sigma=1.5, alpha=1.0):
f = img.astype(np.float32)
detail = f - gaussian_filter(f, sigma)
return np.clip(f + alpha * detail, 0, 255).astype(np.uint8)Sources: Unsharp masking (Wikipedia). The 3 x 3 kernel is derived from the formula above.
Related: Computer Vision MOC, Gaussian Filtering and Convolution, Linear Shift-Invariant Filters, Cross-Correlation and Convolution, Scale Space and Difference of Gaussians