Class CannyOp
java.lang.Object
cloud.opencode.base.image.edge.CannyOp
Canny Edge Detection Operator
Canny 边缘检测算子
Implements the full Canny edge detection pipeline: Gaussian blur, Sobel gradient computation, non-maximum suppression, double thresholding, and hysteresis edge tracking. Produces a binary edge map (0 or 255).
实现完整的 Canny 边缘检测流程:高斯模糊、Sobel 梯度计算、 非极大值抑制、双阈值处理和滞后边缘跟踪。输出二值边缘图(0 或 255)。
Features | 主要功能:
- Full Canny pipeline with configurable thresholds - 完整 Canny 流程支持可配置阈值
- Gaussian smoothing via separable convolution (sigma=1.4) - 通过可分离卷积实现高斯平滑 (sigma=1.4)
- Non-maximum suppression for thin edges - 非极大值抑制实现细化边缘
- Hysteresis tracking for edge continuity - 滞后跟踪确保边缘连续性
- Binary output: only 0 or 255 pixel values - 二值输出:仅 0 或 255 像素值
Usage Examples | 使用示例:
// Canny with custom thresholds
BufferedImage edges = CannyOp.apply(image, 50, 150);
// Canny with default thresholds (50, 150) and sigma=1.4
BufferedImage edges = CannyOp.apply(image);
Performance | 性能特性:
- Time complexity: O(w * h) for each pipeline stage - 时间复杂度: 每个流水线阶段 O(w * h)
- Space complexity: O(w * h) for intermediate buffers - 空间复杂度: 中间缓冲区 O(w * h)
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是(无状态)
- Null-safe: No - 空值安全: 否
- Since:
- JDK 25, opencode-base-image V2.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedImageapply(BufferedImage image) Apply Canny edge detection with default thresholds (50, 150) and sigma=1.4.static BufferedImageapply(BufferedImage image, double lowThreshold, double highThreshold) Apply Canny edge detection with specified thresholds and sigma=1.4.
-
Method Details
-
apply
Apply Canny edge detection with default thresholds (50, 150) and sigma=1.4. 使用默认阈值 (50, 150) 和 sigma=1.4 应用 Canny 边缘检测。- Parameters:
image- the source image | 源图像- Returns:
- the binary edge image (0 or 255) | 二值边缘图像(0 或 255)
- Throws:
NullPointerException- if image is null | 当图像为 null 时抛出
-
apply
Apply Canny edge detection with specified thresholds and sigma=1.4. 使用指定阈值和 sigma=1.4 应用 Canny 边缘检测。- Parameters:
image- the source image | 源图像lowThreshold- the low threshold for hysteresis (must be >= 0 and invalid input: '<'= highThreshold) | 滞后低阈值highThreshold- the high threshold for hysteresis (must be >= lowThreshold) | 滞后高阈值- Returns:
- the binary edge image (0 or 255) | 二值边缘图像(0 或 255)
- Throws:
NullPointerException- if image is null | 当图像为 null 时抛出ImageOperationException- if lowThreshold > highThreshold or thresholds are negative | 当低阈值大于高阈值或阈值为负时抛出
-