PlantSeg plugin
See Cells from a membrane stain.
patchworks.plugins.plantseg.plantseg_fn(model: str | None = 'generic_confocal_3D_unet', *, model_id: str | None = None, config_path: str | None = None, weights_path: str | None = None, segmentation: str = 'gasp', beta: float = 0.6, post_minsize: int = 100, ws_threshold: float = 0.5, ws_sigma_seeds: float = 2.0, ws_min_size: int = 50, ws_stacked: bool = False, nuclei_sigma: Any = 1.0, nuclei_threshold: float | None = None, nuclei_min_size: int = 50, foreground: str | float | None = None, foreground_sigma: Any = 2.0, max_radius_um: float | None = None, boundary_channel: int = 0, rescale: bool = True, patch: tuple[int, ...] | None = None, device: str = 'cuda', n_threads: int | None = None, seeds: str = 'channel', voxel_size: dict[str, float] | None = None) -> Callable[[np.ndarray], np.ndarray]
Return a PlantSeg segmentation for tile_process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str | None
|
PlantSeg zoo model ( |
'generic_confocal_3D_unet'
|
model_id
|
str | None
|
Or a BioImage.IO model zoo id instead of model. |
None
|
config_path
|
str | None
|
Or your own trained U-Net (PlantSeg's training config and weights). |
None
|
weights_path
|
str | None
|
Or your own trained U-Net (PlantSeg's training config and weights). |
None
|
segmentation
|
str
|
One of :data: |
'gasp'
|
beta
|
float
|
Agglomeration bias: lower merges more (under-segments), higher splits more. PlantSeg's GUI default is 0.6. |
0.6
|
post_minsize
|
int
|
Cells smaller than this many voxels are merged into a neighbour. |
100
|
ws_threshold
|
float
|
The supervoxel watershed (PlantSeg's |
0.5
|
ws_sigma_seeds
|
float
|
The supervoxel watershed (PlantSeg's |
0.5
|
ws_min_size
|
float
|
The supervoxel watershed (PlantSeg's |
0.5
|
ws_stacked
|
float
|
The supervoxel watershed (PlantSeg's |
0.5
|
nuclei_sigma
|
Any
|
How nuclei are found in the nuclear channel, see
:func: |
1.0
|
nuclei_threshold
|
Any
|
How nuclei are found in the nuclear channel, see
:func: |
1.0
|
nuclei_min_size
|
Any
|
How nuclei are found in the nuclear channel, see
:func: |
1.0
|
foreground
|
str | float | None
|
Background masking, see
:func: |
None
|
foreground_sigma
|
str | float | None
|
Background masking, see
:func: |
None
|
max_radius_um
|
str | float | None
|
Background masking, see
:func: |
None
|
boundary_channel
|
int
|
Output channel holding the boundaries (0 for the boundary models). |
0
|
rescale
|
bool
|
Resample each tile to the model's training voxel size before predicting (and the prediction back), from voxel_size. The single biggest factor in a pretrained U-Net's quality. |
True
|
patch
|
tuple[int, ...] | None
|
U-Net patch shape; |
None
|
device
|
str
|
|
'cuda'
|
n_threads
|
int | None
|
Threads for the watershed and agglomeration. |
None
|
seeds
|
str
|
For the modes using nuclei: |
'channel'
|
voxel_size
|
dict[str, float] | None
|
|
None
|
Returns:
| Type | Description |
|---|---|
Callable[[ndarray], ndarray]
|
Picklable labeller: |
Source code in src/patchworks/plugins/plantseg.py
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 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | |
patchworks.plugins.plantseg.fetch_model(model: str = 'generic_confocal_3D_unet') -> None
Download a zoo model into $PLANTSEG_HOME now, not on a GPU node.
Compute nodes often have no internet access; the segment jobs then load the copy fetched here.
Source code in src/patchworks/plugins/plantseg.py
patchworks.plugins.plantseg.available_models() -> list[str]
Names in PlantSeg's model zoo (empty without PlantSeg).
patchworks.plugins.plantseg.rescale_factors(voxel_size: dict[str, float] | None, resolution: tuple[float, ...] | None, ndim: int) -> tuple[float, ...] | None
Zoom per axis taking the image to the model's training resolution.
None when either is unknown or every factor is within 10 % of 1.
Examples:
>>> rescale_factors({"z": 0.47, "y": 0.3, "x": 0.3}, (0.235, 0.15, 0.15), 3)
(2.0, 2.0, 2.0)
>>> rescale_factors({"z": 0.24, "y": 0.15, "x": 0.15}, (0.235, 0.15, 0.15), 3)