EP03_08 🧭 Sobel Gradient: Gx and Gy
In Mars exploration rovers (such as Perseverance), obstacle detection is performed in real time by stereoscopic cameras. The Sobel operator computes the directional gradient of the scene and is used in the edge detection algorithm to identify rocks, cracks, and terrain unevenness that could compromise navigation.
See Figure 3.33 for a simulation of this EP.
📋 Implementation Guidelines
Dimensions: Read the integers \(L\) (rows) and \(C\) (columns).
Data: Read the matrix \(f\) .
Gx and Gy: For each internal pixel \((i,j)\) with \(1 \le i < L-1\) , \(1 \le j < C-1\) :
\[G_x(i,j) = [f(i-1,j+1) + 2f(i,j+1) + f(i+1,j+1)] - [f(i-1,j-1) + 2f(i,j-1) + f(i+1,j-1)]\]
\[G_y(i,j) = [f(i+1,j-1) + 2f(i+1,j) + f(i+1,j+1)] - [f(i-1,j-1) + 2f(i-1,j) + f(i-1,j+1)]\]
Magnitude: \(|\nabla f(i,j)| = \text{clip}(\text{round}(\sqrt{G_x^2 + G_y^2}))\) .
Edge: Edge pixels receive magnitude 0.
Output: Display the \(L \times C\) magnitude.
📌 Computational Constraints
Rounding: Apply round before converting to integer.
Saturation: \(\text{clip}(x) = \max(0, \min(255, x))\) .
Square root: Use \(\sqrt{G_x^2 + G_y^2}\) (not the approximation \(|G_x| + |G_y|\) ).
🧠 Theoretical Foundation
\(G_x\)
Vertical edges
\(\pm 1\)
\(G_y\)
Horizontal edges
\(\pm 1\)
\(|\nabla f|\)
All edges
Combined
📌 Examples
3
3
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
Null image: zero gradient
3
3
0 0 255
0 0 255
0 0 255
0 0 0
0 255 0
0 0 0
Central vertical edge: high Gx
Figure 3.33: EP03_08 Simulator: Sobel Gradient (Gx and Gy)
%% writefile EP03_08.py
# Python code
TestSuite("EP03_08.py" ).run()
✔️ EP03_08.cases already exists in casos/
📋 5 case(s) loaded from casos/EP03_08.cases
🔍 Testing Python: EP03_08.py
⚠️ EP03_08.py: Empty file (fewer than 3 lines). Tests skipped.