napari viewer plugin
Open an OME-ZARR image and overlay the labels produced by
tile_process as a napari Labels layer in a single
call. Requires the optional napari extra (pip install "patchworks[napari]").
patchworks.plugins.napari.view_in_napari(image: Union[da.Array, str, Path], labels: Union[da.Array, str, Path, None] = None, *, channel: int | None = None, labels_component: str = 'labels', image_name: str = 'image', labels_name: str = 'labels', glasbey: bool = True, show: bool = True, split_channels: bool = True, shown: 'Sequence[int] | None' = None, hover: bool = True, **add_image_kwargs: Any)
Open image in napari and overlay labels as a Labels layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
(Array, str or Path)
|
OME-ZARR store (multi-scale aware), any bioio-readable file, or an in-memory array. |
required |
labels
|
(Array, str, Path or None)
|
Label array to overlay. A plain |
None
|
channel
|
int or None
|
Channel to display from the image. |
None
|
labels_component
|
str
|
Array name inside a plain-zarr label store (default |
'labels'
|
image_name
|
str
|
Layer names shown in napari. |
'image'
|
labels_name
|
str
|
Layer names shown in napari. |
'image'
|
glasbey
|
bool
|
Colour the labels with a glasbey palette (many distinct, high-contrast
colours, tuned to read on the dark canvas) instead of napari's default.
Default |
True
|
show
|
bool
|
Start the napari event loop (blocking). Set |
True
|
split_channels
|
bool
|
Each channel its own layer (default), so several can be shown
together, each in its own colour; |
True
|
shown
|
sequence of int
|
The channels visible at first (default: the first). A hidden channel is not read until it is switched on. |
None
|
hover
|
bool
|
Show each object's parent and children when hovering it, from the object tables, read in the background once the window is up (for a whole slide, minutes of reading the network shares with zooming). |
True
|
**add_image_kwargs
|
Any
|
Extra keyword arguments forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Viewer
|
The viewer instance (useful when |
Notes
In 3-D view (the cube icon, or viewer.dims.ndisplay = 3), napari
always shows the coarsest pyramid level — there is no automatic
zoom-based switching in 3-D, only in 2-D. To pin a specific resolution
(needs napari>=0.7.1)::
viewer.layers["labels"].locked_data_level = 0 # full resolution
viewer.layers["labels"].locked_data_level = None # back to coarsest
A widget for this is also in the layer controls panel in napari>=0.7.1.
Examples:
Source code in src/patchworks/plugins/napari.py
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 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 | |