Zero-crossing detector¶
| Fact | Value |
|---|---|
| Also called | Zero crossings |
| Status | Implemented and tested |
| Family | Edge detection and boundary analysis |
| Engine | Browser |
| Type | Nonlinear, spatial, sign change test |
| Output | Mask |
| Operator shown as | algorithm (exact) |
| Support radius | 1 |
| Code | web/src/core/filters/edges/zero-crossing.ts, zeroCrossingFilter |
| Operator code | web/src/core/filters/edges/zero-crossing.ts, zeroCrossings |
| Channels | Brightness only, RGB |
Overview¶
The zero-crossing detector marks the pixels where a signed response changes sign. Its input is a result such as a Laplacian, saved with the offset mapping so that 128 means zero. Applied to a second-derivative response, the crossings lie on the edges and form thin, closed lines.
How it works¶
- Subtract the zero level from each value.
- Find negative pixels with a positive neighbor.
- Mark them when the jump is above the threshold.
Mathematical foundation¶
The formula shows the default parameter values.
where
- \(v\): The value minus the zero level
- \(N_4(p)\): The four neighbors of p
- \(T\): The threshold
v is the value minus the zero level, N_4(p) the four neighbors of p and T the threshold. A pixel is marked when it is negative and a neighbor is positive with a jump above T. Only the negative side of each crossing is marked, so the lines are one pixel thick. Other detectors mark the side closer to zero, or both sides. This is the rule used here.
On a smooth edge the first derivative peaks and the second derivative passes through zero. On a pixel grid the exact zero falls between two pixels, so a detector must choose which pixel to mark. This filter marks the negative one, which keeps the lines one pixel thick. The threshold on the jump removes crossings caused by small noise.
Kernel or operator¶
There is no kernel. The Inspector shows the rule with the current level and threshold. The worked example below is in the Marr-Hildreth page, which uses the same rule.
Algorithm¶
- Pad the image by one pixel with the border mode.
- Subtract the zero level.
- Mark each negative pixel that has a positive neighbor with a jump above the threshold.
- Write 255 at marked pixels and 0 elsewhere.
Parameters¶
| Parameter | Default | Values | Meaning |
|---|---|---|---|
Zero level level |
128 | 0 to 255 | The value that counts as zero. 128 reads a result that was saved with the offset mapping. |
Threshold threshold |
0 | 0 to 255 | The smallest jump across the crossing that counts. |
Output mapping outputMapping |
Clip to 0 to 255 | Absolute value, Offset by 128, Stretch to full range, Clip to 0 to 255 | How signed results, such as gradients, become 8-bit pixel values. |
Border mode border |
Reflect 101 (default) | Reflect 101 (default), Reflect, Replicate, Constant (zero), Wrap | How pixels outside the image are filled when the window reaches past the edge. |
Channels channelScope |
Brightness only | RGB, Brightness only | Which part of the color image the filter changes. |
Implementation¶
zeroCrossings in web/src/core/filters/edges/zero-crossing.ts checks the four neighbors of each negative pixel. The filter extends the plane by one pixel with the border mode first. The filter runs in the browser engine, in Web Workers, through the shared filter framework in web/src/core/filters/run.ts, which handles the border mode, the channel scope, alpha and the output mapping. By default it works on luma and gives a gray mask.
Worked example¶
| x | 29 | 30 | 31 | 32 | 33 | 34 |
|---|---|---|---|---|---|---|
| Input | 40 | 40 | 40 | 215 | 215 | 215 |
| LoG + 128 | 141 | 148 | 138 | 118 | 108 | 115 |
| Edge mask | 0 | 0 | 0 | 255 | 0 | 0 |
The same rule as the Marr-Hildreth detector, here on its LoG with sigma 1.5. The LoG, shown with the offset mapping, is above 128 on the dark side and below it on the bright side. The first pixel below 128, next to one above, is marked with 255. It is the first bright pixel of the step.
Complexity¶
- Time: \(O(N)\)
- Memory: \(O(N)\)
N is the number of pixels per channel. Each pixel checks four neighbors.
Artifacts and limitations¶
Limitations
- Noise crosses zero everywhere, so a threshold or smoothing is needed.
- The input must be a signed response with a known zero level, not a plain photo.
Artifacts
- Small closed loops in flat noisy areas when the threshold is low.
Tests¶
The reference applies the same rule with NumPy. The test covers two levels and thresholds for all five border modes.
References¶
- Marr, D. and Hildreth, E. Theory of edge detection. Proceedings of the Royal Society of London, Series B 207(1167), 187 to 217, 1980. DOI 10.1098/rspb.1980.0020.
- Gonzalez, R. C. and Woods, R. E. Digital Image Processing, 4th edition. Pearson, 2018. Section 10.2, the Marr-Hildreth edge detector.