playnano.analysis.modules.particle_region_extraction module¶
Particle region extraction module for the playNano analysis pipeline.
This module extracts per-particle image regions over time using labeled masks
from a detection module (e.g. feature_detection) and particle associations
from a tracking module (e.g. particle_tracking).
For each tracked particle and each frame, the module locates the labeled region and extracts:
the tight bounding-box coordinates of the region,
an optionally padded / squared / fixed-size bounding box,
a crop of the raw image stack frame (optional),
a crop of the binary object mask (optional).
This module is a data-organisation step: it assembles per-track, per-frame region data into a consistent structure for downstream analysis and export. Per-frame statistics (mean, max, etc.) are already produced by the detection module; time-series statistics belong in a dedicated downstream module.
All outputs are None / np.nan for frames where the particle is absent
(dense tracks with missing detections) or where indices are out of range.
- class playnano.analysis.modules.particle_region_extraction.ParticleRegionExtractionModule[source]¶
Bases:
AnalysisModuleExtract per-particle image regions over time from tracked, labeled detections.
For each tracked particle and frame the module resolves the labeled region from the detection output, computes a bounding box, and optionally crops the raw image frame and/or binary mask.
This is a data-organisation step. Per-frame statistics are available from the detection module output; time-series analysis belongs in a downstream module.
The module requires: - output from a particle tracking module (e.g.
particle_tracking) - output from a labeled detection module providing:features_per_frame— list of per-frame feature dicts with a region label underlabel_key.labeled_masks— list of 2-D integer-labeled NumPy arrays.
Parameters accepted in
run()¶- paddingint, default 0
Pixels to add around the tight bounding box (clipped to image bounds).
- fixed_box_sizeint or None, default None
Enforce a fixed-size crop centred on the detection, in pixels.
- squarebool, default False
Force the bounding box to be square (ignored when
fixed_box_sizeis set).- fixed_size_mode{“global”, “per_track”}, default
"global" "global"usesfixed_box_sizedirectly;"per_track"computes the size per track as the largest detection plus2 * padding.- include_imagebool, default True
Include
"image_crop"(raw frame crop) in each region dict.- include_maskbool, default True
Include
"mask_crop"(binary foreground crop) in each region dict.- include_bboxbool, default True
Include
"bbox_tight"and"bbox_padded"in each region dict and in the flat table.
- requires = ['particle_tracking']¶
- run(stack: Any, previous_results: Dict[str, Any] | None = None, *, tracking_module: str = 'particle_tracking', detection_module: str = 'feature_detection', padding: int = 0, fixed_box_size: int | None = None, square: bool = False, fixed_size_mode: str = 'global', include_image: bool = True, include_mask: bool = True, include_bbox: bool = True, label_key: str = 'label') Dict[str, Any][source]¶
Execute the region extraction.
- Parameters:
stack (AFMImageStack) – Input image stack. Must support
stack[frame_idx]integer indexing wheninclude_image=True.previous_results (dict, optional) – Outputs from earlier pipeline modules.
tracking_module (str, default
"particle_tracking") – Key of the tracking module inprevious_results.detection_module (str, default
"feature_detection") – Key of the labeled detection module inprevious_results.padding (int, default 0) – Pixels to add around the tight bounding box on each side.
fixed_box_size (int or None, default None) – Enforce a fixed crop size in pixels, centred on the detection.
square (bool, default False) – Force the bounding box to be square (ignored when
fixed_box_sizeis set).fixed_size_mode ({“global”, “per_track”}, default
"global") –"global"usesfixed_box_sizedirectly;"per_track"computes the size per track as the largest detection plus2 * padding.include_image (bool, default True) – Include
"image_crop"in each region dict.include_mask (bool, default True) – Include
"mask_crop"in each region dict.include_bbox (bool, default True) – Include
"bbox_tight"/"bbox_padded"in each region dict and inflat_table.label_key (str, default
"label") – Key used to look up the region label in each feature dict.
- Returns:
per_tracklist of dictOne entry per track with
"track_id","frames","timestamps","fixed_box_size", and"regions". Each region entry isNone(missing detection) or a dict containing:"frame","timestamp","label""bbox_tight","bbox_padded"(if include_bbox)"image_crop"(if include_image)"mask_crop"(if include_mask)
flat_tablelist of dictRow-per-frame table suitable for
pandas.DataFrame. Array crops are excluded; bbox columns are included wheninclude_bbox=True.summarydictBookkeeping counters and configuration echo.
- Return type:
- version = '0.1.0'¶