Load image file or files from provided path based on reader. If reader is not specified, this class automatically chooses readers based on the supported suffixes and in the following order: - User-specified reader at runtime when calling this loader. - User-specified re
| 107 | |
| 108 | |
| 109 | class LoadImage(Transform): |
| 110 | """ |
| 111 | Load image file or files from provided path based on reader. |
| 112 | If reader is not specified, this class automatically chooses readers |
| 113 | based on the supported suffixes and in the following order: |
| 114 | |
| 115 | - User-specified reader at runtime when calling this loader. |
| 116 | - User-specified reader in the constructor of `LoadImage`. |
| 117 | - Readers from the last to the first in the registered list. |
| 118 | - Current default readers: (nii, nii.gz -> NibabelReader), (png, jpg, bmp -> PILReader), |
| 119 | (npz, npy -> NumpyReader), (nrrd -> NrrdReader), (DICOM file -> ITKReader). |
| 120 | |
| 121 | Please note that for png, jpg, bmp, and other 2D formats, readers by default swap axis 0 and 1 after |
| 122 | loading the array with ``reverse_indexing`` set to ``True`` because the spatial axes definition |
| 123 | for non-medical specific file formats is different from other common medical packages. |
| 124 | |
| 125 | See also: |
| 126 | |
| 127 | - tutorial: https://github.com/Project-MONAI/tutorials/blob/master/modules/load_medical_images.ipynb |
| 128 | |
| 129 | """ |
| 130 | |
| 131 | def __init__( |
| 132 | self, |
| 133 | reader=None, |
| 134 | image_only: bool = True, |
| 135 | dtype: DtypeLike | None = np.float32, |
| 136 | ensure_channel_first: bool = False, |
| 137 | simple_keys: bool = False, |
| 138 | prune_meta_pattern: str | None = None, |
| 139 | prune_meta_sep: str = ".", |
| 140 | expanduser: bool = True, |
| 141 | *args, |
| 142 | **kwargs, |
| 143 | ) -> None: |
| 144 | """ |
| 145 | Args: |
| 146 | reader: reader to load image file and metadata |
| 147 | - if `reader` is None, a default set of `SUPPORTED_READERS` will be used. |
| 148 | - if `reader` is a string, it's treated as a class name or dotted path |
| 149 | (such as ``"monai.data.ITKReader"``), the supported built-in reader classes are |
| 150 | ``"ITKReader"``, ``"NibabelReader"``, ``"NumpyReader"``, ``"PydicomReader"``. |
| 151 | a reader instance will be constructed with the `*args` and `**kwargs` parameters. |
| 152 | - if `reader` is a reader class/instance, it will be registered to this loader accordingly. |
| 153 | image_only: if True return only the image MetaTensor, otherwise return image and header dict. |
| 154 | dtype: if not None convert the loaded image to this data type. |
| 155 | ensure_channel_first: if `True` and loaded both image array and metadata, automatically convert |
| 156 | the image array shape to `channel first`. default to `False`. |
| 157 | simple_keys: whether to remove redundant metadata keys, default to False for backward compatibility. |
| 158 | prune_meta_pattern: combined with `prune_meta_sep`, a regular expression used to match and prune keys |
| 159 | in the metadata (nested dictionary), default to None, no key deletion. |
| 160 | prune_meta_sep: combined with `prune_meta_pattern`, used to match and prune keys |
| 161 | in the metadata (nested dictionary). default is ".", see also :py:class:`monai.transforms.DeleteItemsd`. |
| 162 | e.g. ``prune_meta_pattern=".*_code$", prune_meta_sep=" "`` removes meta keys that ends with ``"_code"``. |
| 163 | expanduser: if True cast filename to Path and call .expanduser on it, otherwise keep filename as is. |
| 164 | args: additional parameters for reader if providing a reader name. |
| 165 | kwargs: additional parameters for reader if providing a reader name. |
| 166 |
no outgoing calls
searching dependent graphs…