cellpose_utils
Helper functions for image normalization in
CellposeChannel1InputModel
¶
Bases: ChannelInputModel
Channel input for cellpose with normalization options.
ATTRIBUTE | DESCRIPTION |
---|---|
wavelength_id |
Unique ID for the channel wavelength, e.g.
|
label |
Name of the channel. Can only be specified if wavelength_id is not set.
|
normalize |
Validator to handle different normalization scenarios for Cellpose models
TYPE:
|
Source code in fractal_tasks_core/tasks/cellpose_utils.py
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 |
|
CellposeChannel2InputModel
¶
Bases: BaseModel
Channel input for secondary cellpose channel with normalization options.
The secondary channel is Optional, thus both wavelength_id and label are
optional to be set. The is_set
function shows whether either value was
set.
ATTRIBUTE | DESCRIPTION |
---|---|
wavelength_id |
Unique ID for the channel wavelength, e.g. |
label |
Name of the channel. Can only be specified if wavelength_id is not set. |
normalize |
Validator to handle different normalization scenarios for Cellpose models
TYPE:
|
Source code in fractal_tasks_core/tasks/cellpose_utils.py
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 |
|
mutually_exclusive_channel_attributes()
¶
Check that only 1 of label
or wavelength_id
is set.
Source code in fractal_tasks_core/tasks/cellpose_utils.py
259 260 261 262 263 264 265 266 267 268 269 270 271 |
|
CellposeCustomNormalizer
¶
Bases: BaseModel
Validator to handle different normalization scenarios for Cellpose models
If type="default"
, then Cellpose default normalization is
used and no other parameters can be specified.
If type="no_normalization"
, then no normalization is used and no
other parameters can be specified.
If type="custom"
, then either percentiles or explicit integer
bounds can be applied.
ATTRIBUTE | DESCRIPTION |
---|---|
type |
One of
TYPE:
|
lower_percentile |
Specify a custom lower-bound percentile for rescaling as a float value between 0 and 100. Set to 1 to run the same as default). You can only specify percentiles or bounds, not both. |
upper_percentile |
Specify a custom upper-bound percentile for rescaling as a float value between 0 and 100. Set to 99 to run the same as default, set to e.g. 99.99 if the default rescaling was too harsh. You can only specify percentiles or bounds, not both. |
lower_bound |
Explicit lower bound value to rescale the image at. Needs to be an integer, e.g. 100. You can only specify percentiles or bounds, not both. |
upper_bound |
Explicit upper bound value to rescale the image at. Needs to be an integer, e.g. 2000. You can only specify percentiles or bounds, not both. |
Source code in fractal_tasks_core/tasks/cellpose_utils.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 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 |
|
cellpose_normalize: bool
property
¶
Determine whether cellpose should apply its internal normalization.
If type is set to custom
or no_normalization
, don't apply cellpose
internal normalization
CellposeModelParams
¶
Bases: BaseModel
Advanced Cellpose Model Parameters
ATTRIBUTE | DESCRIPTION |
---|---|
cellprob_threshold |
Parameter of
TYPE:
|
flow_threshold |
Parameter of
TYPE:
|
anisotropy |
Ratio of the pixel sizes along Z and XY axis (ignored if the image is not three-dimensional). If unset, it is inferred from the OME-NGFF metadata. |
min_size |
Parameter of
TYPE:
|
augment |
Parameter of
TYPE:
|
net_avg |
Parameter of
TYPE:
|
use_gpu |
If
TYPE:
|
batch_size |
number of 224x224 patches to run simultaneously on the GPU (can make smaller or bigger depending on GPU memory usage)
TYPE:
|
invert |
invert image pixel intensity before running network (if True, image is also normalized)
TYPE:
|
tile |
tiles image to ensure GPU/CPU memory usage limited (recommended)
TYPE:
|
tile_overlap |
fraction of overlap of tiles when computing flows
TYPE:
|
resample |
run dynamics at original image size (will be slower but create more accurate boundaries)
TYPE:
|
interp |
interpolate during 2D dynamics (not available in 3D) (in previous versions it was False, now it defaults to True)
TYPE:
|
stitch_threshold |
if stitch_threshold>0.0 and not do_3D and equal image sizes, masks are stitched in 3D to return volume segmentation
TYPE:
|
Source code in fractal_tasks_core/tasks/cellpose_utils.py
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 |
|
_normalize_cellpose_channels(x, channels, normalize, normalize2)
¶
Normalize a cellpose input array by channel.
PARAMETER | DESCRIPTION |
---|---|
x |
4D numpy array.
TYPE:
|
channels |
Which channels to use. If only one channel is provided, |
normalize |
By default, data is normalized so 0.0=1st percentile and 1.0=99th percentile of image intensities in each channel. This automatic normalization can lead to issues when the image to be segmented is very sparse. You can turn off the default rescaling. With the "custom" option, you can either provide your own rescaling percentiles or fixed rescaling upper and lower bound integers.
TYPE:
|
normalize2 |
Normalization options for channel 2. If one channel is normalized with default settings, both channels need to be normalized with default settings.
TYPE:
|
Source code in fractal_tasks_core/tasks/cellpose_utils.py
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
|
normalize_bounds(Y, lower=0, upper=65535)
¶
normalize image so 0.0 is lower value and 1.0 is upper value
PARAMETER | DESCRIPTION |
---|---|
Y |
The image to be normalized
TYPE:
|
lower |
Lower normalization value
TYPE:
|
upper |
Upper normalization value
TYPE:
|
Source code in fractal_tasks_core/tasks/cellpose_utils.py
457 458 459 460 461 462 463 464 465 466 467 468 |
|
normalize_percentile(Y, lower=1, upper=99)
¶
normalize image so 0.0 is lower percentile and 1.0 is upper percentile Percentiles are passed as floats (must be between 0 and 100)
PARAMETER | DESCRIPTION |
---|---|
Y |
The image to be normalized
TYPE:
|
lower |
Lower percentile
TYPE:
|
upper |
Upper percentile
TYPE:
|
Source code in fractal_tasks_core/tasks/cellpose_utils.py
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
|
normalized_img(img, axis=-1, invert=False, lower_p=1.0, upper_p=99.0, lower_bound=None, upper_bound=None)
¶
normalize each channel of the image so that so that 0.0=lower percentile or lower bound and 1.0=upper percentile or upper bound of image intensities.
The normalization can result in values < 0 or > 1 (no clipping).
Based on https://github.com/MouseLand/cellpose/blob/4f5661983c3787efa443bbbd3f60256f4fd8bf53/cellpose/transforms.py#L375 # noqa E501
optional inversion
Parameters¶
img: ND-array (at least 3 dimensions)
axis: channel axis to loop over for normalization
invert: invert image (useful if cells are dark instead of bright)
lower_p: Lower percentile for rescaling
upper_p: Upper percentile for rescaling
lower_bound: Lower fixed-value used for rescaling
upper_bound: Upper fixed-value used for rescaling
Returns¶
ND-array, float32
normalized image of same size
Source code in fractal_tasks_core/tasks/cellpose_utils.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
|