File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ empty_threshold: null # null → Otsu; or a number
3030
3131# ---- segmentation -----------------------------------------------------------
3232method : " cellpose" # "cellpose" (GPU), "threshold" (no GPU; testing), "custom"
33+ # dilate: 2 # optional: pixels to grow labels by after segmentation, any method
3334# Also namespaces this run's intermediate files under work_dir/<label_name>/,
3435# so a second segmentation (different label_name, e.g. nuclei vs cytoplasm)
3536# can safely target the same work_dir — see docs/guide/snakemake.md
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ skip_empty: true
2525empty_threshold : null
2626
2727method : " custom"
28+ # dilate: 2 # optional: pixels to grow labels by after segmentation
2829label_name : " cilia_labels"
2930custom :
3031 module : " patchworks.plugins.dog"
Original file line number Diff line number Diff line change @@ -133,7 +133,34 @@ def build_fn(cfg):
133133 cfg : dict
134134 Snakemake config. ``method`` selects ``"cellpose"`` (default), a simple
135135 ``"threshold"`` (testing / no-GPU), or ``"custom"`` to import your own
136- function (``cfg["custom"] = {module, function, kwargs}``).
136+ function (``cfg["custom"] = {module, function, kwargs}``). Optional
137+ ``cfg["dilate"]``: int, pixels to grow labels by after segmentation
138+ (via ``patchworks.dilate_labels``), applied regardless of ``method``.
139+ Omitted/0 disables dilation.
140+
141+ Returns
142+ -------
143+ callable
144+ ``(ndarray) -> ndarray`` returning integer labels.
145+ """
146+ fn = _build_method_fn (cfg )
147+
148+ dilate = cfg .get ("dilate" )
149+ if dilate :
150+ from patchworks import dilate_labels
151+
152+ fn = dilate_labels (fn , iterations = dilate )
153+
154+ return fn
155+
156+
157+ def _build_method_fn (cfg ):
158+ """Build the per-tile segmentation function for ``cfg["method"]``.
159+
160+ Parameters
161+ ----------
162+ cfg : dict
163+ Snakemake config, see :func:`build_fn`.
137164
138165 Returns
139166 -------
You can’t perform that action at this time.
0 commit comments