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

Method read

monai/data/image_reader.py:1503–1520  ·  view source on GitHub ↗

Read image data from specified file or files. Note that it returns a data object or a sequence of data objects. Args: data: file name or a list of file names to read. kwargs: additional args for actual `read` API of 3rd party libs.

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

Source from the content-addressed store, hash-verified

1501 return has_nrrd and is_supported_format(filename, suffixes)
1502
1503 def read(self, data: Sequence[PathLike] | PathLike, **kwargs) -> Sequence[Any] | Any:
1504 """
1505 Read image data from specified file or files.
1506 Note that it returns a data object or a sequence of data objects.
1507
1508 Args:
1509 data: file name or a list of file names to read.
1510 kwargs: additional args for actual `read` API of 3rd party libs.
1511
1512 """
1513 img_: list = []
1514 filenames: Sequence[PathLike] = ensure_tuple(data)
1515 kwargs_ = self.kwargs.copy()
1516 kwargs_.update(kwargs)
1517 for name in filenames:
1518 nrrd_image = NrrdImage(*nrrd.read(name, index_order=self.index_order, **kwargs_))
1519 img_.append(nrrd_image)
1520 return img_ if len(filenames) > 1 else img_[0]
1521
1522 def get_data(self, img: NrrdImage | list[NrrdImage]) -> tuple[np.ndarray, dict]:
1523 """

Callers 5

test_read_intMethod · 0.95
test_read_floatMethod · 0.95
test_read_listMethod · 0.95
test_read_with_headerMethod · 0.95

Calls 5

ensure_tupleFunction · 0.90
NrrdImageClass · 0.85
updateMethod · 0.45
readMethod · 0.45
appendMethod · 0.45

Tested by 5

test_read_intMethod · 0.76
test_read_floatMethod · 0.76
test_read_listMethod · 0.76
test_read_with_headerMethod · 0.76