Nuclei-seeded watershed plugin
See Cells from a membrane stain.
patchworks.plugins.watershed.watershed_fn(*, boundary_sigma: Any = 1.0, nuclei_sigma: Any = 1.0, nuclei_threshold: float | None = None, nuclei_min_size: int = 50, foreground: str | float | None = 'otsu', foreground_sigma: Any = 2.0, max_radius_um: float | None = None, compactness: float = 0.0, min_size: int = 0, sigma_units: str = 'px', seeds: str = 'channel', voxel_size: dict[str, float] | None = None) -> Callable[[np.ndarray], np.ndarray]
Return a nuclei-seeded watershed for tile_process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundary_sigma
|
float or sequence of float
|
Smoothing of the membrane channel before flooding it. |
1.0
|
nuclei_sigma
|
float or sequence of float
|
Smoothing of the nuclear channel before finding the nuclei (see
:func: |
1.0
|
nuclei_threshold
|
float
|
An intensity of the nuclear channel: above it is nucleus. |
None
|
nuclei_min_size
|
int
|
Smallest nucleus, in voxels. |
50
|
foreground
|
str or float
|
Tissue mask from the membrane channel: |
'otsu'
|
foreground_sigma
|
float or sequence of float
|
Smoothing of the membrane channel before the foreground threshold. |
2.0
|
max_radius_um
|
float
|
Furthest a cell reaches from its nucleus, in micrometres (needs
voxel_size; the workflow passes it). |
None
|
compactness
|
float
|
|
0.0
|
min_size
|
int
|
Drop cells smaller than this many voxels. |
0
|
sigma_units
|
str
|
|
'px'
|
seeds
|
str
|
|
'channel'
|
voxel_size
|
dict of str to float
|
|
None
|
Returns:
| Type | Description |
|---|---|
Callable[[ndarray], ndarray]
|
Picklable |
Source code in src/patchworks/plugins/watershed.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 | |
patchworks.plugins.watershed.nuclei_seeds(nuclei: np.ndarray, *, sigma: Any = 1.0, threshold: float | None = None, min_size: int = 50) -> np.ndarray
Label the nuclei of a nuclear-dye image, to seed the cells with.
Smooth, threshold, fill holes, drop specks and label what is left.
Two touching nuclei come out as one seed, so the two cells around them
as one cell: raise threshold if that happens, or give the seeds from
a nuclei model (:func:seeded_watershed takes any label image).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nuclei
|
ndarray
|
The nuclear channel. |
required |
sigma
|
float or sequence of float
|
Gaussian smoothing first, in pixels (default 1). |
1.0
|
threshold
|
float
|
The intensity above which is nucleus, in the image's own units; None picks it by Otsu. |
None
|
min_size
|
int
|
Drop nuclei smaller than this many voxels (default 50). |
50
|
Returns:
| Type | Description |
|---|---|
ndarray
|
int32 seeds. |
Source code in src/patchworks/plugins/watershed.py
patchworks.plugins.watershed.foreground_mask(membrane: np.ndarray, seeds: np.ndarray, *, foreground: str | float | None = 'otsu', sigma: Any = 2.0, max_radius: tuple[float, ...] | None = None) -> np.ndarray | None
Where cells may grow: tissue and/or near a seed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
membrane
|
ndarray
|
The membrane channel. |
required |
seeds
|
ndarray
|
The seeds, for max_radius. |
required |
foreground
|
str or float
|
|
'otsu'
|
sigma
|
float or sequence of float
|
Smoothing before that threshold, in pixels (default 2). |
2.0
|
max_radius
|
tuple of float
|
Keep only what lies within this distance of a seed (pixels per axis), so a cell on the tissue's edge stops instead of flooding the empty space beyond it. |
None
|
Returns:
| Type | Description |
|---|---|
np.ndarray of bool or None
|
The mask; None (anywhere) when neither applies. |
Source code in src/patchworks/plugins/watershed.py
patchworks.plugins.watershed.seeded_watershed(boundaries: np.ndarray, seeds: np.ndarray, *, mask: np.ndarray | None = None, compactness: float = 0.0, min_size: int = 0) -> np.ndarray
Flood boundaries (high on cell walls) from the labelled seeds.
Every seed becomes exactly one cell.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
boundaries
|
ndarray
|
The membrane signal, high on cell walls. |
required |
seeds
|
ndarray
|
The seed labels. |
required |
mask
|
np.ndarray of bool
|
Cells stop at its edge. |
None
|
compactness
|
float
|
|
0.0
|
min_size
|
int
|
Drop cells smaller than this many voxels (a seed in a speck of tissue); 0 (default) keeps all. |
0
|
Returns:
| Type | Description |
|---|---|
ndarray
|
int32 cells. |