Class MorphologyOp

java.lang.Object
cloud.opencode.base.image.morphology.MorphologyOp

public final class MorphologyOp extends Object
Morphological Image Operations 形态学图像操作工具类

Provides standard morphological operations on grayscale images: erosion, dilation, opening, closing, gradient, top-hat, and black-hat transforms.

提供灰度图像上的标准形态学操作:腐蚀、膨胀、开运算、闭运算、梯度、顶帽和黑帽变换。

Features | 主要功能:

  • Erosion — minimum filter over structuring element - 腐蚀 — 结构元素上的最小值滤波
  • Dilation — maximum filter over structuring element - 膨胀 — 结构元素上的最大值滤波
  • Opening — erosion followed by dilation - 开运算 — 先腐蚀后膨胀
  • Closing — dilation followed by erosion - 闭运算 — 先膨胀后腐蚀
  • Gradient — dilation minus erosion - 梯度 — 膨胀减去腐蚀
  • Top-hat — original minus opening - 顶帽 — 原图减去开运算
  • Black-hat — closing minus original - 黑帽 — 闭运算减去原图

Usage Examples | 使用示例:

StructuringElement se = StructuringElement.rect(3, 3);
Raster eroded = MorphologyOp.erode(image, se);
Raster dilated = MorphologyOp.dilate(image, se);
Raster opened = MorphologyOp.open(image, se);
Raster edges = MorphologyOp.gradient(image, se);

Performance | 性能特性:

  • Time complexity: O(w * h * kw * kh) per operation - 时间复杂度: 每次操作 O(w * h * kw * kh)
  • Space complexity: O(w * h) for output image - 空间复杂度: O(w * h) 输出图像

Security | 安全性:

  • Thread-safe: Yes (stateless) - 线程安全: 是(无状态)
  • Null-safe: No - 空值安全: 否
Since:
JDK 25, opencode-base-image V2.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • erode

      public static Raster erode(Raster raster, StructuringElement element)
      Erode a Raster using the given structuring element. 使用给定的结构元素对 Raster 进行腐蚀。
      Parameters:
      raster - the source raster | 源 raster
      element - the structuring element | 结构元素
      Returns:
      the eroded GRAY_8 raster | 腐蚀后的 GRAY_8 raster
      Throws:
      NullPointerException - if any argument is null | 当任一参数为 null 时抛出
      Since:
      opencode-base-image V1.0.4
    • dilate

      public static Raster dilate(Raster raster, StructuringElement element)
      Dilate a Raster using the given structuring element. 使用给定的结构元素对 Raster 进行膨胀。
      Parameters:
      raster - the source raster | 源 raster
      element - the structuring element | 结构元素
      Returns:
      the dilated GRAY_8 raster | 膨胀后的 GRAY_8 raster
      Throws:
      NullPointerException - if any argument is null | 当任一参数为 null 时抛出
      Since:
      opencode-base-image V1.0.4
    • open

      public static Raster open(Raster raster, StructuringElement element)
      Open a Raster (erode then dilate). 对 Raster 进行开运算(先腐蚀后膨胀)。
      Parameters:
      raster - the source raster | 源 raster
      element - the structuring element | 结构元素
      Returns:
      the opened GRAY_8 raster | 开运算后的 GRAY_8 raster
      Since:
      opencode-base-image V1.0.4
    • close

      public static Raster close(Raster raster, StructuringElement element)
      Close a Raster (dilate then erode). 对 Raster 进行闭运算(先膨胀后腐蚀)。
      Parameters:
      raster - the source raster | 源 raster
      element - the structuring element | 结构元素
      Returns:
      the closed GRAY_8 raster | 闭运算后的 GRAY_8 raster
      Since:
      opencode-base-image V1.0.4
    • gradient

      public static Raster gradient(Raster raster, StructuringElement element)
      Compute the morphological gradient (dilate - erode) on a Raster. 在 Raster 上计算形态学梯度(膨胀 - 腐蚀)。
      Parameters:
      raster - the source raster | 源 raster
      element - the structuring element | 结构元素
      Returns:
      the gradient GRAY_8 raster | 梯度 GRAY_8 raster
      Throws:
      NullPointerException - if any argument is null | 当任一参数为 null 时抛出
      Since:
      opencode-base-image V1.0.4
    • topHat

      public static Raster topHat(Raster raster, StructuringElement element)
      Compute the top-hat transform (original - opening) on a Raster. 在 Raster 上计算顶帽变换(原图 - 开运算)。
      Parameters:
      raster - the source raster | 源 raster
      element - the structuring element | 结构元素
      Returns:
      the top-hat GRAY_8 raster | 顶帽 GRAY_8 raster
      Throws:
      NullPointerException - if any argument is null | 当任一参数为 null 时抛出
      Since:
      opencode-base-image V1.0.4
    • blackHat

      public static Raster blackHat(Raster raster, StructuringElement element)
      Compute the black-hat transform (closing - original) on a Raster. 在 Raster 上计算黑帽变换(闭运算 - 原图)。
      Parameters:
      raster - the source raster | 源 raster
      element - the structuring element | 结构元素
      Returns:
      the black-hat GRAY_8 raster | 黑帽 GRAY_8 raster
      Throws:
      NullPointerException - if any argument is null | 当任一参数为 null 时抛出
      Since:
      opencode-base-image V1.0.4