oxytcmri.domain.use_cases.segment_dti_abnormal_values
¶
This module segments the abnormal values in DTI images using the normative values computed in each center from healthy subjects.
Classes:
| Name | Description |
|---|---|
DTIThresholds |
Encapsulates thresholds for detecting abnormal DTI values. |
ThresholdStrategy |
Strategy interface for computing thresholds for abnormal DTI values. |
QuantileThresholdStrategy |
A strategy that computes thresholds based on quantiles of normative values. |
MeanThresholdStrategy |
A strategy that computes thresholds based on the mean and standard deviation of normative values. |
InterQuartileRangeThresholdStrategy |
A strategy that computes thresholds based on the interquartile range (IQR) of normative values. |
SegmentationMerger |
Abstract interface for merging MRI segmentations. |
SegmentDTIAbnormalValues |
Segment abnormal values in DTI images compared to normative values (computed in each center from healthy subjects). |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
logger = logging.getLogger(__name__)
module-attribute
¶
DTIThresholds(high_threshold, low_threshold)
dataclass
¶
Encapsulates thresholds for detecting abnormal DTI values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
high_threshold
|
float
|
The upper threshold - values above this are considered abnormally high. If None, threshold will be set to inf. |
required |
low_threshold
|
float
|
The lower threshold - values below this are considered abnormally low. If None, threshold will be set to -inf. |
required |
Methods:
| Name | Description |
|---|---|
get_abnormality_type |
Determine if a value is abnormal and return the type of abnormality. |
Attributes:
| Name | Type | Description |
|---|---|---|
high_threshold |
Optional[float]
|
|
low_threshold |
Optional[float]
|
|
high_threshold
instance-attribute
¶
low_threshold
instance-attribute
¶
get_abnormality_type(value)
¶
Determine if a value is abnormal and return the type of abnormality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
float
|
The DTI value to check |
required |
Returns:
| Type | Description |
|---|---|
Optional[AbnormalValueType]
|
The type of abnormality (HIGH or LOW), or None if normal |
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
ThresholdStrategy(normative_value_repository, center_repository)
¶
Bases: ABC
Strategy interface for computing thresholds for abnormal DTI values.
Initialize the strategy with a normative value repository and center.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normative_value_repository
|
NormativeValueRepository
|
The repository to fetch normative values |
required |
center_repository
|
CenterRepository
|
The repository to fetch center information |
required |
Methods:
| Name | Description |
|---|---|
compute_thresholds |
Compute thresholds for a specific DTI metric, atlas, and label. |
Attributes:
| Name | Type | Description |
|---|---|---|
normative_value_repository |
|
|
center_repository |
|
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
normative_value_repository = normative_value_repository
instance-attribute
¶
center_repository = center_repository
instance-attribute
¶
compute_thresholds(dti_image, atlas, atlas_label)
abstractmethod
¶
Compute thresholds for a specific DTI metric, atlas, and label.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dti_image
|
DTIMap
|
The DTI map for which to compute thresholds |
required |
atlas
|
Atlas
|
The atlas used for segmentation |
required |
atlas_label
|
int
|
The specific atlas label for which to compute thresholds |
required |
Returns:
| Type | Description |
|---|---|
DTIThresholds
|
Computed thresholds for the given parameters |
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
QuantileThresholdStrategy(normative_value_repository, center_repository, high_quantile=95, low_quantile=5)
¶
Bases: ThresholdStrategy
A strategy that computes thresholds based on quantiles of normative values.
Initialize with quantiles for threshold computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normative_value_repository
|
NormativeValueRepository
|
The repository to fetch normative values |
required |
center_repository
|
CenterRepository
|
The repository to fetch center information |
required |
high_quantile
|
int
|
The quantile for the high threshold |
95
|
low_quantile
|
int
|
The quantile for the low threshold |
5
|
Methods:
| Name | Description |
|---|---|
compute_thresholds |
Compute thresholds based on quantiles of normative values. |
Attributes:
| Name | Type | Description |
|---|---|---|
high_quantile |
|
|
low_quantile |
|
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | |
high_quantile = high_quantile
instance-attribute
¶
low_quantile = low_quantile
instance-attribute
¶
compute_thresholds(dti_image, atlas, atlas_label)
¶
Compute thresholds based on quantiles of normative values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dti_image
|
DTIMap
|
The DTI map for which to compute thresholds |
required |
atlas
|
Atlas
|
The atlas used for segmentation |
required |
atlas_label
|
int
|
The specific atlas label for which to compute thresholds |
required |
Returns:
| Type | Description |
|---|---|
DTIThresholds
|
Computed thresholds for the given parameters |
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.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 | |
MeanThresholdStrategy(normative_value_repository, center_repository, high_deviation_factor=2.0, low_deviation_factor=2.0)
¶
Bases: ThresholdStrategy
A strategy that computes thresholds based on the mean and standard deviation of normative values.
This is a dummy implementation for development and testing. In a real application, the computation would depend on the DTI metric and atlas.
Initialize with a z-score for threshold computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normative_value_repository
|
NormativeValueRepository
|
The repository to fetch normative values |
required |
center_repository
|
CenterRepository
|
The repository to fetch center information |
required |
high_deviation_factor
|
float
|
The factor to multiply the standard deviation for high threshold |
2.0
|
low_deviation_factor
|
float
|
The factor to multiply the standard deviation for low threshold |
2.0
|
Methods:
| Name | Description |
|---|---|
compute_thresholds |
Compute thresholds based on the mean and standard deviation of normative values. |
Attributes:
| Name | Type | Description |
|---|---|---|
high_deviation_factor |
|
|
low_deviation_factor |
|
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
high_deviation_factor = high_deviation_factor
instance-attribute
¶
low_deviation_factor = low_deviation_factor
instance-attribute
¶
compute_thresholds(dti_image, atlas, atlas_label)
¶
Compute thresholds based on the mean and standard deviation of normative values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dti_image
|
DTIMap
|
The DTI map for which to compute thresholds |
required |
atlas
|
Atlas
|
The atlas used for segmentation |
required |
atlas_label
|
int
|
The specific atlas label for which to compute thresholds |
required |
Returns:
| Type | Description |
|---|---|
DTIThresholds
|
Computed thresholds for the given parameters |
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.py
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 | |
InterQuartileRangeThresholdStrategy(normative_value_repository, center_repository, high_deviation_factor=2.0, low_deviation_factor=2.0)
¶
Bases: ThresholdStrategy
A strategy that computes thresholds based on the interquartile range (IQR) of normative values.
Initialize with a z-score for threshold computation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normative_value_repository
|
NormativeValueRepository
|
The repository to fetch normative values |
required |
center_repository
|
CenterRepository
|
The repository to fetch center information |
required |
high_deviation_factor
|
float
|
The factor to multiply the interquartile range for high threshold |
2.0
|
low_deviation_factor
|
float
|
The factor to multiply the interquartile range for low threshold |
2.0
|
Methods:
| Name | Description |
|---|---|
compute_thresholds |
Compute thresholds based on the interquartile range of normative values. |
Attributes:
| Name | Type | Description |
|---|---|---|
high_deviation_factor |
|
|
low_deviation_factor |
|
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
high_deviation_factor = high_deviation_factor
instance-attribute
¶
low_deviation_factor = low_deviation_factor
instance-attribute
¶
compute_thresholds(dti_image, atlas, atlas_label)
¶
Compute thresholds based on the interquartile range of normative values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dti_image
|
DTIMap
|
The DTI map for which to compute thresholds |
required |
atlas
|
Atlas
|
The atlas used for segmentation |
required |
atlas_label
|
int
|
The specific atlas label for which to compute thresholds |
required |
Returns:
| Type | Description |
|---|---|
DTIThresholds
|
Computed thresholds for the given parameters |
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.py
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 | |
SegmentationMerger
¶
Bases: ABC
Abstract interface for merging MRI segmentations. This interface respects the dependency inversion principle.
Methods:
| Name | Description |
|---|---|
merge |
Merges multiple segmentations into a single one. |
merge(segmentations)
abstractmethod
¶
Merges multiple segmentations into a single one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segmentations
|
List[DTIAbnormalValues]
|
List of segmentations to merge. |
required |
Returns:
| Type | Description |
|---|---|
DTIAbnormalValues
|
The merged segmentation. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the segmentations cannot be merged. |
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.py
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 | |
SegmentDTIAbnormalValues(repositories_registry, threshold_strategy=None, segmentation_merger=None, dispatcher=None)
¶
Segment abnormal values in DTI images compared to normative values (computed in each center from healthy subjects).
Initializes the SegmentDtiAbnormalValues use-case.
Methods:
| Name | Description |
|---|---|
initialize_progress_bar |
Initialize the progress bar with the total number of steps. |
update_progress_bar |
Update the progress bar by incrementing the current step and dispatching a progress event. |
segment_all_mri_exams_of_patients |
Segments all the MRI exams of all patients. |
segment_dti_maps_associated_to_mri_exam |
Segments the DTI maps associated with a given MRI exam. |
segment_dti_map |
Segments the DTI map, i.e. build a map with values indicating the abnormal values in the input DTI map. |
segment_dti_map_for_atlas |
Segments the DTI map for a given atlas, using the normative values. |
merge_segmentations |
Merges the segmentations into a single MRIData object. |
compute_thresholds |
Compute thresholds for abnormal values detection. |
mark_abnormal_voxels |
Mark voxels with abnormal values in the specified atlas region. |
Attributes:
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.py
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 | |
subjects_repository = repositories_registry.get_repository(Subject)
instance-attribute
¶
mri_repository = repositories_registry.get_repository(MRIExam)
instance-attribute
¶
atlas_repository = repositories_registry.get_repository(Atlas)
instance-attribute
¶
centers_repository = repositories_registry.get_repository(Center)
instance-attribute
¶
normative_values_repository = repositories_registry.get_repository(NormativeValue)
instance-attribute
¶
dispatcher = dispatcher
instance-attribute
¶
threshold_strategy = threshold_strategy or default_threshold_strategy
instance-attribute
¶
segmentation_merger = segmentation_merger
instance-attribute
¶
current_step = None
instance-attribute
¶
total_steps = None
instance-attribute
¶
initialize_progress_bar(total_steps)
¶
Initialize the progress bar with the total number of steps.
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.py
483 484 485 486 487 488 489 490 491 | |
update_progress_bar()
¶
Update the progress bar by incrementing the current step and dispatching a progress event.
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.py
493 494 495 496 497 498 499 | |
segment_all_mri_exams_of_patients(dti_metrics)
¶
Segments all the MRI exams of all patients.
It will look for all the patients in the SubjectRepository and for each patient, it will segment the DTI images. This segmentation process will have access to the normative values stored in the NormativeValuesRepository.
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 | |
segment_dti_maps_associated_to_mri_exam(mri_exam, dti_metrics)
¶
Segments the DTI maps associated with a given MRI exam. This method will look for all the DTI maps associated with the MRI exam and segment them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dti_metrics
|
List[DTIMetric]
|
The DTI metrics to segment. |
required |
mri_exam
|
MRIExam
|
The MRI exam to segment the DTI maps for. |
required |
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.py
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 | |
segment_dti_map(dti_image)
¶
Segments the DTI map, i.e. build a map with values indicating the abnormal values in the input DTI map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dti_image
|
DTIMap
|
The DTI map to segment. |
required |
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.py
576 577 578 579 580 581 582 583 584 585 586 587 588 589 | |
segment_dti_map_for_atlas(dti_image, atlas)
¶
Segments the DTI map for a given atlas, using the normative values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dti_image
|
DTIMap
|
The DTI map to segment. |
required |
atlas
|
Atlas
|
The atlas to use for segmentation. |
required |
Returns:
| Type | Description |
|---|---|
DTIAbnormalValues
|
The segmented DTI map with abnormal values. |
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.py
591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 | |
merge_segmentations(segmentations)
¶
Merges the segmentations into a single MRIData object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segmentations
|
List[DTIAbnormalValues]
|
The list of segmentations to merge. |
required |
Returns:
| Type | Description |
|---|---|
DTIAbnormalValues
|
The merged segmentation. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the segmentation merger is not set. |
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.py
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 | |
compute_thresholds(dti_image, atlas, atlas_label)
¶
Compute thresholds for abnormal values detection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dti_image
|
DTIMap
|
The DTI map image to compute thresholds for |
required |
atlas
|
Atlas
|
The atlas used for segmentation |
required |
atlas_label
|
int
|
The atlas label to compute thresholds for |
required |
Returns:
| Type | Description |
|---|---|
DTIThresholds
|
Thresholds for detecting abnormal values |
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.py
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 | |
mark_abnormal_voxels(dti_image, atlas, atlas_label, thresholds, result)
¶
Mark voxels with abnormal values in the specified atlas region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dti_image
|
DTIMap
|
The DTI map image to analyze |
required |
atlas
|
Atlas
|
The atlas used for segmentation |
required |
atlas_label
|
int
|
The atlas label defining the region to analyze |
required |
thresholds
|
DTIThresholds
|
Thresholds for detecting abnormal values |
required |
result
|
DTIAbnormalValues
|
The result object where abnormal voxels will be marked |
required |
Source code in oxytcmri/domain/use_cases/segment_dti_abnormal_values.py
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 | |