Class AdaptiveThresholdOp

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

public final class AdaptiveThresholdOp extends Object
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
Raster binary = AdaptiveThresholdOp.apply(raster, 15, 10.0);

// Adaptive Gaussian thresholding
Raster gaussian = AdaptiveThresholdOp.apply(raster, 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:
  • Method Details

    • apply

      public static Raster apply(Raster raster, int blockSize, double c, AdaptiveThresholdOp.Method method)
      Apply adaptive threshold to a Raster with the specified method. 使用指定方法对 Raster 应用自适应阈值。
      Parameters:
      raster - the source raster | 源 raster
      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 GRAY_8 binary thresholded raster | GRAY_8 二值化后的 raster
      Throws:
      ImageOperationException - if parameters are invalid | 当参数无效时抛出
      Since:
      opencode-base-image V1.0.4
    • apply

      public static Raster apply(Raster raster, int blockSize, double c, AdaptiveThresholdOp.Method method, Raster dst)
      Apply adaptive threshold to a Raster with the specified method and optional caller-provided output buffer. 使用指定方法对 Raster 应用自适应阈值,可指定输出缓冲。
      Parameters:
      raster - the source raster | 源 raster
      blockSize - the neighborhood block size (must be odd and >= 3) | 邻域块大小(必须为奇数且 >= 3)
      c - the constant subtracted from the local mean | 从局部均值中减去的常数
      method - the adaptive method | 自适应方法
      dst - optional output raster (GRAY_8); may be null | 可选输出 raster(GRAY_8),可为 null
      Returns:
      the GRAY_8 binary thresholded raster | GRAY_8 二值化后的 raster
      Throws:
      ImageOperationException - if parameters are invalid | 当参数无效时抛出
      Since:
      opencode-base-image V1.0.4
    • apply

      public static Raster apply(Raster raster, int blockSize, double c)
      Apply adaptive threshold to a Raster with MEAN method (convenience). 使用 MEAN 方法对 Raster 应用自适应阈值(便捷方法)。
      Parameters:
      raster - the source raster | 源 raster
      blockSize - the neighborhood block size (must be odd and >= 3) | 邻域块大小(必须为奇数且 >= 3)
      c - the constant subtracted from the local mean | 从局部均值中减去的常数
      Returns:
      the GRAY_8 binary thresholded raster | GRAY_8 二值化后的 raster
      Throws:
      ImageOperationException - if parameters are invalid | 当参数无效时抛出
      Since:
      opencode-base-image V1.0.4