Autopipeline
autopipeline
#
Functions:
Name | Description |
---|---|
process_one_sample |
Process a single medical imaging sample through the complete pipeline. |
Autopipeline
#
Autopipeline(
input_directory: str | pathlib.Path,
output_directory: str | pathlib.Path,
output_filename_format: str = imgtools.io.sample_output.DEFAULT_FILENAME_FORMAT,
existing_file_mode: imgtools.io.sample_output.ExistingFileMode = imgtools.io.sample_output.ExistingFileMode.FAIL,
update_crawl: bool = False,
n_jobs: int | None = None,
modalities: list[str] | None = None,
roi_match_map: imgtools.coretypes.masktypes.roi_matching.Valid_Inputs = None,
roi_ignore_case: bool = True,
roi_handling_strategy: (
str
| imgtools.coretypes.masktypes.roi_matching.ROIMatchStrategy
) = imgtools.coretypes.masktypes.roi_matching.ROIMatchStrategy.SEPARATE,
roi_allow_multi_key_matches: bool = True,
roi_on_missing_regex: (
str
| imgtools.coretypes.masktypes.roi_matching.ROIMatchFailurePolicy
) = imgtools.coretypes.masktypes.roi_matching.ROIMatchFailurePolicy.WARN,
spacing: tuple[float, float, float] = (0.0, 0.0, 0.0),
window: float | None = None,
level: float | None = None,
)
Pipeline for processing medical images.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
|
str | pathlib.Path
|
Directory containing the DICOM files (or subdirectories with DICOM files) |
required |
|
str | pathlib.Path
|
Directory to save the output nifti files |
required |
|
str
|
Format string for output filenames with placeholders for metadata values. |
imgtools.io.sample_output.DEFAULT_FILENAME_FORMAT
|
|
imgtools.io.sample_output.ExistingFileMode
|
How to handle existing files (FAIL, SKIP, OVERWRITE). |
imgtools.io.sample_output.ExistingFileMode.FAIL
|
|
bool
|
Whether to force recrawling, by default False |
False
|
|
int | None
|
Number of parallel jobs, by default None (uses CPU count - 2) |
None
|
|
list[str] | None
|
List of modalities to include, by default None (all) |
None
|
|
imgtools.coretypes.masktypes.roi_matching.Valid_Inputs
|
ROI matching patterns, by default None |
None
|
|
bool
|
Whether to ignore case in ROI matching, by default True |
True
|
|
str | imgtools.coretypes.masktypes.roi_matching.ROIMatchStrategy
|
Strategy for handling ROI matches, by default ROIMatchStrategy.MERGE |
imgtools.coretypes.masktypes.roi_matching.ROIMatchStrategy.SEPARATE
|
|
bool
|
Whether to allow one ROI to match multiple keys in the match_map. |
True
|
|
str | imgtools.coretypes.masktypes.roi_matching.ROIMatchFailurePolicy
|
How to handle when no ROI matches any pattern in match_map. By default ROIMatchFailurePolicy.WARN |
imgtools.coretypes.masktypes.roi_matching.ROIMatchFailurePolicy.WARN
|
|
tuple[float, float, float]
|
Spacing for resampling, by default (0.0, 0.0, 0.0) |
(0.0, 0.0, 0.0)
|
|
float | None
|
Window level for intensity normalization, by default None |
None
|
|
float | None
|
Window level for intensity normalization, by default None |
None
|
Methods:
Name | Description |
---|---|
run |
Run the pipeline on all samples. |
Source code in src/imgtools/autopipeline.py
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 |
|
run
#
run() -> typing.Dict[
str,
typing.List[imgtools.autopipeline.ProcessSampleResult],
]
Run the pipeline on all samples.
Returns:
Type | Description |
---|---|
typing.Dict[str, typing.List[imgtools.autopipeline.ProcessSampleResult]]
|
Dictionary with 'success' and 'failure' keys, each containing a list of ProcessSampleResult objects. |
Source code in src/imgtools/autopipeline.py
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 |
|
NoValidSamplesError
#
Bases: Exception
Exception raised when no valid samples are found.
Source code in src/imgtools/autopipeline.py
ProcessSampleResult
dataclass
#
ProcessSampleResult(
sample_id: str,
sample: typing.Sequence[
imgtools.dicom.interlacer.SeriesNode
],
output_files: typing.List[pathlib.Path] = list(),
success: bool = False,
error_type: typing.Optional[str] = None,
error_message: typing.Optional[str] = None,
error_details: typing.Optional[typing.Dict] = None,
processing_time: typing.Optional[float] = None,
)
Result of processing a single sample.
Methods:
Name | Description |
---|---|
to_dict |
Convert the result to a dictionary. |
to_dict
#
Convert the result to a dictionary.
Source code in src/imgtools/autopipeline.py
process_one_sample
#
process_one_sample(
args: tuple[
str,
typing.Sequence[
imgtools.dicom.interlacer.SeriesNode
],
imgtools.io.sample_input.SampleInput,
imgtools.transforms.Transformer,
imgtools.io.sample_output.SampleOutput,
],
) -> imgtools.autopipeline.ProcessSampleResult
Process a single medical imaging sample through the complete pipeline.
The single 'args' tuple contains the following elements, likely passed in from the components of the autopipeline class: - idx: str (arbitrary, generated from enumerate) - sample: Sequence[SeriesNode] (a sample is the group of series that belong to the same reference image) - sample_input: SampleInput (class that handles loading the sample) - transformer: Transformer (class that handles the transformation pipeline) - sample_output: SampleOutput (class that handles saving the sample)
This function handles the entire lifecycle of processing a medical image sample:
- First, we load the sample images from the provided input source
- Then, we verify that all requested images were properly loaded
- Next, we apply the transformation pipeline to the images (resampling, windowing, etc.)
- Finally, we save the processed images to the output location
Throughout this process, we track any errors that occur and return detailed information about successes or failures for reporting purposes.
Returns:
Type | Description |
---|---|
imgtools.autopipeline.ProcessSampleResult
|
Result of processing the sample, including success/failure information |
Source code in src/imgtools/autopipeline.py
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 |
|