pymedio package¶
Submodules¶
pymedio.base module¶
Base image class for image containers Author: Jacob Reinhold <jcreinhold@gmail.com>
- class pymedio.base.BasicImage(data: npt.ArrayLike, affine: npt.NDArray | None = None, *, info: str | npt.NDArray[np.str_] | None = None, copy: bool = False)[source]¶
Bases:
ndarray
[Any
,dtype
[DType
]]- property affine: ndarray[Any, dtype[float64]]¶
- property direction: tuple[Union[numpy.floating[T], float], Union[numpy.floating[T], float], Union[numpy.floating[T], float], Union[numpy.floating[T], float]] | tuple[Union[numpy.floating[T], float], Union[numpy.floating[T], float], Union[numpy.floating[T], float], Union[numpy.floating[T], float], Union[numpy.floating[T], float], Union[numpy.floating[T], float]]¶
- property info: ndarray[Any, dtype[str_]]¶
- property memory: integer[T] | int¶
Number of bytes that the image array occupies in RAM
- property origin: tuple[Union[numpy.floating[T], float], ...]¶
Center of first voxel in array, in mm.
- property repr_properties: list[str]¶
- property spacing: tuple[Union[numpy.floating[T], float], ...]¶
Voxel spacing in mm.
pymedio.dicom module¶
DICOM-specific functions inspired by dicom-numpy: https://github.com/innolitics/dicom-numpy Author: Jacob Reinhold <jcreinhold@gmail.com>
- class pymedio.dicom.DICOMDir(slices: 'tuple[pydicom.Dataset, ...]', positions: 'tuple[float, ...]', slice_spacing: 'float', affine: 'npt.NDArray', paths: 'tuple[miot.PathLike, ...] | None' = None)[source]¶
Bases:
object
- affine: npt.NDArray¶
- classmethod from_datasets(datasets: Sequence[pydicom.Dataset], *, paths: Sequence[miot.PathLike] | None = None, max_nonuniformity: float = 0.0005, fail_outside_max_nonuniformity: bool = True, remove_anomalous_images: bool = True) DICOMDir [source]¶
- classmethod from_path(dicom_path: miot.PathLike | Iterable[miot.PathLike], *, max_nonuniformity: float = 0.0005, fail_outside_max_nonuniformity: bool = True, remove_anomalous_images: bool = True, defer_size: str | int | None = '1 KB', extension: str = '.dcm') DICOMDir [source]¶
- classmethod from_zipped_stream(data_stream: IO, *, max_nonuniformity: float = 0.0005, fail_outside_max_nonuniformity: bool = True, remove_anomalous_images: bool = True, encryption_key: bytes | str | None = None, **zip_kwargs: Any) DICOMDir [source]¶
- paths: tuple[miot.PathLike, ...] | None = None¶
- positions: tuple[float, ...]¶
- slice_spacing: float¶
- slices: tuple[pydicom.Dataset, ...]¶
- class pymedio.dicom.DICOMImage(data: npt.ArrayLike, affine: npt.NDArray | None = None, *, info: str | npt.NDArray[np.str_] | None = None, copy: bool = False)[source]¶
Bases:
BasicImage
[Any
,DType
]- classmethod from_dicomdir(dicom_dir: DICOMDir, *, rescale: bool | None = None, rescale_dtype: Type[miot.DType] | None = None, order: Literal['F', 'C'] | None = None) DICOMImage[miot.DType] [source]¶
- classmethod from_path(dicom_path: miot.PathLike | Iterable[miot.PathLike], *, max_nonuniformity: float = 0.0005, fail_outside_max_nonuniformity: bool = True, remove_anomalous_images: bool = True, rescale: bool | None = None, rescale_dtype: Type[miot.DType] | None = None, order: Literal['F', 'C'] | None = None, extension: str = '.dcm') DICOMImage[miot.DType] [source]¶
- classmethod from_zipped_stream(data_stream: IO, *, max_nonuniformity: float = 0.0005, fail_outside_max_nonuniformity: bool = True, remove_anomalous_images: bool = True, encryption_key: bytes | str | None = None, rescale: bool | None = None, rescale_dtype: Type[miot.DType] | None = None, order: Literal['F', 'C'] | None = None, **zip_kwargs: Any) DICOMImage[miot.DType] [source]¶
pymedio.exceptions module¶
Project exceptions Author: Jacob Reinhold <jcreinhold@gmail.com>
- exception pymedio.exceptions.DicomImportException[source]¶
Bases:
MedIOException
- exception pymedio.exceptions.MissingSlicesException[source]¶
Bases:
MedIOException
- exception pymedio.exceptions.OutsideMaxNonUniformity[source]¶
Bases:
MedIOException
pymedio.functional module¶
Functions for reading medical images Taken from torchio and modified to output np.ndarray https://github.com/fepegar/torchio Author: Jacob Reinhold <jcreinhold@gmail.com>
- pymedio.functional.read_image(path: miot.PathLike, *, dtype: Type[miot.DType] | None = None, eager: bool = True) miot.DataAffine[miot.DType] [source]¶
- pymedio.functional.read_matrix(path: str | PathLike) ndarray[Any, dtype[float64]] [source]¶
Read an affine transform and return array
pymedio.image module¶
Image class to hold a medical image Taken from torchio and modified to use eager load and use np.ndarray instead of torch.tensor https://github.com/fepegar/torchio Author: Jacob Reinhold <jcreinhold@gmail.com>
- class pymedio.image.Image(data: npt.ArrayLike, affine: npt.NDArray | None = None, *, info: str | npt.NDArray[np.str_] | None = None, copy: bool = False)[source]¶
Bases:
BasicImage
[Any
,DType
]- property bounds: ndarray[Any, dtype[float64]]¶
Position of centers of voxels in smallest and largest indices.
- classmethod from_dicom_image(dicom_image: DICOMImage) Image [source]¶
- classmethod from_dicom_zipped_stream(data_stream: IO, *, max_nonuniformity: float = 0.0005, fail_outside_max_nonuniformity: bool = True, remove_anomalous_images: bool = True, encryption_key: bytes | str | None = None, rescale: bool | None = None, rescale_dtype: Type[miot.DType] | None = None) Image[miot.DType] [source]¶
- classmethod from_path(path: miot.PathLike, *, dtype: Type[miot.DType] | None = None, eager: bool = True) Image[miot.DType] [source]¶
- classmethod from_sitk(sitk_image: sitk.Image, *, dtype: Type[miot.DType] | None = None) Image [source]¶
- classmethod from_stream(data_stream: IO, *, dtype: Type[miot.DType] | None = None, gzipped: bool = False, image_class: miof.NibabelImageClass | None = None) Image[miot.DType] [source]¶
- classmethod from_zipped_stream(data_stream: IO, *, dtype: Type[miot.DType] | None = None, gzipped: bool = False, image_class: miof.NibabelImageClass | None = None, **zip_kwargs: Any) Image[miot.DType] [source]¶
- get_bounds() tuple[tuple[Union[numpy.floating[T], float], Union[numpy.floating[T], float]], tuple[Union[numpy.floating[T], float], Union[numpy.floating[T], float]], tuple[Union[numpy.floating[T], float], Union[numpy.floating[T], float]]] [source]¶
Get minimum and maximum world coordinates occupied by the image.
- get_center(lps: bool = False) tuple[Union[numpy.floating[T], float], Union[numpy.floating[T], float], Union[numpy.floating[T], float]] [source]¶
Get image center in RAS+ or LPS+ coordinates
- property orientation: tuple[str, str, str]¶
Orientation codes.
- property repr_properties: list[str]¶
pymedio.typing module¶
medio types for type annotations Author: Jacob Reinhold <jcreinhold@gmail.com>
- pymedio.typing.Bounds¶
alias of
tuple
[tuple
[Union
[floating
[T
],float
],Union
[floating
[T
],float
]],tuple
[Union
[floating
[T
],float
],Union
[floating
[T
],float
]],tuple
[Union
[floating
[T
],float
],Union
[floating
[T
],float
]]]
- pymedio.typing.DataAffine¶
alias of
tuple
[ndarray
[Any
,dtype
[DType
]],ndarray
[Any
,dtype
[float64
]]]
- pymedio.typing.Shape¶
alias of
tuple
[Union
[integer
[T
],int
], …]
- pymedio.typing.TripletFloat¶
alias of
tuple
[Union
[floating
[T
],float
],Union
[floating
[T
],float
],Union
[floating
[T
],float
]]
pymedio.utils module¶
miscellaneous project functions Author: Jacob Reinhold <jcreinhold@gmail.com>
- pymedio.utils.check_uint_to_int(array: ndarray[Any, dtype[ScalarType]]) ndarray[Any, dtype[ScalarType]] [source]¶
convert to int b/c PyTorch won’t take uint16 nor uint32
- pymedio.utils.ensure_4d(array: npt.NDArray[miot.DType], *, num_spatial_dims: builtins.int | None = None) npt.NDArray[miot.DType] [source]¶
for PyTorch
- pymedio.utils.get_metadata_from_ras_affine(affine: ndarray[Any, dtype[ScalarType]], *, is_2d: bool = False, lps: bool = True) tuple[tuple[Union[numpy.floating[T], float], Union[numpy.floating[T], float], Union[numpy.floating[T], float]], tuple[Union[numpy.floating[T], float], Union[numpy.floating[T], float], Union[numpy.floating[T], float]], Union[tuple[Union[numpy.floating[T], float], Union[numpy.floating[T], float], Union[numpy.floating[T], float], Union[numpy.floating[T], float]], tuple[Union[numpy.floating[T], float], Union[numpy.floating[T], float], Union[numpy.floating[T], float], Union[numpy.floating[T], float], Union[numpy.floating[T], float], Union[numpy.floating[T], float]]]] [source]¶
- pymedio.utils.get_rotation_and_spacing_from_affine(affine: ndarray[Any, dtype[DType]]) tuple[numpy.ndarray[typing.Any, numpy.dtype[+DType]], numpy.ndarray[typing.Any, numpy.dtype[+DType]]] [source]¶
Module contents¶
Top-level package for pymedio.