cellects.video.connected_components_tracking
cellects.video.connected_components_tracking
Tracks connected components in binary video sequences with shape analysis.
This module implements a framework for analyzing time-lapse binary images by identifying, labeling, and characterizing individual connected components (e.g., colonies, cells, or any blob) across multiple frames. It combines OpenCV-based component detection with custom descriptor computation to generate time-resolved morphological measurements. Key operations include component ID persistence across frames, centroid tracking, and conversion of raw binary data into structured pandas DataFrames for downstream analysis.
Classes:
| Name | Description |
|---|---|
ConnectedComponentsTracking : Tracks connected components in 3D binary video arrays, |
computes shape descriptors per component, and generates time-resolved output tables. |
Notes
- Uses OpenCV's connected components detection with statistical properties (area, position)
- Relies on external shape descriptor computation from
cellects.image.shape_descriptors - Requires numpy for array operations and pandas for result organization
ConnectedComponentsTracking
Tracks connected components in 3D binary video arrays
Include a method optimized for this unique task (track_cc) and a method for computing centroids and shape descriptors for each component (compute_one_descriptor_per_cc).
Source code in src/cellects/video/connected_components_tracking.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 | |
__init__(binary_vid, min_component_size)
Initialize connected components tracking with a binary video and minimum component size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
binary_vid
|
NDArray[uint8]
|
3D binary image array (time x height x width) representing object masks. |
required |
min_component_size
|
int
|
Minimum number of pixels required for a valid connected component. |
required |
Source code in src/cellects/video/connected_components_tracking.py
compute_one_descriptor_per_cc(arena_label, timings, descriptors_dict, output_in_mm, pixel_size, do_fading)
Compute and store shape descriptors for each tracked connected component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arena_label
|
int
|
Identifier for the experimental arena. |
required |
timings
|
NDArray
|
Time stamps corresponding to each frame in |
required |
descriptors_dict
|
dict
|
Mapping of descriptor names to ShapeDescriptors computation functions. |
required |
output_in_mm
|
bool
|
Whether to scale results to real-world units using pixel_size. |
required |
pixel_size
|
float
|
Conversion factor from pixels to millimeters (if |
required |
do_fading
|
bool
|
Whether to compute newly explored area as a growth metric. |
required |
Returns:
| Type | Description |
|---|---|
NDArray | DataFrame
|
Aggregated results with one row per time frame and descriptors per colony. |
Examples:
>>> descriptor_dict = {"area": compute_area, "perimeter": compute_perimeter}
>>> results = tracker.compute_one_descriptor_per_cc(arena_label=1,
... timings=np.arange(10),
... descriptors_dict=descriptor_dict,
... output_in_mm=True,
... pixel_size=2.5,
... do_fading=False)
Source code in src/cellects/video/connected_components_tracking.py
format_results(arena_label, timings, output_in_mm, pixel_size, do_fading)
Format and export tracking results to structured data files.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arena_label
|
int
|
Identifier for the experimental arena. |
required |
timings
|
NDArray
|
Time stamps corresponding to each frame in |
required |
output_in_mm
|
bool
|
Whether to scale results to real-world units using pixel_size. |
required |
pixel_size
|
float
|
Conversion factor from pixels to millimeters (if |
required |
do_fading
|
bool
|
Whether to compute newly explored area as a growth metric. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Aggregated results with one row per time frame and descriptors per colony. |
Notes
Performance: Uses efficient column concatenation for large descriptor sets.
Source code in src/cellects/video/connected_components_tracking.py
get_cc_centroid()
Compute the centroid coordinates of the current connected component.
Stores results as (time, colony_id, y, x) tuples for later analysis or visualization.
Source code in src/cellects/video/connected_components_tracking.py
get_cc_descriptors(output_in_mm, pixel_size)
Calculate and store shape descriptors for the current connected component.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_in_mm
|
bool
|
Whether to scale results to real-world units using |
required |
pixel_size
|
float
|
Conversion factor from pixels to millimeters (if |
required |
Notes
Dependency: Requires initialized ShapeDescriptors instance for computation.
Source code in src/cellects/video/connected_components_tracking.py
get_current_connected_components()
Identify valid connected components in the current time frame.
Uses OpenCV's connectedComponentsWithStats to extract component properties,
filtering out small objects below min_component_size.
Notes
Performance: Avoids redundant computation by directly using binary mask data.
Source code in src/cellects/video/connected_components_tracking.py
identify_current_cc()
Assign unique IDs and track evolution of the current connected component.
Matches colonies between frames to handle continuity, new formations, and divisions. Updates ID matrices and coordination records accordingly.
Notes
Caveat: Assumes larger colonies from divisions take priority in ID assignment.
Source code in src/cellects/video/connected_components_tracking.py
init_cc_tracking()
Reset tracking data structures before processing a new binary video.
Initializes ID matrices, coordination lists, and colony statistics counters to prepare for fresh component tracking.
Source code in src/cellects/video/connected_components_tracking.py
init_descriptors_table()
Initialize a matrix to store shape descriptors for all tracked components.
This pre-allocates memory based on worst-case scenario (maximum possible colonies) to avoid dynamic resizing during tracking iterations.
Notes
Performance: Uses pre-allocation for efficiency in large-scale analysis.
Source code in src/cellects/video/connected_components_tracking.py
track_cc()
Track connected component evolution across all time frames in the binary video.
This method processes each frame sequentially, identifying and tracking individual connected components while handling new colonies and divisions. Updates ID matrices and coordination data for visualization/tracking.
Examples:
Source code in src/cellects/video/connected_components_tracking.py
update_cc_id_matrix()
Prepare the ID matrix for the next time frame by clearing obsolete data.
Overwrites previous frame's IDs with zeros to prevent carryover artifacts, maintaining only current binary mask regions.