scallops.visualize.napari.imnapari

scallops.visualize.napari.imnapari(image, labels=None, points=None, title_attribute='common_src', viewer=None, point_size=5, **kwargs)

View image in Napari.

Napari is a versatile multi-dimensional image viewer, and this function facilitates the visualization of a single image along with optional labels in the Napari viewer.

Parameters:
  • point_size (int) – Size of points if provided

  • points (DataFrame | None) – Dataframe with peaks information

  • image (DataArray | dict[str, DataArray] | None) – Image(s) to display. If a dictionary, the key would be the display name

  • labels (None | ndarray | DataArray | dict[str, ndarray | DataArray]) – Labels (e.g., from segmentation) that map label name to label array.

  • title_attribute (str) – Attribute to set as the window title

  • viewer (napari.Viewer) – An existing Napari viewer instance

  • kwargs – Keyword arguments to be passed to viewer.add_image

Returns:

Napari viewer

Example:
import xarray as xr
import numpy as np
from napari import Viewer
from scallops.visualize.napari import imnapari

# Create a synthetic image
width = 512
height = 512
channels = 3
data = np.random.randint(
    0, 255, size=(channels, height, width), dtype=np.uint8
)
coords = {
    "c": np.arange(channels),
    "y": np.arange(height),
    "x": np.arange(width),
}
synthetic_image = xr.DataArray(data, coords=coords, dims=("c", "y", "x"))

# Create a Napari viewer
viewer = Viewer()

# View the synthetic image in Napari
imnapari(synthetic_image, title_attribute="Synthetic Image", viewer=viewer)

# Run the Napari event loop
viewer.show()
Return type:

napari.Viewer