Class BilateralFilterOp
java.lang.Object
cloud.opencode.base.image.filter.BilateralFilterOp
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)
BufferedImage smoothed = BilateralFilterOp.apply(image);
// Custom parameters
BufferedImage smoothed = BilateralFilterOp.apply(image, 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 Summary
Modifier and TypeMethodDescriptionstatic BufferedImageapply(BufferedImage image) Apply bilateral filter with default parameters (kernelSize=9, sigmaColor=75, sigmaSpace=75).static BufferedImageapply(BufferedImage image, int kernelSize, double sigmaColor, double sigmaSpace) Apply bilateral filter with custom parameters.
-
Method Details
-
apply
Apply bilateral filter with default parameters (kernelSize=9, sigmaColor=75, sigmaSpace=75). 使用默认参数(kernelSize=9, sigmaColor=75, sigmaSpace=75)应用双边滤波。- Parameters:
image- the source image | 源图像- Returns:
- the filtered image | 滤波后的图像
- Throws:
NullPointerException- if image is null | 当图像为 null 时抛出
-
apply
public static BufferedImage apply(BufferedImage image, int kernelSize, double sigmaColor, double sigmaSpace) Apply bilateral filter with custom parameters. 使用自定义参数应用双边滤波。For each pixel, computes a weighted average of its neighbors within the kernel window. The weight combines a spatial Gaussian (based on pixel distance) and a range Gaussian (based on intensity difference). R, G, B channels are processed independently.
对每个像素,计算核窗口内邻近像素的加权平均值。 权重结合了空间高斯(基于像素距离)和范围高斯(基于强度差异)。 R、G、B 通道独立处理。
- Parameters:
image- the source image | 源图像kernelSize- the kernel size (must be odd and >= 3) | 核大小(必须为奇数且 >= 3)sigmaColor- the range sigma controlling color similarity weighting (must be > 0) | 范围 sigma,控制颜色相似度权重(必须大于 0)sigmaSpace- the spatial sigma controlling distance weighting (must be > 0) | 空间 sigma,控制距离权重(必须大于 0)- Returns:
- the filtered image | 滤波后的图像
- Throws:
NullPointerException- if image is null | 当图像为 null 时抛出ImageOperationException- if parameters are invalid | 当参数无效时抛出
-