Morphological Dilation
Expands bright regions. Fills holes. Dual operation to erosion. Used for region growing and gap filling.
Visualization
Interactive visualization for Morphological Dilation
Dilation:
- • Expands white regions
Interactive visualization with step-by-step execution
Implementation
1function dilation(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 max = -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 max = Math.max(max, image[ni][nj]);
17 }
18 }
19 }
20 }
21 result[i][j] = max;
22 }
23 }
24 return result;
25}Deep Dive
Theoretical Foundation
Dilation: take maximum over structuring element. Expands foreground. A ⊕ B = {z | B_z ∩ A ≠ ∅}. Combined with erosion for opening/closing operations.
Complexity
Time
O(w×h×k²)
O(w×h×k²)
O(w×h×k²)
Space
O(w×h)
Applications
Industry Use
Gap filling in binary images
Object reconstruction in microscopy
Text processing and character repair
Industrial defect analysis
Medical image enhancement
Document 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.