Load medical images based on Pydicom library. All the supported image formats can be found at: https://dicom.nema.org/medical/dicom/current/output/chtml/part10/chapter_7.html PydicomReader is also able to load segmentations, if a dicom file contains tag: `SegmentSequence`, the read
| 391 | |
| 392 | @require_pkg(pkg_name="pydicom") |
| 393 | class PydicomReader(ImageReader): |
| 394 | """ |
| 395 | Load medical images based on Pydicom library. |
| 396 | All the supported image formats can be found at: |
| 397 | https://dicom.nema.org/medical/dicom/current/output/chtml/part10/chapter_7.html |
| 398 | |
| 399 | PydicomReader is also able to load segmentations, if a dicom file contains tag: `SegmentSequence`, the reader |
| 400 | will consider it as segmentation data, and to load it successfully, `PerFrameFunctionalGroupsSequence` is required |
| 401 | for dicom file, and for each frame of dicom file, `SegmentIdentificationSequence` is required. |
| 402 | This method refers to the Highdicom library. |
| 403 | |
| 404 | This class refers to: |
| 405 | https://nipy.org/nibabel/dicom/dicom_orientation.html#dicom-affine-formula |
| 406 | https://github.com/pydicom/contrib-pydicom/blob/master/input-output/pydicom_series.py |
| 407 | https://highdicom.readthedocs.io/en/latest/usage.html#parsing-segmentation-seg-images |
| 408 | |
| 409 | Args: |
| 410 | channel_dim: the channel dimension of the input image, default is None. |
| 411 | This is used to set original_channel_dim in the metadata, EnsureChannelFirstD reads this field. |
| 412 | If None, `original_channel_dim` will be either `no_channel` or `-1`. |
| 413 | affine_lps_to_ras: whether to convert the affine matrix from "LPS" to "RAS". Defaults to ``True``. |
| 414 | Set to ``True`` to be consistent with ``NibabelReader``, |
| 415 | otherwise the affine matrix remains in the Dicom convention. |
| 416 | swap_ij: whether to swap the first two spatial axes. Default to ``True``, so that the outputs |
| 417 | are consistent with the other readers. |
| 418 | prune_metadata: whether to prune the saved information in metadata. This argument is used for |
| 419 | `get_data` function. If True, only items that are related to the affine matrix will be saved. |
| 420 | Default to ``True``. |
| 421 | label_dict: label of the dicom data. If provided, it will be used when loading segmentation data. |
| 422 | Keys of the dict are the classes, and values are the corresponding class number. For example: |
| 423 | for TCIA collection "C4KC-KiTS", it can be: {"Kidney": 0, "Renal Tumor": 1}. |
| 424 | fname_regex: a regular expression to match the file names when the input is a folder. |
| 425 | If provided, only the matched files will be included. For example, to include the file name |
| 426 | "image_0001.dcm", the regular expression could be `".*image_(\\d+).dcm"`. Default to `""`. |
| 427 | Set it to `None` to use `pydicom.misc.is_dicom` to match valid files. |
| 428 | to_gpu: If True, load the image into GPU memory using CuPy and Kvikio. This can accelerate data loading. |
| 429 | Default is False. CuPy and Kvikio are required for this option. |
| 430 | In practical use, it's recommended to add a warm up call before the actual loading. |
| 431 | A related tutorial will be prepared in the future, and the document will be updated accordingly. |
| 432 | kwargs: additional args for `pydicom.dcmread` API. more details about available args: |
| 433 | https://pydicom.github.io/pydicom/stable/reference/generated/pydicom.filereader.dcmread.html |
| 434 | If the `get_data` function will be called |
| 435 | (for example, when using this reader with `monai.transforms.LoadImage`), please ensure that the argument |
| 436 | `stop_before_pixels` is `True`, and `specific_tags` covers all necessary tags, such as `PixelSpacing`, |
| 437 | `ImagePositionPatient`, `ImageOrientationPatient` and all `pixel_array` related tags. |
| 438 | """ |
| 439 | |
| 440 | def __init__( |
| 441 | self, |
| 442 | channel_dim: str | int | None = None, |
| 443 | affine_lps_to_ras: bool = True, |
| 444 | swap_ij: bool = True, |
| 445 | prune_metadata: bool = True, |
| 446 | label_dict: dict | None = None, |
| 447 | fname_regex: str = "", |
| 448 | to_gpu: bool = False, |
| 449 | **kwargs, |
| 450 | ): |
no outgoing calls
searching dependent graphs…