Class ThresholdOp

java.lang.Object
cloud.opencode.base.image.threshold.ThresholdOp

public final class ThresholdOp extends Object
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
BufferedImage binary = ThresholdOp.apply(image, 128);

// Inverse binary thresholding
BufferedImage inv = ThresholdOp.apply(image, 128, ThresholdOp.Mode.BINARY_INV);

// Truncate mode
BufferedImage trunc = ThresholdOp.apply(image, 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:
  • Method Details

    • apply

      public static BufferedImage apply(BufferedImage image, int threshold, ThresholdOp.Mode mode)
      Apply fixed threshold to a grayscale image with the specified mode. 使用指定模式对灰度图像应用固定阈值。

      The image is first converted to grayscale, then a lookup table is built according to the mode and applied to all pixels.

      图像先转换为灰度,然后根据模式构建查找表并应用于所有像素。

      Parameters:
      image - the source image | 源图像
      threshold - the threshold value [0, 255] | 阈值 [0, 255]
      mode - the threshold mode | 阈值模式
      Returns:
      the thresholded image | 阈值处理后的图像
      Throws:
      ImageOperationException - if image is null, threshold out of range, or mode is null | 当图像为 null、阈值越界或模式为 null 时抛出
    • apply

      public static BufferedImage apply(BufferedImage image, int threshold)
      Apply BINARY mode threshold (convenience method). 应用 BINARY 模式阈值(便捷方法)。

      Equivalent to apply(image, threshold, Mode.BINARY).

      等价于 apply(image, threshold, Mode.BINARY)

      Parameters:
      image - the source image | 源图像
      threshold - the threshold value [0, 255] | 阈值 [0, 255]
      Returns:
      the binary thresholded image | 二值化后的图像
      Throws:
      ImageOperationException - if image is null or threshold out of range | 当图像为 null 或阈值越界时抛出