MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / ITKReader

Class ITKReader

monai/data/image_reader.py:169–389  ·  view source on GitHub ↗

Load medical images based on ITK library. All the supported image formats can be found at: https://github.com/InsightSoftwareConsortium/ITK/tree/master/Modules/IO The loaded data array will be in C order, for example, a 3D image NumPy array index order will be `CDWH`. Args:

Source from the content-addressed store, hash-verified

167
168@require_pkg(pkg_name="itk")
169class ITKReader(ImageReader):
170 """
171 Load medical images based on ITK library.
172 All the supported image formats can be found at:
173 https://github.com/InsightSoftwareConsortium/ITK/tree/master/Modules/IO
174 The loaded data array will be in C order, for example, a 3D image NumPy
175 array index order will be `CDWH`.
176
177 Args:
178 channel_dim: the channel dimension of the input image, default is None.
179 This is used to set original_channel_dim in the metadata, EnsureChannelFirstD reads this field.
180 If None, `original_channel_dim` will be either `no_channel` or `-1`.
181
182 - Nifti file is usually "channel last", so there is no need to specify this argument.
183 - PNG file usually has `GetNumberOfComponentsPerPixel()==3`, so there is no need to specify this argument.
184
185 series_name: the name of the DICOM series if there are multiple ones.
186 used when loading DICOM series.
187 reverse_indexing: whether to use a reversed spatial indexing convention for the returned data array.
188 If ``False``, the spatial indexing convention is reversed to be compatible with ITK;
189 otherwise, the spatial indexing follows the numpy convention. Default is ``False``.
190 This option does not affect the metadata.
191 series_meta: whether to load the metadata of the DICOM series (using the metadata from the first slice).
192 This flag is checked only when loading DICOM series. Default is ``False``.
193 affine_lps_to_ras: whether to convert the affine matrix from "LPS" to "RAS". Defaults to ``True``.
194 Set to ``True`` to be consistent with ``NibabelReader``, otherwise the affine matrix remains in the ITK convention.
195 kwargs: additional args for `itk.imread` API. more details about available args:
196 https://github.com/InsightSoftwareConsortium/ITK/blob/master/Wrapping/Generators/Python/itk/support/extras.py
197
198 """
199
200 def __init__(
201 self,
202 channel_dim: str | int | None = None,
203 series_name: str = "",
204 reverse_indexing: bool = False,
205 series_meta: bool = False,
206 affine_lps_to_ras: bool = True,
207 **kwargs,
208 ):
209 super().__init__()
210 self.kwargs = kwargs
211 self.channel_dim = float("nan") if channel_dim == "no_channel" else channel_dim
212 self.series_name = series_name
213 self.reverse_indexing = reverse_indexing
214 self.series_meta = series_meta
215 self.affine_lps_to_ras = affine_lps_to_ras
216
217 def verify_suffix(self, filename: Sequence[PathLike] | PathLike) -> bool:
218 """
219 Verify whether the specified file or files format is supported by ITK reader.
220
221 Args:
222 filename: file name or a list of file names to read.
223 if a list of files, verify all the suffixes.
224
225 """
226 return has_itk

Callers 12

itk_image_to_metatensorFunction · 0.90
test_readersMethod · 0.90
setUpMethod · 0.90
test_registerMethod · 0.90
test_channel_dimMethod · 0.90
test_load_image.pyFile · 0.85
test_registerMethod · 0.85
test_kwargsMethod · 0.85

Calls

no outgoing calls

Tested by 9

test_readersMethod · 0.72
setUpMethod · 0.72
test_registerMethod · 0.72
test_channel_dimMethod · 0.72
test_registerMethod · 0.68
test_kwargsMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…