Vision core

Load images


source

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. Can be a string, Path object or a list. apply_reorder: Whether to reorder the data to be closest to canonical (RAS+) orientation. Defaults to False. target_spacing: Whether to resample image to different voxel sizes and image dimensions. Defaults to None. 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.


source

MetaResolver


def MetaResolver(
    args:VAR_POSITIONAL, kwargs:VAR_KEYWORD
):

A class to bypass metaclass conflict: https://pytorch-geometric.readthedocs.io/en/latest/_modules/torch_geometric/data/batch.html


source

MedBase


def MedBase(
    args:VAR_POSITIONAL, kwargs:VAR_KEYWORD
):

A class that represents an image object. Metaclass casts x to this class if it is of type cls._bypass_type.


source

MedImage


def MedImage(
    args:VAR_POSITIONAL, kwargs:VAR_KEYWORD
):

Subclass of MedBase that represents an image object.


source

MedMask


def MedMask(
    args:VAR_POSITIONAL, kwargs:VAR_KEYWORD
):

Subclass of MedBase that represents an mask object.

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)
ax = im.show(anatomical_plane=0)