oxytcmri.interface.mri.staple_segmenter
¶
Concrete implementation of SegmentationMerger using c3d command line tool with STAPLE algorithm.
Classes:
| Name | Description |
|---|---|
TemporaryFilesHandler |
Handler for temporary NIfTI files used during segmentation merging. |
C3DSTAPLESegmentationMerger |
Implementation of SegmentationMerger using c3d-tools STAPLE algorithm. |
Attributes:
| Name | Type | Description |
|---|---|---|
logger |
|
logger = logging.getLogger(__name__)
module-attribute
¶
TemporaryFilesHandler()
¶
Handler for temporary NIfTI files used during segmentation merging.
This class provides utilities for creating temporary files and ensuring they are properly cleaned up when no longer needed.
Initialize an empty list to track temporary files.
Methods:
| Name | Description |
|---|---|
create_temp_nifti_file |
Create a temporary NIfTI file for storing segmentation data. |
clean_up_temporary_files |
Remove all temporary files created by this handler. |
Attributes:
| Name | Type | Description |
|---|---|---|
temp_files |
List[Path]
|
|
Source code in oxytcmri/interface/mri/staple_segmenter.py
27 28 29 30 31 | |
temp_files = []
instance-attribute
¶
create_temp_nifti_file()
¶
Create a temporary NIfTI file for storing segmentation data.
The file path is tracked for later cleanup.
Returns:
| Type | Description |
|---|---|
Path
|
Path to the temporary NIfTI file. |
Source code in oxytcmri/interface/mri/staple_segmenter.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | |
clean_up_temporary_files()
¶
Remove all temporary files created by this handler.
This method should be called when the temporary files are no longer needed, typically after the segmentation merging process is complete.
Source code in oxytcmri/interface/mri/staple_segmenter.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
C3DSTAPLESegmentationMerger()
¶
Bases: SegmentationMerger
Implementation of SegmentationMerger using c3d-tools STAPLE algorithm.
STAPLE (Simultaneous Truth and Performance Level Estimation) is an algorithm for merging multiple segmentations into a consensus segmentation.
Initialize the merger with a temporary files handler.
Methods:
| Name | Description |
|---|---|
merge |
Merge multiple segmentations using |
build_output_path |
|
run_c3d_command |
Run the c3d command line tool. |
Attributes:
| Name | Type | Description |
|---|---|---|
temp_files_handler |
|
Source code in oxytcmri/interface/mri/staple_segmenter.py
76 77 78 79 80 | |
temp_files_handler = TemporaryFilesHandler()
instance-attribute
¶
merge(segmentations)
¶
Merge multiple segmentations using c3d command line tool with STAPLE algorithm.
Process flow: 1. Convert AbnormalVoxelData (semantic values LOW/HIGH) to temporary NIfTI files (integers 0/1/2) 2. Process these files with c3d STAPLE algorithm 3. Convert the result back to AbnormalVoxelData (semantic values LOW/HIGH)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
segmentations
|
List[DTIAbnormalValues]
|
List of segmentations to merge |
required |
Returns:
| Type | Description |
|---|---|
DTIAbnormalValues
|
Merged segmentation |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the segmentations list is empty |
RuntimeError
|
If the c3d command fails |
Source code in oxytcmri/interface/mri/staple_segmenter.py
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 | |
build_output_path(source_voxel_data, suffix)
staticmethod
¶
Source code in oxytcmri/interface/mri/staple_segmenter.py
228 229 230 231 232 233 234 235 | |
run_c3d_command(input_paths_list, output_path, options)
staticmethod
¶
Run the c3d command line tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_paths_list
|
List[Path]
|
List of input file paths to merge |
required |
output_path
|
Path
|
Path to save the output NIfTI file |
required |
options
|
List[str]
|
Options for the c3d command (e.g., "-staple 1") |
required |
Source code in oxytcmri/interface/mri/staple_segmenter.py
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 | |