From b0716af19eb2f1a141a4d97a8b01d52ee1478566 Mon Sep 17 00:00:00 2001 From: Tim Blakely Date: Thu, 9 Apr 2026 12:22:27 -0700 Subject: [PATCH] Allow specifying `threshold_abs` and `threshold_rel`. This fixes the drop-everything-under-zero bug in ExaSPIM PiperOrigin-RevId: 897242664 --- ffn/inference/seed.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/ffn/inference/seed.py b/ffn/inference/seed.py index 1c6af68..1334e54 100644 --- a/ffn/inference/seed.py +++ b/ffn/inference/seed.py @@ -316,11 +316,39 @@ def init_coords(self): class PolicyMaxPeaks(BaseSeedPolicy): """Local peaks of intensity.""" + def __init__( + self, canvas, min_distance=3, threshold_abs=0, threshold_rel=0, **kwargs + ): + """Initialize settings. + + Args: + canvas: inference Canvas object. + min_distance: forwarded to peak_local_max. + threshold_abs: forwarded to peak_local_max. + threshold_rel: forwarded to peak_local_max. + **kwargs: forwarded to base. + """ + super().__init__(canvas, **kwargs) + logging.info( + 'max peaks: min_distance=%s, threshold_abs=%s, threshold_rel=%s', + min_distance, + threshold_abs, + threshold_rel, + ) + self.min_distance = min_distance + self.threshold_abs = threshold_abs + self.threshold_rel = threshold_rel + def init_coords(self): img = self.canvas.image.astype(np.float32).copy() mask = self.get_exclusion_mask() img[mask] = 0 - idxs = _find_peaks(img, min_distance=3, threshold_abs=0, threshold_rel=0) + idxs = _find_peaks( + img, + min_distance=self.min_distance, + threshold_abs=self.threshold_abs, + threshold_rel=self.threshold_rel, + ) self.coords = np.array(sorted((z, y, x) for z, y, x in idxs))