POI — Points of Interest¶
POI maps (vertebra_id, subregion_id) tuples to 3D coordinates and
provides save/load, coordinate-space conversion, and iteration helpers.
POI¶
TPTBox.core.poi.POI
dataclass
¶
Bases: Abstract_POI, Has_Grid
This class represents a collection of POIs used to define points of interest in medical imaging data.
Attributes:
| Name | Type | Description |
|---|---|---|
orientation |
Ax_Codes
|
A tuple of three string values representing the orientation of the image. |
centroids |
dict
|
A dictionary of POI points, where the keys are the labels for the POI points, and values are tuples of three float values representing the x, y, and z coordinates of the POI. |
zoom |
Zooms | None
|
A tuple of three float values representing the zoom level of the image. Defaults to None if not provided. |
shape |
tuple[float, float, float] | None
|
A tuple of three integer values representing the shape of the image. Defaults to None if not provided. |
format |
int | None
|
An integer value representing the format of the image. Defaults to None if not provided. |
info |
dict
|
Additional information stored as key-value pairs. Defaults to an empty dictionary. |
rotation |
Rotation | None
|
A 3x3 numpy array representing the rotation matrix for the image orientation. Defaults to None if not provided. |
origin |
Coordinate | None
|
A tuple of three float values representing the origin of the image in millimeters along the x, y, and z axes. Defaults to None if not provided. |
Properties
is_global (bool): Property indicating whether the POI is a global POI. Always returns False. zoom (Zooms | None): Property getter for the zoom level. affine: Property representing the affine transformation for the image.
Examples:
>>> # Create a POI object with 2D dictionary input
>>> from BIDS.core.poi import POI
>>> poi_data = {
... (1, 0): (10.0, 20.0, 30.0),
... (2, 1): (15.0, 25.0, 35.0),
... }
>>> poi_obj = POI(centroids=poi_data, orientation=("R", "A", "S"), zoom=(1.0, 1.0, 1.0), shape=(256, 256, 100))
>>> # Access attributes
>>> print(poi_obj.orientation)
('R', 'A', 'S')
>>> print(poi_obj.centroids)
{1: {0: (10.0, 20.0, 30.0)}, 2: {1: (15.0, 25.0, 35.0)}}
>>> print(poi_obj.zoom)
(1.0, 1.0, 1.0)
>>> print(poi_obj.shape)
(256, 256, 100)
>>> # Update attributes
>>> poi_obj.rescale_((2.0, 2.0, 2.0))
>>> poi_obj.centroids[(3, 0)] = (5.0, 15.0, 25.0)
>>> print(poi_obj)
POI(centroids={1: {0: (5.0, 10.0, 15.0)}, 2: {1: (7.5, 12.5, 17.5)}, 3: {0: (5.0, 15.0, 25.0)}}, orientation=('R', 'A', 'S'), zoom=(2.0, 2.0, 2.0), info={}, origin=None)
>>> # Perform operations
>>> poi_obj = poi_obj.map_labels({(1): (4), (2): (4)})
>>> poi_obj.round_(0)
>>> print(poi_obj)
POI(centroids={4: {0: (5.0, 10.0, 15.0), 1: (8.0, 12.0, 18.0)}, 3: {0: (5.0, 15.0, 25.0)}}, orientation=('R', 'A', 'S'), zoom=(2.0, 2.0, 2.0), info={}, origin=None)
Source code in TPTBox/core/poi.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 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 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 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 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 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 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 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 516 517 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 583 584 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 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 | |
is_global
property
¶
Always False for voxel-space POIs; True only for POI_Global objects.
rotation
property
writable
¶
3×3 rotation matrix of the image grid, or None if not set.
clone
¶
copy
¶
copy(centroids: POI_DICT | POI_Descriptor | None = None, orientation: AX_CODES | None = None, zoom: ZOOMS | Sentinel = Sentinel(), shape: TRIPLE | tuple[float, ...] | Sentinel = Sentinel(), rotation: ROTATION | Sentinel = Sentinel(), origin: COORDINATE | Sentinel = Sentinel()) -> Self
Create a copy of the POI object with optional attribute overrides.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
centroids
|
POI_Dict | POI_Descriptor | None
|
The POIs to use in the copied object. Defaults to None, in which case the original POIs will be used. |
None
|
orientation
|
Ax_Codes | None
|
The orientation code to use in the copied object. Defaults to None, in which case the original orientation will be used. |
None
|
zoom
|
Zooms | None | Sentinel
|
The zoom values to use in the copied object. Defaults to Sentinel(), in which case the original zoom values will be used. |
Sentinel()
|
shape
|
tuple[float, float, float] | None | Sentinel
|
The shape values to use in the copied object. Defaults to Sentinel(), in which case the original shape values will be used. |
Sentinel()
|
rotation
|
Rotation | None | Sentinel
|
The rotation matrix to use in the copied object. Defaults to Sentinel(), in which case the original rotation matrix will be used. |
Sentinel()
|
origin
|
Coordinate | None | Sentinel
|
The origin coordinates to use in the copied object. Defaults to Sentinel(), in which case the original origin coordinates will be used. |
Sentinel()
|
Returns:
| Name | Type | Description |
|---|---|---|
POI |
Self
|
A new POI object with the specified attribute overrides. |
Examples:
>>> POI_obj = POI(...)
>>> POI_obj_copy = POI_obj.copy(zoom=(2.0, 2.0, 2.0), rotation=rotation_matrix)
Source code in TPTBox/core/poi.py
local_to_global
¶
Converts local coordinates to global coordinates using zoom, rotation, and origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Coordinate | list[float]
|
The local coordinate(s) to convert. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Coordinate |
COORDINATE
|
The converted global coordinate(s). |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the attributes 'zoom', 'rotation', or 'origin' are missing. |
Notes
The 'zoom' and 'rotation' attributes should be set before calling this method.
Examples:
>>> POI_obj = Centroids(...)
>>> POI_obj.zoom = (2.0, 2.0, 2.0)
>>> POI_obj.rotation = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
>>> POI_obj.origin = (10.0, 20.0, 30.0)
>>> local_coordinate = (1.0, 2.0, 3.0)
>>> global_coordinate = POI_obj.local_to_global(local_coordinate)
Source code in TPTBox/core/poi.py
global_to_local
¶
Converts global coordinates to local coordinates using zoom, rotation, and origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Coordinate | list[float]
|
The global coordinate(s) to convert. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Coordinate |
COORDINATE
|
The converted local coordinate(s). |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the attributes 'zoom', 'rotation', or 'origin' are missing. |
Notes
The 'zoom' and 'rotation' attributes should be set before calling this method.
Examples:
>>> POI_obj = Centroids(...)
>>> POI_obj.zoom = (2.0, 2.0, 2.0)
>>> POI_obj.rotation = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
>>> POI_obj.origin = (10.0, 20.0, 30.0)
>>> global_coordinate = (20.0, 30.0, 40.0)
>>> local_coordinate = POI_obj.global_to_local(global_coordinate)
Source code in TPTBox/core/poi.py
apply_crop_reverse
¶
apply_crop_reverse(o_shift: tuple[slice, slice, slice] | Sequence[slice], shape: tuple[int, int, int] | Sequence[int], inplace=False) -> Self
A Poi crop can be trivially reversed with out any loss. See apply_crop for more information.
Source code in TPTBox/core/poi.py
apply_crop
¶
Adjust POI coordinates after a crop operation by shifting the origin.
Points outside the cropped frame are NOT removed.
See :meth:~TPTBox.NII.compute_crop_slice.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
o_shift
|
tuple[slice, slice, slice]
|
translation of the origin, cause by the crop |
required |
inplace
|
bool
|
inplace. Defaults to True. |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
Self |
Source code in TPTBox/core/poi.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 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 | |
apply_crop_
¶
shift_all_coordinates
¶
shift_all_coordinates(translation_vector: tuple[slice, slice, slice] | Sequence[slice] | None, inplace=True, **kwargs) -> Self
Shift all POI coordinates by a translation expressed as crop slices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
translation_vector
|
tuple[slice, slice, slice] | Sequence[slice] | None
|
Per-axis slices encoding the origin shift, or |
required |
inplace
|
bool
|
Whether to modify in place. Defaults to True. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
Self |
Self
|
The updated POI (same object when |
Source code in TPTBox/core/poi.py
reorient
¶
reorient(axcodes_to: AX_CODES = ('P', 'I', 'R'), decimals=ROUNDING_LVL, verbose: logging = False, inplace=False, _shape=None) -> Self
Reorients the POIs of an image from the current orientation to the specified orientation.
This method updates the position of the POIs, zoom level, and shape of the image accordingly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axcodes_to
|
Ax_Codes
|
An Ax_Codes object representing the desired orientation of the POIs. Defaults to ("P", "I", "R"). |
('P', 'I', 'R')
|
decimals
|
int
|
Number of decimal places to round the coordinates of the POIs after reorientation. Defaults to ROUNDING_LVL. |
ROUNDING_LVL
|
verbose
|
bool
|
If True, print a message indicating the current and new orientation of the POIs. Defaults to False. |
False
|
inplace
|
bool
|
If True, update the current POIs object with the reoriented values. If False, return a new POI object with reoriented values. Defaults to False. |
False
|
_shape
|
tuple[int] | None
|
The shape of the image. Required if the shape is not already present in the POI object. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
POI |
Self
|
If inplace is True, returns the updated POI object. If inplace is False, returns a new POI object with reoriented values. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the given _shape is not compatible with the shape already present in the POI object. |
AssertionError
|
If shape is not provided (either in the POI object or as _shape argument). |
Examples:
>>> poi_obj = POI(...)
>>> new_orientation = ("A", "P", "L") # Desired orientation for reorientation
>>> new_poi_obj = poi_obj.reorient(axcodes_to=new_orientation, decimals=4, inplace=False)
Source code in TPTBox/core/poi.py
415 416 417 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 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 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 | |
reorient_
¶
reorient_(axcodes_to: AX_CODES = ('P', 'I', 'R'), decimals=3, verbose: logging = False, _shape=None) -> Self
In-place variant of :meth:reorient.
Source code in TPTBox/core/poi.py
rescale
¶
rescale(voxel_spacing: ZOOMS = (1, 1, 1), decimals=ROUNDING_LVL, verbose: logging = True, inplace=False) -> Self
Rescale the POI coordinates to a new voxel spacing in the current x-y-z-orientation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
voxel_spacing
|
tuple[float, float, float]
|
New voxel spacing in millimeters. Defaults to (1, 1, 1). |
(1, 1, 1)
|
decimals
|
int
|
Number of decimal places to round the rescaled coordinates to. Defaults to ROUNDING_LVL. |
ROUNDING_LVL
|
verbose
|
bool
|
Whether to print a message indicating that the POI coordinates have been rescaled. Defaults to True. |
True
|
inplace
|
bool
|
Whether to modify the current instance or return a new instance. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
POI |
Self
|
If inplace=True, returns the modified POI instance. Otherwise, returns a new POI instance with rescaled POI coordinates. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the 'zoom' attribute is not set in the Centroids instance. |
Examples:
>>> POI_obj = POI(...)
>>> new_voxel_spacing = (2.0, 2.0, 2.0) # Desired voxel spacing for rescaling
>>> rescaled_POI_obj = POI_obj.rescale(voxel_spacing=new_voxel_spacing, decimals=4, inplace=False)
Source code in TPTBox/core/poi.py
rescale_
¶
In-place variant of :meth:rescale.
to_global
¶
Converts the Centroids object to a global POI_Global object.
This method converts the local POI coordinates to global coordinates using the Centroids' zoom, rotation, and origin attributes and returns a new POI_Global object.
Returns:
| Name | Type | Description |
|---|---|---|
POI_Global |
POI_Global
|
A new POI_Global object with the converted global POI coordinates. |
Examples:
Source code in TPTBox/core/poi.py
resample_from_to
¶
Resample this POI to the grid of another image by converting to global and back.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ref
|
Has_Grid
|
Target image grid (any object providing affine/orientation info). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
POI |
POI
|
A new POI in the voxel space of |
Source code in TPTBox/core/poi.py
resample_from_to_
¶
save
¶
save(out_path: Path | str, make_parents=False, additional_info: dict | None = None, save_hint=2, resample_reference: Has_Grid | None = None, verbose: logging = True) -> None
Saves the POIs to a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out_path
|
Path | str
|
The path where the JSON file will be saved. |
required |
make_parents
|
bool
|
If True, create any necessary parent directories for the output file. Defaults to False. |
False
|
verbose
|
bool
|
If True, print status messages to the console. Defaults to True. |
True
|
save_hint
|
0 Default, 1 Gruber, 2 POI (readable), 10 ISO-POI (outdated) |
2
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
TypeError
|
If any of the POIs have an invalid type. |
Example
POIs = Centroids(...) POIs.save("output/POIs.json")
Source code in TPTBox/core/poi.py
make_point_cloud_nii
¶
Create point cloud NIfTI images from the POI coordinates.
This method generates two NIfTI images, one for the regions and another for the subregions, representing the point cloud with a specified neighborhood size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
affine
|
ndarray
|
The affine transformation matrix for the NIfTI image. Defaults to None. If None, the POI object's affine will be used. |
None
|
s
|
int
|
The neighborhood size. Defaults to 8. |
8
|
Returns:
| Type | Description |
|---|---|
tuple[NII, NII]
|
tuple[NII, NII]: A tuple containing two NII objects representing the point cloud for regions and subregions. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the 'shape' or 'zoom' attributes are not set in the Centroids instance. |
Examples:
>>> POI_obj = Centroids(...)
>>> neighborhood_size = 10
>>> region_cloud, subregion_cloud = POI_obj.make_point_cloud_nii(s=neighborhood_size)
Source code in TPTBox/core/poi.py
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 | |
filter_points_inside_shape
¶
Filter out POI points that are outside the defined shape.
This method checks each POI point and removes any point whose coordinates are outside the defined shape.
Returns:
| Name | Type | Description |
|---|---|---|
POI |
Self
|
A new POI object containing POI points that are inside the defined shape. |
Examples:
Source code in TPTBox/core/poi.py
load
classmethod
¶
Load a Centroids object from various input sources.
This method provides a convenient way to load a Centroids object from different sources, including BIDS files, file paths, image references, or existing POI objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poi
|
Centroid_Reference
|
The input source from which to load the Centroids object. It can be one of the following types: - BIDS_FILE: A BIDS file representing the Centroids object. - Path: The path to the file containing the Centroids object. - str: The string representation of the Centroids object file path. - Tuple[Image_Reference, Image_Reference, list[int]]: A tuple containing two Image_Reference objects and a list of integers representing the POI data. - POI: An existing POI object to be loaded. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
POI |
POI
|
The loaded Centroids object. |
Examples:
>>> # Load from a BIDS file
>>> bids_file_path = BIDS_FILE("/path/to/POIs.json", "/path/to/dataset/")
>>> loaded_poi = POI.load(bids_file_path)
>>> # Load from a file path
>>> file_path = "/path/to/POIs.json"
>>> loaded_poi = POI.load(file_path)
>>> # Load from an image reference tuple and POI data
>>> image_ref1 = Image_Reference(...)
>>> image_ref2 = Image_Reference(...)
>>> POI_data = [1, 2, 3]
>>> loaded_poi = POI.load((image_ref1, image_ref2, POI_data))
>>> # Load from an existing POI object
>>> existing_poi = POI(...)
>>> loaded_poi = POI.load(existing_poi)
Source code in TPTBox/core/poi.py
POI_Global¶
TPTBox.core.poi_fun.poi_global.POI_Global
¶
Bases: Abstract_POI
POI container stored in world (mm) coordinates rather than voxel space.
Extends :class:~TPTBox.core.poi_fun.poi_abstract.Abstract_POI with coordinate-system
conversion methods.
Source code in TPTBox/core/poi_fun/poi_global.py
18 19 20 21 22 23 24 25 26 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 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 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 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 301 302 303 304 305 306 | |
zoom
property
¶
Always returns (1, 1, 1) — global POIs are in mm so zoom is unity.
origin
property
¶
Always returns (0, 0, 0) — global POIs use a world origin.
orientation
property
¶
Return the axis-code orientation for the active coordinate system.
Returns:
| Type | Description |
|---|---|
str
|
|
str
|
for NIfTI/RAS coordinates. |
is_global
property
¶
Check if the POI is global.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the POI is global, False otherwise. |
to_other_nii
¶
Convert the POI to another NII file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ref
|
Image_Reference
|
The reference to the NII file. |
required |
Returns:
| Type | Description |
|---|---|
POI | NII
|
Union[poi.POI, poi.NII]: The converted POI as either a POI or NII object. |
Source code in TPTBox/core/poi_fun/poi_global.py
to_other_poi
¶
Convert the POI to another POI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ref
|
Centroid_Reference
|
The reference to the other POI. |
required |
Returns:
| Type | Description |
|---|---|
POI | Self | None
|
poi.POI: The converted POI. |
Source code in TPTBox/core/poi_fun/poi_global.py
to_global
¶
Return this object unchanged (already in global coordinates).
to_local
¶
Convert this global POI to the voxel space of msk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msk
|
Has_Grid
|
Reference grid ( |
required |
Returns:
| Type | Description |
|---|---|
POI
|
|
Source code in TPTBox/core/poi_fun/poi_global.py
resample_from_to
¶
Alias for :meth:to_local / :meth:to_other.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msk
|
Has_Grid
|
Reference grid defining the target affine. |
required |
Returns:
| Type | Description |
|---|---|
POI
|
|
Source code in TPTBox/core/poi_fun/poi_global.py
to_cord_system
¶
Convert between ITK (LPS) and NIfTI (RAS) coordinate systems.
Flips the first two coordinate axes when switching between the two systems (LPS ↔ RAS only differs in the sign of x and y).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
itk_coords
|
bool
|
|
required |
inplace
|
bool
|
Convert in place. Defaults to |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
|
Source code in TPTBox/core/poi_fun/poi_global.py
to_other
¶
Convert the POI to another coordinate system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msk
|
Union[POI, NII]
|
The reference to the other coordinate system. |
required |
Returns:
| Type | Description |
|---|---|
POI
|
poi.POI: The converted POI. |
Source code in TPTBox/core/poi_fun/poi_global.py
copy
¶
Return a deep copy of this POI_Global.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
centroids
|
POI_Descriptor | None
|
Optional replacement |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
New |
Source code in TPTBox/core/poi_fun/poi_global.py
load
classmethod
¶
Load a POI_Global from a file or POI reference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poi
|
POI_Reference
|
Path to a JSON or |
required |
itk_coords
|
bool | None
|
When |
None
|
Returns:
| Type | Description |
|---|---|
Self
|
|
Raises:
| Type | Description |
|---|---|
AssertionError
|
If |
Source code in TPTBox/core/poi_fun/poi_global.py
save
¶
save(out_path: str | Path, make_parents: bool = False, additional_info: dict | None = None, save_hint: int = FORMAT_GLOBAL, resample_reference: Has_Grid | None = None, verbose: logging = True) -> None
Save this POI_Global to a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out_path
|
str | Path
|
Output path (must end with |
required |
make_parents
|
bool
|
Create parent directories if missing.
Defaults to |
False
|
additional_info
|
dict | None
|
Extra key-value pairs added to the file header. |
None
|
save_hint
|
int
|
Format identifier. Defaults to |
FORMAT_GLOBAL
|
resample_reference
|
Has_Grid | None
|
When set, convert to local coordinates of this grid before saving. |
None
|
verbose
|
logging
|
Emit a save log message. Defaults to |
True
|
Source code in TPTBox/core/poi_fun/poi_global.py
save_mrk
¶
save_mrk(filepath: str | Path, color: list[float] | None = None, split_by_region: bool = False, split_by_subregion: bool = False, add_points: bool = True, add_lines: list[MKR_Lines] | None = None, display: MKR_Display | dict = None, pointLabelsVisibility: bool = False, glyphScale: float = 5.0, main_key: str = 'Point') -> None
Save this POI_Global as a 3D Slicer .mrk.json markup file.
Delegates to :func:~TPTBox.core.poi_fun.save_mkr._save_mrk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str | Path
|
Output path. The extension is forced to |
required |
color
|
list[float] | None
|
Default group colour (RGB in |
None
|
split_by_region
|
bool
|
Separate markup group per region.
Defaults to |
False
|
split_by_subregion
|
bool
|
Separate markup group per subregion.
Defaults to |
False
|
add_points
|
bool
|
Include Fiducial markups. Defaults to |
True
|
add_lines
|
list[MKR_Lines] | None
|
Optional |
None
|
display
|
MKR_Display | dict
|
Base display property overrides. |
None
|
pointLabelsVisibility
|
bool
|
Show point labels in the 3D view.
Defaults to |
False
|
glyphScale
|
float
|
Glyph size factor. Defaults to |
5.0
|
main_key
|
str
|
Base markup group key. Defaults to |
'Point'
|
Source code in TPTBox/core/poi_fun/poi_global.py
Helper functions¶
TPTBox.core.poi
¶
calc_centroids
¶
calc_centroids(msk: Image_Reference, decimals=3, first_stage: int | Abstract_lvl = -1, second_stage: int | Abstract_lvl = 50, extend_to: POI | None = None, inplace: bool = False, bar=False, _crop=True) -> POI
Calculates the centroid coordinates of each region in the given mask image.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msk
|
Image_Reference
|
An |
required |
decimals
|
int
|
An optional integer specifying the number of decimal places to round the centroid coordinates to (default is 3). |
3
|
vert_id
|
int
|
An optional integer specifying the fixed vertical dimension for the centroids (default is -1). |
required |
subreg_id
|
int
|
An optional integer specifying the fixed subregion dimension for the centroids (default is 50). |
required |
extend_to
|
POI
|
An optional |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
POI |
POI
|
A |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the |
Notes
- The function calculates the centroid coordinates of each region in the mask image.
- The centroid coordinates are rounded to the specified number of decimal places.
- The fixed dimensions for the centroids can be specified using
vert_idandsubreg_id. - If
extend_tois provided, the calculated centroids will be added to the existing object and the updated object will be returned. - The region label is assumed to be an integer.
- NaN values in the binary mask are ignored.
Source code in TPTBox/core/poi.py
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 | |
calc_poi_from_subreg_vert
¶
calc_poi_from_subreg_vert(vert: Image_Reference, subreg: Image_Reference, *, buffer_file: str | Path | None = None, save_buffer_file=False, decimals=2, subreg_id: int | Abstract_lvl | Sequence[int | Abstract_lvl] | Sequence[Abstract_lvl] | Sequence[int] = 50, verbose: logging = False, extend_to: POI | None = None, _vert_ids: list[int] | None = None, _print_phases=False, _orientation_version=0) -> POI
Calculates the POIs of a subregion within a vertebral mask. This function is spine opinionated, the general implementation is "calc_poi_from_two_masks".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vert_msk
|
Image_Reference
|
A vertebral mask image reference. |
required |
subreg
|
Image_Reference
|
An image reference for the subregion of interest. |
required |
decimals
|
int
|
Number of decimal places to round the output coordinates to. Defaults to 1. |
2
|
subreg_id
|
int | Location | list[int | Location]
|
The ID(s) of the subregion(s) to calculate POIs for. Defaults to 50. |
50
|
axcodes_to
|
Ax_Codes | None
|
A tuple of axis codes indicating the target orientation of the images. Defaults to None. |
required |
verbose
|
bool
|
Whether to print progress messages. Defaults to False. |
False
|
fixed_offset
|
int
|
A fixed offset value to add to the calculated POI coordinates. Defaults to 0. |
required |
extend_to
|
POI | None
|
An existing POI object to extend with the new POI values. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
POI |
POI
|
A POI object containing the calculated POI coordinates. |
Source code in TPTBox/core/poi.py
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 | |
calc_poi_from_two_segs
¶
calc_poi_from_two_segs(msk_reference: Image_Reference, subreg_reference: Image_Reference | None, out_path: Path | str, subreg_id: int | Abstract_lvl | Sequence[int | Abstract_lvl] | None = None, verbose=True, override=False, decimals=3, check_every_point=True) -> POI
Compute centroids of a mask within each subregion and optionally save/load from file.
If out_path is None and msk_reference is a :class:~TPTBox.BIDS_FILE, a path is
generated automatically from its label attribute and subreg_id.
If subreg_reference is None, the function computes the centroids using only msk_reference.
If subreg_reference is not None, the function computes the centroids with respect to the given subreg_id in the
subregion defined by subreg_reference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msk_reference
|
Image_Reference
|
The mask to compute the centroids from. |
required |
subreg_reference
|
Image_Reference | None
|
The subregion mask to compute the centroids relative to. |
required |
out_path
|
Path | None
|
The path to save the computed centroids to. |
required |
subreg_id
|
int | Location | list[int | Location]
|
The ID of the subregion to compute centroids in. |
None
|
verbose
|
bool
|
Whether to print verbose output during the computation. |
True
|
override
|
bool
|
Whether to overwrite any existing centroids file at |
False
|
decimals
|
int
|
The number of decimal places to round the computed centroid coordinates to. |
3
|
additional_folder
|
bool
|
Whether to add a |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Centroids |
POI
|
The computed centroids, as a |
Source code in TPTBox/core/poi.py
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 | |