Record Class StructuringElement

java.lang.Object
java.lang.Record
cloud.opencode.base.image.morphology.StructuringElement
Record Components:
mask - the binary mask array of length width*height | 长度为 width*height 的二值掩码数组
width - the width of the structuring element (must be positive and odd) | 结构元素宽度(必须为正奇数)
height - the height of the structuring element (must be positive and odd) | 结构元素高度(必须为正奇数)
anchorX - the x-coordinate of the anchor point | 锚点 x 坐标
anchorY - the y-coordinate of the anchor point | 锚点 y 坐标

public record StructuringElement(boolean[] mask, int width, int height, int anchorX, int anchorY) extends Record
Structuring Element for Morphological Operations 形态学运算的结构元素

Defines a binary mask used as the kernel for morphological operations such as erosion, dilation, opening, and closing. Provides factory methods for common shapes.

定义用于形态学操作(如腐蚀、膨胀、开运算、闭运算)内核的二值掩码, 提供常用形状的工厂方法。

Features | 主要功能:

  • Rectangular structuring element - 矩形结构元素
  • Elliptical structuring element - 椭圆形结构元素
  • Cross (plus) structuring element - 十字形结构元素
  • Custom anchor point support - 自定义锚点支持

Usage Examples | 使用示例:

StructuringElement rect = StructuringElement.rect(3, 3);
StructuringElement ellipse = StructuringElement.ellipse(5, 5);
StructuringElement cross = StructuringElement.cross(3);
BufferedImage eroded = MorphologyOp.erode(image, rect);

Security | 安全性:

  • Thread-safe: Yes (immutable record) - 线程安全: 是(不可变记录)
  • Null-safe: No - 空值安全: 否
Since:
JDK 25, opencode-base-image V2.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    StructuringElement(boolean[] mask, int width, int height, int anchorX, int anchorY)
    Compact constructor with validation.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the value of the anchorX record component.
    int
    Returns the value of the anchorY record component.
    cross(int size)
    Create a cross (plus) shaped structuring element.
    ellipse(int width, int height)
    Create an elliptical structuring element.
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    int
    Returns the value of the height record component.
    boolean[]
    Return a defensive copy of the mask.
    rect(int width, int height)
    Create a rectangular structuring element with all mask values set to true.
    final String
    Returns a string representation of this record class.
    int
    Returns the value of the width record component.

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • StructuringElement

      public StructuringElement(boolean[] mask, int width, int height, int anchorX, int anchorY)
      Compact constructor with validation. 带验证的紧凑构造器。
  • Method Details

    • mask

      public boolean[] mask()
      Return a defensive copy of the mask. 返回掩码的防御性副本。
      Returns:
      a copy of the mask array | 掩码数组的副本
    • rect

      public static StructuringElement rect(int width, int height)
      Create a rectangular structuring element with all mask values set to true. 创建所有掩码值为 true 的矩形结构元素。
      Parameters:
      width - the width (must be positive and odd) | 宽度(必须为正奇数)
      height - the height (must be positive and odd) | 高度(必须为正奇数)
      Returns:
      a rectangular structuring element | 矩形结构元素
      Throws:
      ImageOperationException - if dimensions are invalid | 当尺寸无效时抛出
    • ellipse

      public static StructuringElement ellipse(int width, int height)
      Create an elliptical structuring element. 创建椭圆形结构元素。

      Pixels inside the ellipse inscribed in the width x height rectangle are set to true.

      在 width x height 矩形内接椭圆内的像素设置为 true。

      Parameters:
      width - the width (must be positive and odd) | 宽度(必须为正奇数)
      height - the height (must be positive and odd) | 高度(必须为正奇数)
      Returns:
      an elliptical structuring element | 椭圆形结构元素
      Throws:
      ImageOperationException - if dimensions are invalid | 当尺寸无效时抛出
    • cross

      public static StructuringElement cross(int size)
      Create a cross (plus) shaped structuring element. 创建十字形结构元素。

      The cross is formed by the center row and center column of a size x size grid.

      十字由 size x size 网格的中心行和中心列构成。

      Parameters:
      size - the width and height (must be positive and odd) | 宽度和高度(必须为正奇数)
      Returns:
      a cross-shaped structuring element | 十字形结构元素
      Throws:
      ImageOperationException - if size is invalid | 当尺寸无效时抛出
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • width

      public int width()
      Returns the value of the width record component.
      Returns:
      the value of the width record component
    • height

      public int height()
      Returns the value of the height record component.
      Returns:
      the value of the height record component
    • anchorX

      public int anchorX()
      Returns the value of the anchorX record component.
      Returns:
      the value of the anchorX record component
    • anchorY

      public int anchorY()
      Returns the value of the anchorY record component.
      Returns:
      the value of the anchorY record component