Class BilateralFilterOp

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

public final class BilateralFilterOp extends Object
Bilateral Filter 双边滤波器

Edge-preserving smoothing filter that averages nearby pixels weighted by both spatial proximity and intensity similarity. Flat regions are smoothed while edges are preserved.

保边平滑滤波器,通过空间距离和强度相似度的联合加权来平均邻近像素。 平坦区域被平滑,而边缘被保留。

Features | 主要功能:

  • Edge-preserving smoothing via bilateral weighting - 通过双边加权实现保边平滑
  • Configurable spatial and range sigma - 可配置的空间和范围 sigma
  • Independent R, G, B channel processing - 独立处理 R、G、B 通道
  • Alpha channel preservation - Alpha 通道保持不变

Usage Examples | 使用示例:

// Default bilateral filter (kernelSize=9, sigmaColor=75, sigmaSpace=75)
Raster smoothed = BilateralFilterOp.apply(raster);

// Custom parameters
Raster smoothed = BilateralFilterOp.apply(raster, 5, 50.0, 50.0);

Performance | 性能特性:

  • Time: O(W * H * K^2) where K is kernel size - 时间: O(W * H * K^2) 其中 K 为核大小
  • Space: O(W * H) - 空间: 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)
      Apply bilateral filter to a Raster with default parameters (kernelSize=9, sigmaColor=75, sigmaSpace=75). 使用默认参数对 Raster 应用双边滤波。
      Parameters:
      raster - the source raster | 源 raster
      Returns:
      the filtered raster | 滤波后的 raster
      Throws:
      NullPointerException - if raster is null | 当 raster 为 null 时抛出
      Since:
      opencode-base-image V1.0.4
    • apply

      public static Raster apply(Raster raster, int kernelSize, double sigmaColor, double sigmaSpace)
      Apply bilateral filter to a Raster with custom parameters. Output format is RGBA_8 when the source has alpha, otherwise RGB_8. 使用自定义参数对 Raster 应用双边滤波。 源含 alpha 时输出 RGBA_8,否则 RGB_8
      Parameters:
      raster - the source raster | 源 raster
      kernelSize - the kernel size (must be odd and >= 3) | 核大小(奇数且 >= 3)
      sigmaColor - the range sigma | 范围 sigma
      sigmaSpace - the spatial sigma | 空间 sigma
      Returns:
      the filtered raster | 滤波后的 raster
      Throws:
      ImageOperationException - if parameters are invalid | 参数无效时抛出
      Since:
      opencode-base-image V1.0.4
    • apply

      public static Raster apply(Raster raster, int kernelSize, double sigmaColor, double sigmaSpace, Raster dst)
      Apply bilateral filter to a Raster with optional output buffer. 对 Raster 应用双边滤波,可指定输出缓冲。
      Parameters:
      raster - the source raster | 源 raster
      kernelSize - the kernel size (must be odd and >= 3) | 核大小(奇数且 >= 3)
      sigmaColor - the range sigma | 范围 sigma
      sigmaSpace - the spatial sigma | 空间 sigma
      dst - optional output raster, may be null | 可选输出 raster,可为 null
      Returns:
      the filtered raster | 滤波后的 raster
      Throws:
      ImageOperationException - if parameters are invalid | 参数无效时抛出
      Since:
      opencode-base-image V1.0.4