FilterROIBySize
eitprocessing.roi.filter_by_size
¶
FilterROIBySize
dataclass
¶
FilterROIBySize(
*,
min_region_size: int = DEFAULT_MIN_REGION_SIZE,
connectivity: Literal[1, 2] | ndarray = 1
)
Class for labeling and selecting connected regions in a PixelMask.
This dataclass identifies and labels regions of interest (ROIs) in a PixelMask. You can specify the minimum region size and the connectivity structure.
Connectivity
For 2D images, connectivity determines which pixels are considered neighbors when labeling regions. - 1-connectivity (also called 4-connectivity in image processing): Only directly adjacent pixels (up, down, left, right) are considered neighbors. - 2-connectivity (also called 8-connectivity in image processing): Both directly adjacent and diagonal pixels are considered neighbors.
The default value is 1-connectivity.
If a custom array is provided, it must be a boolean or integer array specifying the neighborhood structure.
See the documentation for scipy.ndimage.label
:
https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.label.html
PARAMETER | DESCRIPTION |
---|---|
min_region_size
|
Minimum number of pixels in a region for it to be considered an ROI. Defaults to 10.
TYPE:
|
connectivity
|
Connectivity type or custom array. Defaults to 1. |
apply
¶
Identify connected regions in a PixelMask, filter them by size, and return a combined mask.
This method:
- Converts the input PixelMask into a binary representation where all non-NaN values are treated as part of a region and NaNs are excluded.
- Labels connected components using the specified connectivity structure.
- Keeps only those connected regions whose pixel count is greater than or equal
to
self.min_region_size
. - Combines the remaining regions into a single PixelMask.
PARAMETER | DESCRIPTION |
---|---|
mask
|
Input mask where non-NaN pixels are considered valid region pixels. NaNs are treated as excluded/background.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
PixelMask
|
A new PixelMask representing the union of all regions that meet the
TYPE:
|
RAISES | DESCRIPTION |
---|---|
RuntimeError
|
If no connected regions meet the size threshold (e.g., mask is empty, all regions are too small, or connectivity is too restrictive). |