Load NRRD format images based on pynrrd library. Args: channel_dim: the channel dimension of the input image, default is None. This is used to set original_channel_dim in the metadata, EnsureChannelFirstD reads this field. If None, `original_channel_dim` wil
| 1455 | |
| 1456 | @require_pkg(pkg_name="nrrd") |
| 1457 | class NrrdReader(ImageReader): |
| 1458 | """ |
| 1459 | Load NRRD format images based on pynrrd library. |
| 1460 | |
| 1461 | Args: |
| 1462 | channel_dim: the channel dimension of the input image, default is None. |
| 1463 | This is used to set original_channel_dim in the metadata, EnsureChannelFirstD reads this field. |
| 1464 | If None, `original_channel_dim` will be either `no_channel` or `0`. |
| 1465 | NRRD files are usually "channel first". |
| 1466 | dtype: dtype of the data array when loading image. |
| 1467 | index_order: Specify whether the returned data array should be in C-order (‘C’) or Fortran-order (‘F’). |
| 1468 | Numpy is usually in C-order, but default on the NRRD header is F |
| 1469 | affine_lps_to_ras: whether to convert the affine matrix from "LPS" to "RAS". Defaults to ``True``. |
| 1470 | Set to ``True`` to be consistent with ``NibabelReader``, otherwise the affine matrix is unmodified. |
| 1471 | |
| 1472 | kwargs: additional args for `nrrd.read` API. more details about available args: |
| 1473 | https://github.com/mhe/pynrrd/blob/master/nrrd/reader.py |
| 1474 | |
| 1475 | """ |
| 1476 | |
| 1477 | def __init__( |
| 1478 | self, |
| 1479 | channel_dim: str | int | None = None, |
| 1480 | dtype: np.dtype | type | str | None = np.float32, |
| 1481 | index_order: str = "F", |
| 1482 | affine_lps_to_ras: bool = True, |
| 1483 | **kwargs, |
| 1484 | ): |
| 1485 | self.channel_dim = float("nan") if channel_dim == "no_channel" else channel_dim |
| 1486 | self.dtype = dtype |
| 1487 | self.index_order = index_order |
| 1488 | self.affine_lps_to_ras = affine_lps_to_ras |
| 1489 | self.kwargs = kwargs |
| 1490 | |
| 1491 | def verify_suffix(self, filename: Sequence[PathLike] | PathLike) -> bool: |
| 1492 | """ |
| 1493 | Verify whether the specified `filename` is supported by pynrrd reader. |
| 1494 | |
| 1495 | Args: |
| 1496 | filename: file name or a list of file names to read. |
| 1497 | if a list of files, verify all the suffixes. |
| 1498 | |
| 1499 | """ |
| 1500 | suffixes: Sequence[str] = ["nrrd", "seg.nrrd"] |
| 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) |
no outgoing calls
searching dependent graphs…