PlantSeg plugin
See Cells from a membrane stain.
patchworks.plugins.plantseg.plantseg_fn(model: str | None = 'generic_confocal_3D_unet', *, model_id: str | None = None, config_path: str | None = None, weights_path: str | None = None, segmentation: str = 'gasp', beta: float = 0.6, post_minsize: int = 100, ws_threshold: float = 0.5, ws_sigma_seeds: float = 2.0, ws_min_size: int = 50, ws_stacked: bool = False, nuclei_sigma: Any = 1.0, nuclei_threshold: float | None = None, nuclei_min_size: int = 50, foreground: str | float | None = None, foreground_sigma: Any = 2.0, max_radius_um: float | None = None, boundary_channel: int = 0, rescale: bool = True, patch: tuple[int, ...] | None = None, device: str = 'cuda', n_threads: int | None = None, seeds: str = 'channel', voxel_size: dict[str, float] | None = None, intensity_stats: 'tuple[float, float] | None' = None) -> Callable[[np.ndarray], np.ndarray]
Return a PlantSeg segmentation for tile_process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
PlantSeg zoo model ( |
'generic_confocal_3D_unet'
|
model_id
|
str
|
Or a BioImage.IO model zoo id instead of model. |
None
|
config_path
|
str
|
Or your own trained U-Net (PlantSeg's training config and weights). |
None
|
weights_path
|
str
|
Or your own trained U-Net (PlantSeg's training config and weights). |
None
|
segmentation
|
str
|
One of :data: |
'gasp'
|
beta
|
float
|
Agglomeration bias: lower merges more (under-segments), higher splits more. PlantSeg's GUI default is 0.6. |
0.6
|
post_minsize
|
int
|
Cells smaller than this many voxels are merged into a neighbour. |
100
|
ws_threshold
|
float
|
The supervoxel watershed's (PlantSeg's |
0.5
|
ws_sigma_seeds
|
float
|
Its smoothing of the distance transform before seeding. |
2.0
|
ws_min_size
|
int
|
Its smallest supervoxel, in voxels. |
50
|
ws_stacked
|
bool
|
Run it plane by plane, for a coarse z. |
False
|
nuclei_sigma
|
float or sequence of float
|
Smoothing of the nuclear channel before finding nuclei (see
:func: |
1.0
|
nuclei_threshold
|
float
|
Intensity of the nuclear channel that counts as nucleus; None picks it by Otsu. |
None
|
nuclei_min_size
|
int
|
Smallest nucleus, in voxels. |
50
|
foreground
|
str or float
|
Background masking (see
:func: |
None
|
foreground_sigma
|
float or sequence of float
|
Smoothing before the foreground threshold. |
2.0
|
max_radius_um
|
float
|
Furthest a cell reaches from its nucleus, in micrometres (needs voxel_size); None: no limit. |
None
|
boundary_channel
|
int
|
Output channel holding the boundaries (0 for the boundary models). |
0
|
rescale
|
bool
|
Resample each tile to the model's training voxel size before predicting (and the prediction back), from voxel_size. The single biggest factor in a pretrained U-Net's quality. |
True
|
patch
|
tuple of int
|
U-Net patch shape (z, y, x). |
None
|
device
|
str
|
|
'cuda'
|
n_threads
|
int
|
Threads for the watershed and agglomeration. |
None
|
seeds
|
str
|
For the modes using nuclei: |
'channel'
|
voxel_size
|
dict of str to float
|
|
None
|
intensity_stats
|
tuple of float
|
|
None
|
Returns:
| Type | Description |
|---|---|
Callable[[ndarray], ndarray]
|
Picklable labeller: |
Source code in src/patchworks/plugins/plantseg.py
377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 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 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 | |
patchworks.plugins.plantseg.fetch_model(model: str = 'generic_confocal_3D_unet') -> None
Download a zoo model into $PLANTSEG_HOME now, not on a GPU node.
Compute nodes often have no internet access; the segment jobs then load the copy fetched here.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
The zoo model's name (default |
'generic_confocal_3D_unet'
|
Source code in src/patchworks/plugins/plantseg.py
patchworks.plugins.plantseg.available_models() -> list[str]
Names in PlantSeg's model zoo (empty without PlantSeg).
patchworks.plugins.plantseg.rescale_factors(voxel_size: dict[str, float] | None, resolution: tuple[float, ...] | None, ndim: int) -> tuple[float, ...] | None
Zoom per axis taking the image to the model's training resolution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
voxel_size
|
dict of str to float or None
|
The image's µm per voxel by axis. |
required |
resolution
|
tuple of float or None
|
The model's training voxel size, (z, y, x) µm. |
required |
ndim
|
int
|
The tile's spatial axes. |
required |
Returns:
| Type | Description |
|---|---|
tuple of float or None
|
None when either is unknown or every factor is within 10 % of 1. |
Examples:
>>> rescale_factors({"z": 0.47, "y": 0.3, "x": 0.3}, (0.235, 0.15, 0.15), 3)
(2.0, 2.0, 2.0)
>>> rescale_factors({"z": 0.24, "y": 0.15, "x": 0.15}, (0.235, 0.15, 0.15), 3)