Class AdaptiveThresholdOp
java.lang.Object
cloud.opencode.base.image.threshold.AdaptiveThresholdOp
Adaptive Thresholding Operations
自适应阈值操作工具类
Applies locally adaptive thresholding where the threshold for each pixel is computed from its local neighborhood, making it robust to uneven illumination.
应用局部自适应阈值处理,每个像素的阈值由其局部邻域计算得到, 对不均匀光照具有鲁棒性。
Features | 主要功能:
- MEAN method: local mean via integral image (O(1) per pixel) - MEAN 方法:通过积分图计算局部均值(每像素 O(1))
- GAUSSIAN method: Gaussian-weighted local mean via separable convolution - GAUSSIAN 方法:通过可分离卷积计算高斯加权局部均值
- Configurable block size and constant offset - 可配置的块大小和常数偏移
Usage Examples | 使用示例:
// Adaptive mean thresholding
BufferedImage binary = AdaptiveThresholdOp.apply(image, 15, 10.0);
// Adaptive Gaussian thresholding
BufferedImage gaussian = AdaptiveThresholdOp.apply(image, 15, 10.0, AdaptiveThresholdOp.Method.GAUSSIAN);
Performance | 性能特性:
- MEAN method: O(n) using integral image - MEAN 方法:使用积分图 O(n)
- GAUSSIAN method: O(n * k) using separable convolution - GAUSSIAN 方法:使用可分离卷积 O(n * k)
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是(无状态)
- Since:
- JDK 25, opencode-base-image V2.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumAdaptive threshold method enumeration. -
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedImageapply(BufferedImage image, int blockSize, double c) Apply adaptive threshold with MEAN method (convenience method).static BufferedImageapply(BufferedImage image, int blockSize, double c, AdaptiveThresholdOp.Method method) Apply adaptive threshold with the specified method.
-
Method Details
-
apply
public static BufferedImage apply(BufferedImage image, int blockSize, double c, AdaptiveThresholdOp.Method method) Apply adaptive threshold with the specified method. 使用指定方法应用自适应阈值。For each pixel, a local threshold is computed from a blockSize x blockSize neighborhood. The pixel is set to 255 if its value exceeds (local_mean - c), otherwise it is set to 0.
对每个像素,从 blockSize x blockSize 邻域计算局部阈值。 若像素值大于 (局部均值 - c) 则置 255,否则置 0。
- Parameters:
image- the source image | 源图像blockSize- the neighborhood block size (must be odd and >= 3) | 邻域块大小(必须为奇数且 >= 3)c- the constant subtracted from the local mean | 从局部均值中减去的常数method- the adaptive method | 自适应方法- Returns:
- the binary thresholded image | 二值化后的图像
- Throws:
ImageOperationException- if parameters are invalid | 当参数无效时抛出
-
apply
Apply adaptive threshold with MEAN method (convenience method). 使用 MEAN 方法应用自适应阈值(便捷方法)。Equivalent to
apply(image, blockSize, c, Method.MEAN).等价于
apply(image, blockSize, c, Method.MEAN)。- Parameters:
image- the source image | 源图像blockSize- the neighborhood block size (must be odd and >= 3) | 邻域块大小(必须为奇数且 >= 3)c- the constant subtracted from the local mean | 从局部均值中减去的常数- Returns:
- the binary thresholded image | 二值化后的图像
- Throws:
ImageOperationException- if parameters are invalid | 当参数无效时抛出
-