Sobel Edge Filter
Gradient-based edge detection. Calculates image intensity derivatives. Separable 3×3 kernels for X and Y directions.
Visualization
Interactive visualization for Sobel Edge Filter
Sobel X:
Sobel Filter:
- • Edge detection
Interactive visualization with step-by-step execution
Implementation
1function sobelFilter(image: number[][]): { magnitude: number[][], direction: number[][] } {
2 const Gx = [[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]];
3 const Gy = [[1, 2, 1], [0, 0, 0], [-1, -2, -1]];
4
5 const gradX = convolve2D(image, Gx);
6 const gradY = convolve2D(image, Gy);
7
8 const magnitude: number[][] = [];
9 const direction: number[][] = [];
10
11 for (let i = 0; i < gradX.length; i++) {
12 magnitude[i] = [];
13 direction[i] = [];
14 for (let j = 0; j < gradX[0].length; j++) {
15 magnitude[i][j] = Math.sqrt(gradX[i][j]**2 + gradY[i][j]**2);
16 direction[i][j] = Math.atan2(gradY[i][j], gradX[i][j]);
17 }
18 }
19
20 return { magnitude, direction };
21}Deep Dive
Theoretical Foundation
Uses two 3×3 kernels: Gx=[[-1,0,1],[-2,0,2],[-1,0,1]] and Gy=[[1,2,1],[0,0,0],[-1,-2,-1]]. Magnitude: √(Gx²+Gy²). Direction: arctan(Gy/Gx).
Complexity
Time
O(w×h)
O(w×h)
O(w×h)
Space
O(w×h)
Applications
Industry Use
Real-time edge detection in embedded systems
Preprocessing for Canny edge detection
Gradient computation in optical flow
Feature extraction in machine learning
Industrial inspection systems
Robotics vision systems
Use Cases
Related Algorithms
A* Search Algorithm
Informed search algorithm combining best-first search with Dijkstra's algorithm using heuristics. Widely used in pathfinding and graph traversal, A* is optimal and complete when using admissible heuristic. Used in games, GPS navigation, and robotics. Invented by Peter Hart, Nils Nilsson, and Bertram Raphael in 1968.
Convex Hull (Graham Scan)
Find smallest convex polygon containing all points. Graham Scan invented by Ronald Graham in 1972, runs in O(n log n). Essential in computational geometry, computer graphics, and pattern recognition.
Line Segment Intersection
Determine if two line segments intersect. Fundamental geometric primitive used in graphics, CAD, GIS. Uses orientation and collinearity tests.
Caesar Cipher
The Caesar Cipher is one of the oldest and simplest encryption techniques, named after Julius Caesar who used it to protect military messages around 100 BC. It works by shifting each letter in the plaintext by a fixed number of positions down the alphabet. For example, with a shift of 3, A becomes D, B becomes E, and so on. Despite being used for over 2000 years, it's extremely weak by modern standards with only 25 possible keys, making it trivially breakable by brute force or frequency analysis.