MedBase.item_preprocessing(target_spacing=[1,1,1], apply_reorder=True)
im = MedImage.create('images/IXI002-Guys-0828-T1.nii.gz')
test_eq(type(im), MedImage)Vision core
MedImage and MedMask tensors.
Load images
med_img_reader
def med_img_reader(
file_path:str | pathlib.Path | fastcore.foundation.L | list, apply_reorder:bool=False, target_spacing:list=None,
only_tensor:bool=True, dtype:_TensorMeta=Tensor
):Loads and preprocesses a medical image.
Args: file_path: Path to the image, or a list of paths (e.g. T1, T2) that are stacked as channels of one image, using the first channel of each file. For a list, the original image and size come from the last file. apply_reorder: Whether to reorder the data to be closest to canonical (RAS+) orientation. Defaults to False. target_spacing: Voxel spacing to resample to. Defaults to None, which keeps the original spacing. only_tensor: Whether to return only image tensor. Defaults to True. dtype: Datatype for the return value. Defaults to torch.Tensor.
Returns: The preprocessed image. Returns only the image tensor if only_tensor is True, otherwise returns original image, preprocessed image, and original size.
Basic types
MetaResolver
def MetaResolver(
*args, **kwargs
):A class to bypass metaclass conflict: https://pytorch-geometric.readthedocs.io/en/latest/_modules/torch_geometric/data/batch.html
MedBase
def MedBase(
*args, **kwargs
):A class that represents an image object. Metaclass casts x to this class if it is of type cls._bypass_type.
target_spacing, apply_reorder and affine_matrix are CLASS attributes (shared by MedImage/MedMask), set once via item_preprocessing (from MedDataBlock); affine_matrix is latched from the first loaded image and read by spatial augmentation. One dataset per process with uniform reorder+resample before augmentation, so all samples share an affine.
MedImage
def MedImage(
*args, **kwargs
):Subclass of MedBase that represents an image object.
MedMask
def MedMask(
*args, **kwargs
):Subclass of MedBase that represents a mask object.
ax = im.show(anatomical_plane=0)