EP03_10 ✨ Unsharp Masking (USM)
In digitization systems for historical documents and works of art, image sharpness is essential for reading handwritten texts and ornamental details. Unsharp Masking (USM) is the standard sharpening enhancement algorithm used in professional scanners and software such as Adobe Photoshop, controlled by the parameter \(k\) that determines the enhancement intensity.
See Figure 3.35 for a simulation of this EP.
📋 Implementation Guidelines
Dimensions: Read the integers \(L\) (rows) and \(C\) (columns).
Parameter: Read the real value \(k\) (enhancement intensity, \(k \ge 0\) ).
Data: Read the pixel matrix \(f\) .
Smoothing: Compute \(\bar{f}\) with a \(3\times3\) averaging filter (internal pixels only; borders preserved):
\[\bar{f}(i,j) = \frac{1}{9} \sum_{s=-1}^{1} \sum_{t=-1}^{1} f(i+s, j+t)\]
High-frequency mask: \(m(i,j) = f(i,j) - \bar{f}(i,j)\) .
USM Enhancement: For each internal pixel:
\[g(i,j) = \text{clip}\left(\text{round}\left(f(i,j) + k \cdot m(i,j)\right)\right)\]
Border: \(g(i,j) = f(i,j)\) (direct copy).
Output: Display the enhanced matrix \(L \times C\) .
📌 Computational Constraints
Rounding: Apply round before clipping.
Saturation: \(\text{clip}(x) = \max(0, \min(255, x))\) .
Float operations: Compute \(\bar{f}\) and \(m\) in floating point before rounding the final result.
\(k = 0\) : No enhancement — the output is identical to the input (except for borders).
🧠 Theoretical Foundation
1
\(\bar{f} = f * \frac{1}{9}\mathbf{1}_{3\times3}\)
Smoothing (low frequencies)
2
\(m = f - \bar{f}\)
Mask (high frequencies)
3
\(g = \text{clip}(\text{round}(f + k \cdot m))\)
Weighted enhancement
📌 Examples
3
3
0.0
100 100 100
100 100 100
100 100 100
100 100 100
100 100 100
100 100 100
k=0: no enhancement
3
3
1.0
50 50 50
50 200 50
50 50 50
50 50 50
50 255 50
50 50 50
k=1: center pixel enhanced and saturated
Figure 3.35: EP03_10 Simulator: Unsharp Masking (USM)
%% writefile EP03_10.cpp
// your solution
TestSuite("EP03_10.cpp" ).run()
✔️ EP03_10.cases already exists in casos/
📋 5 case(s) loaded from casos/EP03_10.cases
🔍 Testing C++: EP03_10.cpp
⚠️ EP03_10.cpp: Empty file (fewer than 3 lines). Tests skipped.