I/O

input/output management

ScalarImage

 ScalarImage (*args, **kwargs)

Image whose pixel values represent scalars.

See :class:~torchio.Image for more information.

Image Readers


source

tiff2torch

 tiff2torch (file_path:str)

Load tiff into pytorch tensor


source

aics_image_reader

 aics_image_reader (path)

*Reads an image from the specified path using AICSImage library.

Parameters: path (str): The file path to the image.

Returns: tuple: A tuple containing the image data and its affine transformation matrix. The image data is a NumPy array representing the image. The affine transformation matrix is a 4x4 NumPy array.*

Details
path The file path to the image
file_path = 'data_examples/example_tiff.tiff'
test_img, _ = aics_image_reader(file_path)
test_img.shape

Hierarchical Data Format


source

split_hdf_path

 split_hdf_path (file_path,
                 hdf5_exts:(<class'fastcore.foundation.L'>,<class'list'>)=
                 ['.h5', '.hdf5'])
Type Default Details
file_path The path to the HDF5 file to split
hdf5_exts (<class ‘fastcore.foundation.L’>, <class ‘list’>) [‘.h5’, ‘.hdf5’] List of filename extensions

source

hdf5_reader

 hdf5_reader (dataset=None, patch=0,
              hdf5_exts:(<class'fastcore.foundation.L'>,<class'list'>)=['.
              h5', '.hdf5'])

Initialize self. See help(type(self)) for accurate signature.

Type Default Details
dataset NoneType None The dataset to load
patch int 0 The patch to load from the dataset
hdf5_exts (<class ‘fastcore.foundation.L’>, <class ‘list’>) [‘.h5’, ‘.hdf5’] List of filename extensions

Images can be loaded by explicitly writing dataset name and path number…

from bioMONAI.visualize import plot_image
file_path = './data_examples/0450_1.hdf5'
dataset_name='clean'
patch_num=10

im , _ = hdf5_reader(dataset=dataset_name, patch=patch_num)(file_path)
plot_image(im[0])

… or enconding them in the path, where datasets are subfolders and patches the image files. The latter being compatible with image_reader syntaxis.

f = file_path + '/' + dataset_name + '/' + '%d'%(patch_num)
im , _ = hdf5_reader()(f)
plot_image(im[0])

Preprocessing

Load and preprocess

org_img, _, _ = _load_and_preprocess(f)

test_eq(org_img.data[0].shape, im.shape)

Read multichannel data

t = _multi_channel([f], only_tensor=True);
test_eq(t[0].shape, im.shape)
t.shape

Image reader


source

image_reader

 image_reader (file_path:(<class'str'>,<class'pathlib.Path'>,<class'fastco
               re.foundation.L'>,<class'list'>), dtype=<class
               'torch.Tensor'>, only_tensor:bool=True, **kwargs)

*Loads and preprocesses a medical image.

Args: file_path: Path to the image. Can be a string, Path object or a list. dtype: Datatype for the return value. Defaults to torchTensor. reorder: Whether to reorder the data to be closest to canonical (RAS+) orientation. Defaults to False. resample: Whether to resample image to different voxel sizes and image dimensions. Defaults to None. only_tensor: To return only an image tensor. Defaults to True.

Returns: The preprocessed image. Returns only the image tensor if only_tensor is True, otherwise returns original image, preprocessed image, and original size.*

Type Default Details
file_path (<class ‘str’>, <class ‘pathlib.Path’>, <class ‘fastcore.foundation.L’>, <class ‘list’>) Path to the image
dtype _TensorMeta Tensor Datatype for the return value. Defaults to torchTensor
only_tensor bool True To return only an image tensor
kwargs
test_eq(image_reader(f)[0].shape, im.shape)