Skip to content

Predict cell instances

Use a grayscale TIFF image or volume. The output is a TIFF of integer instance labels with the same shape as the input.

morphodeep predict image.tif image_instances.tif --mode 2D --size 256
morphodeep predict volume.tif volume_instances.tif --mode 3D --size 128 \
  --voxel-size 2 1 1 --z-axis 0

The dimension is inferred when --mode is omitted. Supported published patch sizes are 256 for 2D and 128 or 256 for 3D. Overlapping patches are enabled by default; --no-patches resizes the entire image to the model input size. Voxel spacings follow array axis order. For 3D, isotropic rescaling is enabled by default and can be disabled with --no-isotrope.

Pass --weights /path/to/model.h5 to use local weights, such as those produced by fine tuning. Omit the output filename to write <input>_instances.tif. Existing outputs require --overwrite.

from tifffile import imread
from morphodeep.napari.model import run_instance_segmentation

image = imread("image.tif")
labels = run_instance_segmentation(
    image, mode="2D", net_size=256, weights_path="model.h5"
)

See the prediction API for all parameters.