acia.segm.filter#
Filters for segmentating overlay objects
- class acia.segm.filter.NMSFilter[source]#
Bases:
objectNon-maximum supression filter based on contours
- class acia.segm.filter.CellFilter[source]#
Bases:
objectPluggable, physical-unit cell filter for an
Overlay.A
CellFilterkeeps contours whose backing property (its calibratedvalue()) falls within a(vmin, vmax)range. The range bounds are pintQuantityobjects in physical units (e.g.Q_(2, "um**2")) so the same filter stays valid across cameras with differentpixel_size– the per-contourvalue()is calibrated from the sourcepixel_size, not measured in raw pixels.Mirrors
PropertyExtractor: adding a new filter is a single small subclass that setsnameand overridesvalue(); there is no central registry. Instances are simply passed in a list toapply_cell_filters().- Variables:
name (str) – short identifier for the backing property (e.g.
"area").vmin – inclusive lower bound (pint
Quantity/ number), orNonefor an open lower bound.vmax – inclusive upper bound (pint
Quantity/ number), orNonefor an open upper bound.
- property range: tuple[Quantity | float | None, Quantity | float | None]#
The
(vmin, vmax)range driving this filter.
- value(cont, *, images)[source]#
Return the calibrated physical value of
contfor this filter.Subclasses derive a raw pixel measurement from
contand convert it to physical units usingimages.pixel_size.- Parameters:
cont (Contour) – the contour to measure.
images (ImageSequenceSource) – the calibrated image source (provides
pixel_size).
- Returns:
The contour’s property as a pint
Quantity.- Raises:
NotImplementedError – always, in the base class.
- Return type:
- accepts(cont, *, images)[source]#
Whether
contfalls within the(vmin, vmax)range.The comparison uses pint, so a dimensionality mismatch between the contour value and a bound (e.g. a µm² value vs a µm bound) raises a
pint.DimensionalityError– a deliberate guard against misconfigured filters.Nonebounds are open on that side.- Parameters:
cont (Contour) – the contour to test.
images (ImageSequenceSource) – the calibrated image source (provides
pixel_size).
- Returns:
Trueif the contour’s value is within range.- Return type:
- mask(properties)[source]#
Boolean keep-mask over
properties, aligned with its row order.This is the path
apply_cell_filters()uses. The values come from the column named after this filter – the one its matchingPropertyExtractoralready produced – instead of being measured again from the contours, which is both the expensive part and a second, independent implementation of the same measurement.- Parameters:
properties (pd.DataFrame) – an extractor table (see
execute()) that contains a column namedname.- Return type:
np.ndarray
A row whose value is not finite is always dropped, including by a filter with no bounds at all.
nanis what an extractor reports for a contour whose geometry it cannot measure – a collinear outline, a mask with no pixels – and a cell whose length is unknown cannot be asserted to lie within a length range. Dropping it here is what the row-wise filters effectively did before, and it keeps such a detection from surviving a one-sided bound.- Returns:
A boolean
np.ndarrayoflen(properties),Truewhere the row is finite and within the(vmin, vmax)range.- Raises:
KeyError – if
propertieshas no column for this filter.pint.DimensionalityError – if a bound’s dimension does not match the column’s – the same guard
accepts()provides, applied once per run instead of once per contour.
- Parameters:
properties (pd.DataFrame)
- Return type:
np.ndarray
- class acia.segm.filter.AreaFilter[source]#
Bases:
_ExtractorCalibratedFilterFilter cells by physical area (
pixel_size**2-> µm²).Reuses
AreaExfor calibration, so the range bounds must be areas, e.g.AreaFilter(Q_(2, "um**2"), Q_(20, "um**2")).
- class acia.segm.filter.LengthFilter[source]#
Bases:
_ExtractorCalibratedFilterFilter cells by physical length (major axis,
pixel_size-> µm).Length is the longer edge of the contour’s minimum rotated bounding box, computed exactly like
LengthEx.
- class acia.segm.filter.WidthFilter[source]#
Bases:
_ExtractorCalibratedFilterFilter cells by physical width (minor axis,
pixel_size-> µm).Width is the shorter edge of the contour’s minimum rotated bounding box, computed exactly like
WidthEx.
- class acia.segm.filter.CircularityFilter[source]#
Bases:
CellFilterFilter cells by circularity (dimensionless,
4*pi*area / perimeter**2).Computed exactly like
CircularityEx. Bounds are dimensionless (plain floats or dimensionlessQuantity), e.g.CircularityFilter(vmin=0.8).- value(cont, *, images)[source]#
Return the calibrated physical value of
contfor this filter.Subclasses derive a raw pixel measurement from
contand convert it to physical units usingimages.pixel_size.- Parameters:
cont (Contour) – the contour to measure.
images (ImageSequenceSource) – the calibrated image source (provides
pixel_size).
- Returns:
The contour’s property as a pint
Quantity.- Raises:
NotImplementedError – always, in the base class.
- Return type:
- class acia.segm.filter.BoundaryClosenessFilter[source]#
Bases:
CellFilterDrop cells whose bounding box lies near any image border.
The
value()is the minimum distance (in physical units) from the contour’s bounding box to any of the four image borders, using the sourcesize_h/size_wandpixel_size. The range is(min_distance, None)so cells closer thanmin_distanceto a border are dropped.- name: str = 'boundary_closeness'#
short identifier for the backing property; overridden by subclasses.
- __init__(min_distance)[source]#
Create the filter.
- Parameters:
min_distance (Quantity) – minimum allowed distance from any image border as a pint length
Quantity(e.g.Q_(1, "um")).- Return type:
None
- value(cont, *, images)[source]#
Return the calibrated physical value of
contfor this filter.Subclasses derive a raw pixel measurement from
contand convert it to physical units usingimages.pixel_size.- Parameters:
cont (Contour) – the contour to measure.
images (ImageSequenceSource) – the calibrated image source (provides
pixel_size).
- Returns:
The contour’s property as a pint
Quantity.- Raises:
NotImplementedError – always, in the base class.
- Return type:
- acia.segm.filter.apply_cell_filters(overlay, filters, *, properties)[source]#
Keep contours accepted by ALL filters, preserving the overlay time model.
propertiesis the table anExtractorExecutoralready produced for this overlay. Each filter reads its own column from it, so the contours are measured once (during extraction) rather than a second time here. Calibration comes from the table’s units, which is why no image source is needed.- Parameters:
overlay (Overlay) – the overlay to filter.
filters (Sequence[CellFilter]) – the cell filters to apply; a contour is kept iff every filter accepts it (logical AND). An empty filter list keeps everything.
properties (pd.DataFrame) – the extractor table describing
overlay, indexed by contour id. Every filter needs a column named after it.
- Returns:
A new
Overlaywith the kept contours and the same time model (timepoints / frame_interval). The result may be empty.- Raises:
ValueError – if
propertiesdoes not describe every contour.KeyError – if a filter has no matching column in
properties.
- Return type: