roi
Subpackage for ROI-related functions.
apply_shift_in_one_direction(tmp_df_well, line_1, line_2, mu, tol=1e-10)
¶
TBD
PARAMETER | DESCRIPTION |
---|---|
tmp_df_well |
TBD
TYPE:
|
line_1 |
TBD |
line_2 |
TBD |
mu |
TBD
TYPE:
|
tol |
TBD
TYPE:
|
Source code in fractal_tasks_core/roi/v1_overlaps.py
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 |
|
are_ROI_table_columns_valid(*, table)
¶
Verify some validity assumptions on a ROI table.
This function reflects our current working assumptions (e.g. the presence of some specific columns); this may change in future versions.
PARAMETER | DESCRIPTION |
---|---|
table |
AnnData table to be checked
TYPE:
|
Source code in fractal_tasks_core/roi/v1_checks.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
|
array_to_bounding_box_table(mask_array, pxl_sizes_zyx, origin_zyx=(0, 0, 0))
¶
Construct bounding-box ROI table for a mask array.
PARAMETER | DESCRIPTION |
---|---|
mask_array |
Original array to construct bounding boxes.
TYPE:
|
pxl_sizes_zyx |
Physical-unit pixel ZYX sizes. |
origin_zyx |
Shift ROI origin by this amount of ZYX pixels. |
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
DataFrame with each line representing the bounding-box ROI that
corresponds to a unique value of |
Source code in fractal_tasks_core/roi/v1.py
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 361 362 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 |
|
check_valid_ROI_indices(list_indices, ROI_table_name)
¶
Check that list of indices has zero origin on each axis.
See fractal-tasks-core issues #530 and #554.
This helper function is meant to provide informative error messages when ROI tables created with fractal-tasks-core up to v0.11 are used in v0.12. This function will be deprecated and removed as soon as the v0.11/v0.12 transition advances.
Note that only FOV_ROI_table
and well_ROI_table
have to fulfill this
constraint, while ROI tables obtained through segmentation may have
arbitrary (non-negative) indices.
PARAMETER | DESCRIPTION |
---|---|
list_indices |
Output of |
ROI_table_name |
Name of the ROI table.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If the table name is |
Source code in fractal_tasks_core/roi/v1_checks.py
28 29 30 31 32 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 |
|
check_well_for_FOV_overlap(site_metadata, selected_well, plotting_function, tol=1e-10)
¶
This function is currently only used in tests and examples.
The plotting_function
parameter is exposed so that other tools (see
examples in this repository) may use it to show the FOV ROIs.
PARAMETER | DESCRIPTION |
---|---|
site_metadata |
TBD
TYPE:
|
selected_well |
TBD
TYPE:
|
plotting_function |
TBD
TYPE:
|
tol |
TBD
TYPE:
|
Source code in fractal_tasks_core/roi/v1_overlaps.py
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 |
|
convert_ROI_table_to_indices(ROI, full_res_pxl_sizes_zyx, level=0, coarsening_xy=2, cols_xyz_pos=['x_micrometer', 'y_micrometer', 'z_micrometer'], cols_xyz_len=['len_x_micrometer', 'len_y_micrometer', 'len_z_micrometer'])
¶
Convert a ROI AnnData table into integer array indices.
PARAMETER | DESCRIPTION |
---|---|
ROI |
AnnData table with list of ROIs.
TYPE:
|
full_res_pxl_sizes_zyx |
Physical-unit pixel ZYX sizes at the full-resolution pyramid level. |
level |
Pyramid level.
TYPE:
|
coarsening_xy |
Linear coarsening factor in the YX plane.
TYPE:
|
cols_xyz_pos |
Column names for XYZ ROI positions.
TYPE:
|
cols_xyz_len |
Column names for XYZ ROI edges.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If any of the array indices is negative. |
RETURNS | DESCRIPTION |
---|---|
list[list[int]]
|
Nested list of indices. The main list has one item per ROI. Each ROI
item is a list of six integers as in |
Source code in fractal_tasks_core/roi/v1.py
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 |
|
convert_ROIs_from_3D_to_2D(adata, pixel_size_z)
¶
TBD
Note that this function is only relevant when the ROIs in adata span the whole extent of the Z axis. TODO: check this explicitly.
PARAMETER | DESCRIPTION |
---|---|
adata |
TBD
TYPE:
|
pixel_size_z |
TBD
TYPE:
|
Source code in fractal_tasks_core/roi/v1.py
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 |
|
convert_indices_to_regions(index)
¶
Converts index tuples to region tuple
PARAMETER | DESCRIPTION |
---|---|
index |
Tuple containing 6 entries of (z_start, z_end, y_start, y_end, x_start, x_end). |
RETURNS | DESCRIPTION |
---|---|
region
|
tuple of three slices (ZYX) |
Source code in fractal_tasks_core/roi/v1.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
|
create_roi_table_from_df_list(bbox_dataframe_list)
¶
Creates an AnnData ROI table from a list of bounding-box tables
This function handles empty bbox lists, ensures that it has unique entries per label (and to address #810, it handles duplicate labels by only keeping the first entry for each label) & converts it to an AnnData table with a label column in obs.
PARAMETER | DESCRIPTION |
---|---|
bbox_dataframe_list |
List of bounding box dataframes. All dataframes are expected to have the same columns and they usually are: x_micrometer, y_micrometer, z_micrometer, len_x_micrometer, len_y_micrometer, len_z_micrometer, label. The label column is required.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
AnnData
|
An |
Source code in fractal_tasks_core/roi/v1.py
585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 |
|
empty_bounding_box_table()
¶
Construct an empty bounding-box ROI table of given shape.
This function mirrors the functionality of array_to_bounding_box_table
,
for the specific case where the array includes no label. The advantages of
this function are that:
- It does not require computing a whole array of zeros;
- We avoid hardcoding column names in the task functions.
RETURNS | DESCRIPTION |
---|---|
DataFrame
|
DataFrame with no rows, and with columns corresponding to the output of
|
Source code in fractal_tasks_core/roi/v1.py
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 |
|
find_overlaps_in_ROI_indices(list_indices)
¶
Given a list of integer ROI indices, find whether there are overlaps.
PARAMETER | DESCRIPTION |
---|---|
list_indices |
List of ROI indices, where each element in the list
should look like
|
RETURNS | DESCRIPTION |
---|---|
Optional[tuple[int, int]]
|
|
Source code in fractal_tasks_core/roi/v1_overlaps.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
|
get_image_grid_ROIs(array_shape, pixels_ZYX, grid_YX_shape)
¶
Produce a table with ROIS placed on a rectangular grid.
The main goal of this ROI grid is to allow processing of smaller subset of the whole array.
In a specific case (that is, if the image array was obtained by stitching together a set of FOVs placed on a regular grid), the ROIs correspond to the original FOVs.
TODO: make this flexible with respect to the presence/absence of Z.
PARAMETER | DESCRIPTION |
---|---|
array_shape |
ZYX shape of the image array. |
pixels_ZYX |
ZYX pixel sizes in micrometers. |
grid_YX_shape |
|
RETURNS | DESCRIPTION |
---|---|
AnnData
|
An |
Source code in fractal_tasks_core/roi/v1.py
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 |
|
get_overlapping_pair(tmp_df, tol=1e-10)
¶
Finds the indices for the next overlapping FOVs pair.
Note: the returned indices are positional indices, starting from 0.
PARAMETER | DESCRIPTION |
---|---|
tmp_df |
Dataframe with columns
TYPE:
|
tol |
Finite tolerance for floating-point comparisons.
TYPE:
|
Source code in fractal_tasks_core/roi/v1_overlaps.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
get_overlapping_pairs_3D(tmp_df, full_res_pxl_sizes_zyx)
¶
Finds the indices for the all overlapping FOVs pair, in three dimensions.
Note: the returned indices are positional indices, starting from 0.
PARAMETER | DESCRIPTION |
---|---|
tmp_df |
Dataframe with columns
TYPE:
|
full_res_pxl_sizes_zyx |
TBD |
Source code in fractal_tasks_core/roi/v1_overlaps.py
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 |
|
get_single_image_ROI(array_shape, pixels_ZYX)
¶
Produce a table with a single ROI that covers the whole array
TODO: make this flexible with respect to the presence/absence of Z.
PARAMETER | DESCRIPTION |
---|---|
array_shape |
ZYX shape of the image array. |
pixels_ZYX |
ZYX pixel sizes in micrometers. |
RETURNS | DESCRIPTION |
---|---|
AnnData
|
An |
Source code in fractal_tasks_core/roi/v1.py
474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
|
is_ROI_table_valid(*, table_path, use_masks)
¶
Verify some validity assumptions on a ROI table.
This function reflects our current working assumptions (e.g. the presence of some specific columns); this may change in future versions.
If use_masks=True
, we verify that the table is a valid
masking_roi_table
as of table specifications V1; if this check fails,
use_masks
should be set to False
upstream in the parent function.
PARAMETER | DESCRIPTION |
---|---|
table_path |
Path of the AnnData ROI table to be checked.
TYPE:
|
use_masks |
If
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Optional[bool]
|
Always |
Source code in fractal_tasks_core/roi/v1_checks.py
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 |
|
is_overlapping_1D(line1, line2, tol=1e-10)
¶
Given two intervals, finds whether they overlap.
This is based on https://stackoverflow.com/a/70023212/19085332, and we additionally use a finite tolerance for floating-point comparisons.
PARAMETER | DESCRIPTION |
---|---|
line1 |
The boundaries of the first interval, written as
|
line2 |
The boundaries of the second interval, written as
|
tol |
Finite tolerance for floating-point comparisons.
TYPE:
|
Source code in fractal_tasks_core/roi/_overlaps_common.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
|
is_overlapping_2D(box1, box2, tol=1e-10)
¶
Given two rectangular boxes, finds whether they overlap.
This is based on https://stackoverflow.com/a/70023212/19085332, and we additionally use a finite tolerance for floating-point comparisons.
PARAMETER | DESCRIPTION |
---|---|
box1 |
The boundaries of the first rectangle, written as
|
box2 |
The boundaries of the second rectangle, written as
|
tol |
Finite tolerance for floating-point comparisons.
TYPE:
|
Source code in fractal_tasks_core/roi/_overlaps_common.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
|
is_overlapping_3D(box1, box2, tol=1e-10)
¶
Given two three-dimensional boxes, finds whether they overlap.
This is based on https://stackoverflow.com/a/70023212/19085332, and we additionally use a finite tolerance for floating-point comparisons.
PARAMETER | DESCRIPTION |
---|---|
box1 |
The boundaries of the first box, written as
|
box2 |
The boundaries of the second box, written as
|
tol |
Finite tolerance for floating-point comparisons.
TYPE:
|
Source code in fractal_tasks_core/roi/_overlaps_common.py
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 |
|
is_standard_roi_table(table)
¶
True if the name of the table contains one of the standard Fractal tables
If a table name is well_ROI_table, FOV_ROI_table or contains either of the two (e.g. registered_FOV_ROI_table), this function returns True.
PARAMETER | DESCRIPTION |
---|---|
table |
table name
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
bool of whether it's a standard ROI table |
Source code in fractal_tasks_core/roi/v1.py
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
|
prepare_FOV_ROI_table(df, metadata=('time'))
¶
Prepare an AnnData table for fields-of-view ROIs.
PARAMETER | DESCRIPTION |
---|---|
df |
Input dataframe, possibly prepared through
TYPE:
|
metadata |
Columns of |
Source code in fractal_tasks_core/roi/v1.py
27 28 29 30 31 32 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 |
|
prepare_well_ROI_table(df, metadata=('time'))
¶
Prepare an AnnData table with a single well ROI.
PARAMETER | DESCRIPTION |
---|---|
df |
Input dataframe, possibly prepared through
TYPE:
|
metadata |
Columns of |
Source code in fractal_tasks_core/roi/v1.py
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 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 |
|
remove_FOV_overlaps(df)
¶
Given a metadata dataframe, shift its columns to remove FOV overlaps.
PARAMETER | DESCRIPTION |
---|---|
df |
Metadata dataframe.
TYPE:
|
Source code in fractal_tasks_core/roi/v1_overlaps.py
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 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 |
|
reset_origin(ROI_table, x_pos='x_micrometer', y_pos='y_micrometer', z_pos='z_micrometer')
¶
Return a copy of a ROI table, with shifted-to-zero origin for some columns.
PARAMETER | DESCRIPTION |
---|---|
ROI_table |
Original ROI table.
TYPE:
|
x_pos |
Name of the column with X position of ROIs.
TYPE:
|
y_pos |
Name of the column with Y position of ROIs.
TYPE:
|
z_pos |
Name of the column with Z position of ROIs.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
AnnData
|
A copy of the |
Source code in fractal_tasks_core/roi/v1.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 |
|
run_overlap_check(site_metadata, tol=1e-10, plotting_function=None)
¶
Run an overlap check over all wells and optionally plots overlaps.
This function is currently only used in tests and examples.
The plotting_function
parameter is exposed so that other tools (see
examples in this repository) may use it to show the FOV ROIs. Its arguments
are: [xmin, xmax, ymin, ymax, list_overlapping_FOVs, selected_well]
.
PARAMETER | DESCRIPTION |
---|---|
site_metadata |
TBD
TYPE:
|
tol |
TBD
TYPE:
|
plotting_function |
TBD |
Source code in fractal_tasks_core/roi/v1_overlaps.py
362 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 |
|