Args: reader: reader to load image file and metadata - if `reader` is None, a default set of `SUPPORTED_READERS` will be used. - if `reader` is a string, it's treated as a class name or dotted path (such as ``"monai.data.ITKReader"
(
self,
reader=None,
image_only: bool = True,
dtype: DtypeLike | None = np.float32,
ensure_channel_first: bool = False,
simple_keys: bool = False,
prune_meta_pattern: str | None = None,
prune_meta_sep: str = ".",
expanduser: bool = True,
*args,
**kwargs,
)
| 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 | |
| 167 | Note: |
| 168 | |
| 169 | - The transform returns a MetaTensor, unless `set_track_meta(False)` has been used, in which case, a |
| 170 | `torch.Tensor` will be returned. |
| 171 | - If `reader` is specified, the loader will attempt to use the specified readers and the default supported |
| 172 | readers. This might introduce overheads when handling the exceptions of trying the incompatible loaders. |
| 173 | In this case, it is therefore recommended setting the most appropriate reader as |
| 174 | the last item of the `reader` parameter. |
| 175 | |
| 176 | """ |
| 177 | |
| 178 | self.auto_select = reader is None |
| 179 | self.image_only = image_only |
| 180 | self.dtype = dtype |
| 181 | self.ensure_channel_first = ensure_channel_first |
| 182 | self.simple_keys = simple_keys |
| 183 | self.pattern = prune_meta_pattern |
| 184 | self.sep = prune_meta_sep |
| 185 | self.expanduser = expanduser |
| 186 | |
| 187 | self.readers: list[ImageReader] = [] |
| 188 | for r in SUPPORTED_READERS: # set predefined readers as default |
nothing calls this directly
no test coverage detected