Class BoxBlurOp

java.lang.Object
cloud.opencode.base.image.filter.BoxBlurOp

public final class BoxBlurOp extends Object
Box Blur Filter 均值模糊滤波器

Applies box blur (averaging filter) to images using integral images, achieving O(1) per-pixel computation regardless of kernel size.

使用积分图对图像应用均值模糊(均值滤波器), 无论核大小如何,每像素计算复杂度均为 O(1)。

Features | 主要功能:

  • O(1) per-pixel box blur via integral image - 通过积分图实现 O(1) 每像素均值模糊
  • Independent R/G/B channel processing - 独立 R/G/B 通道处理
  • Alpha channel preservation - Alpha 通道保持不变
  • Efficient for large kernel sizes - 对大核尺寸高效

Usage Examples | 使用示例:

// Mild blur with 3x3 kernel
Raster blurred = BoxBlurOp.apply(raster, 3);

// Strong blur with 31x31 kernel
Raster blurred = BoxBlurOp.apply(raster, 31);

Performance | 性能特性:

  • Time: O(W * H) regardless of kernel size - 时间: O(W * H) 与核大小无关
  • Space: O(W * H) for integral image per channel - 空间: 每通道 O(W * H) 用于积分图

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 kernelSize)
      Apply box blur to a Raster using integral images. 使用积分图对 Raster 应用均值模糊。

      Output format is RGBA_8 when the source has alpha, otherwise RGB_8. R/G/B channels are blurred independently; alpha is preserved.

      源含 alpha 时输出 RGBA_8,否则 RGB_8。 R/G/B 通道独立模糊,alpha 保留。

      Parameters:
      raster - the source raster | 源 raster
      kernelSize - the kernel size (must be odd and >= 1) | 核大小(奇数且 >= 1)
      Returns:
      the blurred raster | 模糊后的 raster
      Throws:
      ImageOperationException - if raster is null or kernelSize is invalid | 参数无效时抛出
      Since:
      opencode-base-image V1.0.4
    • apply

      public static Raster apply(Raster raster, int kernelSize, Raster dst)
      Apply box blur to a Raster with optional caller-provided output buffer. 对 Raster 应用均值模糊,可指定输出缓冲。
      Parameters:
      raster - the source raster | 源 raster
      kernelSize - the kernel size (must be odd and >= 1) | 核大小(奇数且 >= 1)
      dst - optional output raster, may be null | 可选输出 raster,可为 null
      Returns:
      the blurred raster | 模糊后的 raster
      Throws:
      ImageOperationException - if raster is null or kernelSize is invalid | 参数无效时抛出
      Since:
      opencode-base-image V1.0.4