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

Method read

monai/data/image_reader.py:1074–1097  ·  view source on GitHub ↗

Read image data from specified file or files, it can read a list of images and stack them together as multi-channel data in `get_data()`. Note that the returned object is Nibabel image object or list of Nibabel image objects. Args: data: file name or a l

(self, data: Sequence[PathLike] | PathLike, **kwargs)

Source from the content-addressed store, hash-verified

1072 return has_nib and is_supported_format(filename, suffixes)
1073
1074 def read(self, data: Sequence[PathLike] | PathLike, **kwargs):
1075 """
1076 Read image data from specified file or files, it can read a list of images
1077 and stack them together as multi-channel data in `get_data()`.
1078 Note that the returned object is Nibabel image object or list of Nibabel image objects.
1079
1080 Args:
1081 data: file name or a list of file names to read.
1082 kwargs: additional args for `nibabel.load` API, will override `self.kwargs` for existing keys.
1083 More details about available args:
1084 https://github.com/nipy/nibabel/blob/master/nibabel/loadsave.py
1085
1086 """
1087 img_: list[Nifti1Image] = []
1088
1089 filenames: Sequence[PathLike] = ensure_tuple(data)
1090 self.filenames = filenames
1091 kwargs_ = self.kwargs.copy()
1092 kwargs_.update(kwargs)
1093 for name in filenames:
1094 img = nib.load(name, **kwargs_)
1095 img = correct_nifti_header_if_necessary(img)
1096 img_.append(img) # type: ignore
1097 return img_ if len(filenames) > 1 else img_[0]
1098
1099 def get_data(self, img) -> tuple[np.ndarray, dict]:
1100 """

Calls 5

ensure_tupleFunction · 0.90
loadMethod · 0.80
updateMethod · 0.45
appendMethod · 0.45