Class ThresholdOp
java.lang.Object
cloud.opencode.base.image.threshold.ThresholdOp
Fixed Threshold Operations
固定阈值操作工具类
Applies fixed-value thresholding to grayscale images with multiple modes including binary, inverse binary, truncate, to-zero and inverse to-zero.
对灰度图像应用固定值阈值处理,支持多种模式: 二值化、反向二值化、截断、置零和反向置零。
Features | 主要功能:
- Five threshold modes: BINARY, BINARY_INV, TRUNC, TOZERO, TOZERO_INV - 五种阈值模式
- LUT-based O(n) implementation - 基于查找表的 O(n) 实现
- Automatic grayscale conversion - 自动灰度转换
Usage Examples | 使用示例:
// Binary thresholding
Raster binary = ThresholdOp.apply(raster, 128);
// Inverse binary thresholding
Raster inv = ThresholdOp.apply(raster, 128, ThresholdOp.Mode.BINARY_INV);
// Truncate mode
Raster trunc = ThresholdOp.apply(raster, 200, ThresholdOp.Mode.TRUNC);
Performance | 性能特性:
- Time: O(n) where n = pixel count - 时间: O(n),n 为像素数量
- Space: O(n) for output image - 空间: O(n) 用于输出图像
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 Classes -
Method Summary
-
Method Details
-
apply
Apply fixed threshold to aRasterwith the specified mode. 使用指定模式对Raster应用固定阈值。The raster is converted to grayscale using BT.601 luminance, then a lookup table is built according to the mode and applied. The returned raster is always
PixelFormat.GRAY_8regardless of input format.使用 BT.601 亮度公式将 raster 转为灰度,然后按模式构建 LUT 并应用。 输出一律为
PixelFormat.GRAY_8。- Parameters:
raster- the source raster | 源 rasterthreshold- the threshold value [0, 255] | 阈值 [0, 255]mode- the threshold mode | 阈值模式- Returns:
- the GRAY_8 thresholded raster | GRAY_8 阈值处理后的 raster
- Throws:
ImageOperationException- if raster is null, threshold out of range, or mode is null- Since:
- opencode-base-image V1.0.4
-
apply
- Parameters:
raster- the source raster | 源 rasterthreshold- the threshold value [0, 255] | 阈值 [0, 255]- Returns:
- the GRAY_8 binary thresholded raster | GRAY_8 二值化后的 raster
- Throws:
ImageOperationException- if raster is null or threshold out of range- Since:
- opencode-base-image V1.0.4
-