Morphological Erosion
Shrinks bright regions. Removes small objects. Fundamental morphological operation for binary/grayscale images.
Visualization
Interactive visualization for Morphological Erosion
Erosion:
- • Shrinks white regions
Interactive visualization with step-by-step execution
Implementation
1function erosion(image: number[][], kernel: number[][]): number[][] {
2 const result: number[][] = [];
3 const kh = Math.floor(kernel.length / 2);
4 const kw = Math.floor(kernel[0].length / 2);
5
6 for (let i = 0; i < image.length; i++) {
7 result[i] = [];
8 for (let j = 0; j < image[0].length; j++) {
9 let min = Infinity;
10
11 for (let ki = -kh; ki <= kh; ki++) {
12 for (let kj = -kw; kj <= kw; kj++) {
13 const ni = i + ki, nj = j + kj;
14 if (ni >= 0 && ni < image.length && nj >= 0 && nj < image[0].length) {
15 if (kernel[ki + kh][kj + kw] === 1) {
16 min = Math.min(min, image[ni][nj]);
17 }
18 }
19 }
20 }
21 result[i][j] = min;
22 }
23 }
24 return result;
25}Deep Dive
Theoretical Foundation
Erosion: take minimum over structuring element. Shrinks foreground. A ⊖ B = {z | B_z ⊆ A}. Dual of dilation. Used for noise removal, boundary extraction.
Complexity
Time
O(w×h×k²)
O(w×h×k²)
O(w×h×k²)
Space
O(w×h)
Applications
Industry Use
Noise removal in binary images
Object separation in microscopy
Text processing and OCR preprocessing
Industrial part inspection
Medical image segmentation
Fingerprint image processing
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.