Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

Recipe

Sharpen an image with unsharp masking

Use when: you have a grayscale image and want to emphasize edges and fine detail without a full frequency-domain filter

Goal: a sharpened image that amplifies detail while leaving flat regions nearly unchanged

Taught in Unsharp masking

  1. 1

    Convolve the original image I with a Gaussian kernel. This produces a blurred copy \bar I. Choose \sigma deliberately: a small \sigma isolates only very fine detail, while a larger \sigma also captures broader structure as "detail" to be sharpened.

    Example

    Take a 1\times 4 strip I=[60,200,60,200]. A light Gaussian blur, with weights roughly [0.25,0.5,0.25] per interior point and edges padded, produces approximately \bar I=[100,130,130,100]. The sharp alternation is smoothed toward the middle.

    Why: the mask in Step 2 is defined as what the blur removes, so the blurred copy has to exist first. Its sigma directly controls what counts as "detail" versus "already-smooth structure."

  2. 2

    Compute M = I - \bar I pixel by pixel. Where I was already close to its own local average, M is close to zero. Where I had a sharp local feature, M is a large positive or negative number.

    Example

    Continuing with I=[60,200,60,200] and \bar I=[100,130,130,100]: M = [60-100,\ 200-130,\ 60-130,\ 200-100] = [-40,\ 70,\ -70,\ 100]

    Why: this is exactly the detail signal Section 6's Laplacian was building toward. It is large where the image changes sharply and small where it doesn't.

  3. 3

    Multiply every value of M by the chosen strength a>0. A larger a gives more aggressive sharpening. Values of a around 0.5–1.5 are typical.

    Example

    Using a=1 on M=[-40,70,-70,100] leaves it unchanged: aM=[-40,70,-70,100]. Using a=0.5 instead gives aM=[-20,35,-35,50], a gentler correction.

    Why: the mask alone is a correction signal, not a finished image. Its scale has to be chosen deliberately, the same way Section 1's sigma controls smoothing strength.

  4. 4

    Compute \hat I = I + aM pointwise, then clip every value to the legal [0,255] range.

    Example

    With a=1: \hat I = [60,200,60,200] + [-40,70,-70,100] = [20,270,-10,300], clipped to [20,255,0,255]. The already-bright peaks push all the way to white and the already-dark troughs push toward black, a visibly sharper alternation than the original [60,200,60,200].

    Why: clipping is the same safety rail every point operation in this course relies on (Chapter 2). The raw sharpened value can genuinely leave the legal range.

Common mistakes

  • Forgetting to clip the final result. This leaves values outside [0,255] that display incorrectly or wrap around.
  • Choosing \sigma far too large. The "mask" then captures broad structure instead of fine detail, producing halo-like artifacts around large shapes instead of crisp edges.
  • Confusing the mask M=I-\bar I with the Laplacian directly. They are closely related, since both are high-pass signals, but computed differently, and mixing up the formulas gives a mask with the wrong scale.
  • Applying too large an a. This amplifies noise along with genuine detail, since unsharp masking cannot tell the two apart.