EP03_07 🔍 Laplacian Operator (w4) for Edge Enhancement
In high-resolution tomography, the sharpness of edges between tissues is critical for diagnosis. The Laplacian operator is widely used in medical image preprocessing pipelines to automatically enhance anatomical contours before segmentation, avoiding manual intervention by the radiologist.
See Figure 3.32 for a simulation of this EP.
📋 Implementation Guidelines
Dimensions: Read the integers \(L\) (rows) and \(C\) (columns).
Data: Read the pixel matrix \(f\) .
Laplacian (w4): For each internal pixel \((i,j)\) with \(1 \le i < L-1\) , \(1 \le j < C-1\) , compute:
\[\nabla^2 f(i,j) = f(i-1,j) + f(i+1,j) + f(i,j-1) + f(i,j+1) - 4 \cdot f(i,j)\]
Enhancement: Compute the enhanced image:
\[g(i,j) = \text{clip}(f(i,j) - \nabla^2 f(i,j))\]
Border: Border pixels are copied directly: \(g(i,j) = f(i,j)\) .
Output: Display the enhanced matrix \(L \times C\) .
📌 Computational Constraints
Kernel w4: \(\begin{bmatrix} 0 & 1 & 0 \\ 1 & -4 & 1 \\ 0 & 1 & 0 \end{bmatrix}\) — only 4-neighbors.
Saturation: \(\text{clip}(x) = \max(0, \min(255, x))\) applied to the enhancement result.
No rounding: The Laplacian uses only integer additions/subtractions.
🧠 Theoretical Background
Uniform
\(\approx 0\)
No change
Rising edge
\(< 0\)
Pixel lightened
Falling edge
\(> 0\)
Pixel darkened
📌 Examples
3
3
0 0 0
0 100 0
0 0 0
0 0 0
0 255 0
0 0 0
Isolated peak: lap=−400, g=100−(−400)=500 → clip=255
3
3
50 50 50
50 50 50
50 50 50
50 50 50
50 50 50
50 50 50
Uniform region: Laplacian=0, no change
Figure 3.32: Simulator EP03_07: Laplacian Operator (w4) for Edge Enhancement
%% writefile EP03_07.cpp
// your solution
TestSuite("EP03_07.cpp" ).run()
✔️ EP03_07.cases already exists in casos/
📋 5 case(s) loaded from casos/EP03_07.cases
🔍 Testing C++: EP03_07.cpp
⚠️ EP03_07.cpp: Empty file (fewer than 3 lines). Tests skipped.