Class MedianBlurOp

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

public final class MedianBlurOp extends Object
Median Blur Filter 中值模糊滤波器

Applies median filtering to images using the Huang sliding histogram algorithm, achieving O(W*H*K) time complexity instead of the naive O(W*H*K^2).

使用 Huang 滑动直方图算法对图像进行中值滤波, 时间复杂度为 O(W*H*K),优于朴素算法的 O(W*H*K^2)。

Features | 主要功能:

  • Effective salt-and-pepper noise removal - 有效去除椒盐噪声
  • Edge-preserving smoothing - 保边平滑
  • Huang sliding histogram for efficient computation - Huang 滑动直方图高效计算
  • Independent R/G/B channel processing with alpha preservation - 独立 R/G/B 通道处理,Alpha 通道保持不变

Usage Examples | 使用示例:

// Remove salt-and-pepper noise with 3x3 median filter
BufferedImage filtered = MedianBlurOp.apply(noisyImage, 3);

// Stronger filtering with 5x5 kernel
BufferedImage filtered = MedianBlurOp.apply(noisyImage, 5);

Performance | 性能特性:

  • Time: O(W * H * K) via Huang sliding histogram - 时间: O(W * H * K) 通过 Huang 滑动直方图
  • Space: O(W * H) + O(256) histogram - 空间: O(W * H) + O(256) 直方图

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 kernelSize)
      Apply median filter to an image. 对图像应用中值滤波。
      Parameters:
      image - the source image | 源图像
      kernelSize - the kernel size (must be odd and >= 3) | 核大小(必须为奇数且 >= 3)
      Returns:
      the filtered image | 滤波后的图像
      Throws:
      ImageOperationException - if image is null or kernelSize is invalid | 当图像为 null 或核大小无效时抛出