CAREamics denoising plugin
See Denoising first.
patchworks.plugins.careamics.denoise_fn(fn: Callable[[np.ndarray], np.ndarray], model: str, *, nuclei_model: str | None = None, tile_size: Sequence[int] | None = None, tile_overlap: Sequence[int] | None = None, batch_size: int = 1) -> Callable[[np.ndarray], np.ndarray]
Wrap fn so every tile is denoised before fn segments it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
callable
|
Any per-tile segmentation function. |
required |
model
|
str
|
CAREamics model for the segmented channel: a checkpoint ( |
required |
nuclei_model
|
str
|
Model for the nuclear channel ( |
None
|
tile_size
|
sequence of int
|
CAREamics' own tiling inside a patchworks tile (VRAM). Defaults:
:data: |
None
|
tile_overlap
|
sequence of int
|
CAREamics' own tiling inside a patchworks tile (VRAM). Defaults:
:data: |
None
|
batch_size
|
int
|
CAREamics tiles per forward pass. |
1
|
Returns:
| Type | Description |
|---|---|
Callable[[ndarray], ndarray]
|
Picklable |
Source code in src/patchworks/plugins/careamics.py
patchworks.plugins.careamics.denoise(tile: np.ndarray, **kwargs: Any) -> np.ndarray
Just the denoised tile, e.g. to look at it before segmenting with it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tile
|
ndarray
|
The raw tile. |
required |
**kwargs
|
Any
|
:func: |
{}
|
Returns:
| Type | Description |
|---|---|
ndarray
|
float32. |
Source code in src/patchworks/plugins/careamics.py
patchworks.plugins.careamics.train_n2v(store: str | Path, out: str | Path, *, channel: int = 0, level: int = 0, crop_shape: Sequence[int] = (32, 512, 512), n_crops: int = 4, patch_size: Sequence[int] | None = None, batch_size: int = 8, epochs: int = 30, n2v2: bool = False, work_dir: str | Path | None = None) -> Path
Train a Noise2Void model on crops of one channel of store.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
str or Path
|
OME-Zarr image (the workflow's |
required |
out
|
str or Path
|
Where to write the trained checkpoint ( |
required |
channel
|
int
|
Channel and pyramid level -- the ones the segmentation reads. |
0
|
level
|
int
|
Channel and pyramid level -- the ones the segmentation reads. |
0
|
crop_shape
|
sequence of int, int
|
What to train on: the n_crops brightest crops of that shape
(:func: |
(32, 512, 512)
|
n_crops
|
sequence of int, int
|
What to train on: the n_crops brightest crops of that shape
(:func: |
(32, 512, 512)
|
patch_size
|
sequence of int
|
Training patch, |
None
|
batch_size
|
int
|
Training length. 30 epochs takes minutes to an hour on one GPU. |
8
|
epochs
|
int
|
Training length. 30 epochs takes minutes to an hour on one GPU. |
8
|
n2v2
|
bool
|
Noise2Void2 (fewer checkerboard artefacts on structured noise). |
False
|
work_dir
|
str or Path
|
Where CAREamics keeps its logs and intermediate checkpoints. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
out. |
Source code in src/patchworks/plugins/careamics.py
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 | |
patchworks.plugins.careamics.training_crops(store: str | Path, *, channel: int = 0, level: int = 0, crop_shape: Sequence[int] = (32, 512, 512), n_crops: int = 4) -> list[np.ndarray]
The n_crops brightest crops of a channel, to train a denoiser on.
Ranked on the store's coarsest pyramid level, so picking them reads almost nothing; empty background (nothing to learn the noise of structure from) is skipped that way too.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
store
|
str or Path
|
The OME-Zarr image. |
required |
channel
|
int
|
The channel (default 0). |
0
|
level
|
int
|
The pyramid level the crops are read at (default 0). |
0
|
crop_shape
|
sequence of int
|
Each crop's shape (default |
(32, 512, 512)
|
n_crops
|
int
|
How many crops (default 4). |
4
|
Returns:
| Type | Description |
|---|---|
list of np.ndarray
|
float32 crops. |