Skip to content

User interfaces

to_napari

to_napari(
    runner: Union[AlgorithmRunner, Callable],
    viewer: Optional[Viewer] = None,
) -> Viewer

Add the dock widget of an algorithm, collection, or client to a Napari viewer.

Requires the napari extra.

Parameters:

Name Type Description Default
runner AlgorithmRunner or callable

An algorithm, an algorithm collection, or a client. A plain Python function is converted to an algorithm.

required
viewer Viewer

The viewer to add the widget to. By default, a new viewer is created.

None

Returns:

Type Description
Viewer

The viewer with the dock widget.

Examples:

>>> viewer = sk.to_napari(threshold_algo)

to_qwidget

to_qwidget(
    runner: Union[AlgorithmRunner, Callable], viewer: Viewer
) -> QWidget

Create the Napari widget of an algorithm, collection, or client, without adding it to a viewer.

Useful to ship an algorithm as a Napari plugin of its own. Requires the napari extra.

Parameters:

Name Type Description Default
runner AlgorithmRunner or callable

An algorithm, an algorithm collection, or a client. A plain Python function is converted to an algorithm.

required
viewer Viewer

The Napari viewer the widget interacts with.

required

Returns:

Type Description
QWidget

The widget, exposing the parameters and results of the runner.

to_qupath

to_qupath(
    runner: Union[AlgorithmRunner, Callable],
    port: int = 25333,
    token: str = "",
    viewer: Optional[Viewer] = None,
) -> Optional[Viewer]

Open a panel to run an algorithm, collection, or client on QuPath images. Experimental.

The panel connects to QuPath through QuBaLab and a Py4J gateway started from QuPath. Computations run inside a selected QuPath annotation (e.g. a rectangular region). Only algorithms that take a single image as input are compatible; that image is interpreted as the current QuPath image. Requires the qupath extra.

Parameters:

Name Type Description Default
runner AlgorithmRunner or callable

An algorithm, an algorithm collection, or a client. A plain Python function is converted to an algorithm.

required
port int

Port of the Py4J gateway started from QuPath.

25333
token str

Token of the Py4J gateway started from QuPath.

""
viewer Viewer

A Napari viewer to collect results that cannot be displayed in QuPath. If given, the panel is added to the viewer as a dock widget, and the viewer is returned. Otherwise, the panel opens in its own window.

None

Returns:

Type Description
Viewer or None

The viewer, if one was given.

convert

convert(
    stack: Stack, to: str = "stack"
) -> Union[Stack, Viewer]

Convert a stack into another representation.

Parameters:

Name Type Description Default
stack Stack

The stack to convert.

required
to (stack, napari)

The target representation.

"stack"

Returns:

Type Description
Stack or Viewer

With to="stack", a new stack with the same layers. With to="napari", a new Napari viewer displaying the layers (requires the napari extra).

Raises:

Type Description
ValueError

If to is not supported.