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
ConstructorsConstructorDescriptionStructuringElement(boolean[] mask, int width, int height, int anchorX, int anchorY) Compact constructor with validation. -
Method Summary
Modifier and TypeMethodDescriptionintanchorX()Returns the value of theanchorXrecord component.intanchorY()Returns the value of theanchorYrecord component.static StructuringElementcross(int size) Create a cross (plus) shaped structuring element.static StructuringElementellipse(int width, int height) Create an elliptical structuring element.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.intheight()Returns the value of theheightrecord component.boolean[]mask()Return a defensive copy of the mask.static StructuringElementrect(int width, int height) Create a rectangular structuring element with all mask values set to true.final StringtoString()Returns a string representation of this record class.intwidth()Returns the value of thewidthrecord component.
-
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
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
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
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
-
hashCode
-
equals
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 withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
width
-
height
-
anchorX
-
anchorY
-