Cellpose plugin
patchworks.plugins.cellpose.cellpose_fn(model: str = 'cyto3', *, gpu: bool = False, diameter: float | None = None, do_3D: bool = False, channels: list[int] | None = None, channel_axis: int | None = None, voxel_size: dict[str, float] | None = None, **cellpose_kwargs: Any) -> Callable[[np.ndarray], np.ndarray]
Return a ready-to-use Cellpose function for tile_process.
One-liner convenience wrapper: combines model configuration and function creation into a single call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Cellpose model type: |
'cyto3'
|
gpu
|
bool
|
Use GPU for inference. |
False
|
diameter
|
float | None
|
Expected cell diameter in pixels. |
None
|
do_3D
|
bool
|
Run in 3-D mode. Each tile must contain the full z-stack — use
|
False
|
channels
|
list[int] | None
|
Cellpose 3 only. |
None
|
channel_axis
|
int | None
|
Cellpose 4 only. Index of the channel axis in the input array.
|
None
|
voxel_size
|
dict[str, float] | None
|
Physical voxel size as |
None
|
**cellpose_kwargs
|
Any
|
Extra kwargs forwarded to |
{}
|
Returns:
| Type | Description |
|---|---|
Callable[[ndarray], ndarray]
|
Picklable function ready for |
Examples:
Greyscale 2-D:
>>> fn = cellpose_fn("cyto3", gpu=True, diameter=30)
>>> result = tile_process("image.zarr", fn, tile_shape=(1, 2048, 2048), overlap=20)
Nuclear segmentation:
3-D with an explicit anisotropy:
>>> fn = cellpose_fn("cyto3", gpu=True, do_3D=True, anisotropy=3.0, diameter=20)
>>> from functools import partial
>>> from patchworks import auto_tile_shape_cellpose, tile_process
>>> tile_fn = partial(auto_tile_shape_cellpose, do_3D=True, use_gpu=True, diameter=20)
>>> result = tile_process("image.zarr", fn, tile_shape=tile_fn, overlap=10)
3-D with anisotropy derived from the image's own calibration:
>>> fn = cellpose_fn("cyto3", gpu=True, do_3D=True, diameter=20,
... voxel_size={"z": 0.24, "y": 0.10833, "x": 0.10833})
Source code in src/patchworks/plugins/cellpose.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
patchworks.plugins.cellpose.cellpose_anisotropy(voxel_size: dict[str, float]) -> float | None
Cellpose's anisotropy (z voxel size / lateral voxel size) from a calibration.
do_3D assumes isotropic voxels unless told otherwise: without this,
Cellpose builds its 3-D flow-field consensus across z-planes it thinks
are spaced the same as the xy pixels, which for real data rarely holds
and fragments or distorts objects across z. Getting this wrong does not
fail loudly -- it just produces a subtly (or not so subtly) wrong
segmentation, which is why deriving it beats retyping it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
voxel_size
|
dict
|
Image calibration, e.g. from
:func: |
required |
Returns:
| Type | Description |
|---|---|
float or None
|
|
Examples: