Priority: Medium (Performance Improvement)
The private method _crop_random in img_proc/crop.py is currently inefficient. It uses a guessing loop (while (crop_count < num_random_tracks)) that randomly selects coordinates and performs slow, frame-by-frame validation for three criteria: spatial boundaries, APO-blocking status, and correct size.
This iterative approach is computationally wasteful for checks based on static volume data.
Proposed Solution
Dramatically improve performance by replacing the blocking checks with a single, fast 3D Maximum Filter pre-calculation.
Implementation Plan:
-
Pre-Calculation (New Block in _crop_random):
- Use
scipy.ndimage.maximum_filter of size $(\text{L}, \text{W}, \text{W})$ (Length, Window, Window) on the apo_check_array.
- Find all coordinates $(\text{t}, \text{y}, \text{x})$ where the filtered volume is $\mathbf{0}$. These are the guaranteed valid centers concerning spatial boundaries and static APO-blocking.
- Store the result as a list of candidate center tuples.
-
Sampling:
- Replace the inefficient
while guessing loop with a direct random.sample() from the pre-calculated list of valid candidate centers.
File Location: img_proc/crop.py, method _crop_random(self, ...)
Priority: Medium (Performance Improvement)
The private method
_crop_randominimg_proc/crop.pyis currently inefficient. It uses a guessing loop (while (crop_count < num_random_tracks)) that randomly selects coordinates and performs slow, frame-by-frame validation for three criteria: spatial boundaries, APO-blocking status, and correct size.This iterative approach is computationally wasteful for checks based on static volume data.
Proposed Solution
Dramatically improve performance by replacing the blocking checks with a single, fast 3D Maximum Filter pre-calculation.
Implementation Plan:
Pre-Calculation (New Block in
_crop_random):scipy.ndimage.maximum_filterof sizeapo_check_array.Sampling:
whileguessing loop with a directrandom.sample()from the pre-calculated list of valid candidate centers.File Location:
img_proc/crop.py, method_crop_random(self, ...)