Combining algorithms#
Combining algorithms allows users to access multiple algorithms from a single interface, such as the “Algorithm” dropdown in Napari (or the equivalent dropdown in QuPath).
Using sk.combine#
Let’s consider two separately defined algorithms:
import imaging_server_kit as sk
@sk.algorithm(
name="threshold",
description="Segment a grayscale image based on an intensity threshold."
)
def threshold_algo(image, threshold=128):
mask = image > threshold
return sk.Mask(mask, name="Binary mask")
@sk.algorithm(
name="foreground",
description="Compute the fraction of positive pixels in a binary mask."
)
def foreground_fract(mask):
fract = mask.sum() / mask.size
return sk.Float(fract, name="Foreground fraction")
You can combine these algorithms into a single collection using sk.combine:
multi_algo = sk.combine([threshold_algo, foreground_fract], name="segmentation-pipeline")
# Test the combined algorithms in Napari
sk.to_napari(multi_algo)
Using this technique, the two algorithms become available from the “Algorithm” dropdown in Napari.
Summary#
Use
sk.combineto create a collection of multiple algorithms and use them in a single interface.
Next steps#
In the next section, we will explore the concept of live updates in Imaging Server Kit.