-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Closed
Labels
Description
This is a follow-up of #856 to track the progress of a preliminary IO refactoring.
Goal
The main goal of this ticket is to create a file format agnostic wrapper for the image inputs (LoadImage and LoadImaged).
A typical use case (enhancing the current NiftiDataset) is:
train_ds = ImageDataset(images, segs, transform=train_imtrans, seg_transform=train_segtrans)where images and segs are filenames, ImageDataset internally invokes LoadImage.
Or using a generic monai Dataset API, specify the first component of train_imtrans as a LoadImage transform that extracts data array and meta data from the file.
More specifically:
Reader (file format-specific component)
[format]readerare themselves monai data components (users can use the readers without going through theLoadImagelogic), they call external package APIs[format]readershare the same superclassImageReaderinterface (for handling physical/voxel resolution, orientation...)
class ImageReader:
def get_data(self, ...):
# return the data in the designated resolution, orientation,
# image channel selector, the relevant coordinates, datatype
def read(self, ...):
# create an IO object instance or a set of instances- users can make customized
MyReaderby implementing theImageReaderinterface - the customized
MyReadercould be registered with theLoadImagefactory
@register_reader(requires='my_external_library')
class MyReader(ImageReader):
...LoadImage(file format agnostic component)
LoadImageis a monai transformLoadImagedshould return the same underlying data representation dictionary regardless of the image format.LoadImagemay choose a suitable[format]readerdynamically at runtime based on the following rules (ordered from high to low priority):
- user's selection of a specific reader, such as
LoadImage(reader='ITkReader') - try any user-registered readers
- try resources map based on a global property file and filename extensions:
MONAI.IO
{
FOO LoadFOO
PNG ITK/5.1/LoadITK
TIFF,TIF ITK/5.1/LoadITK
* ITK/5.1/LoadITK
}
- fails early and preserves detailed error messages
additional requirements
- should be able to specify versions of external reader to ensure reproducibility
- need to have consistent coordinate systems, resolution conventions
tasks
- implement interface
ImageReader, factory (transforms)LoadImageLoadImaged - implement ITKReader, NibabelReader, NumpyReader, PILReader?
-
LoadImageselecting readers according to the preference list - new interfaces tutorial 17 Add load medical image notebook tutorials#19
- deprecate
NiftiDataset, addImageDataset - deprecate
LoadNifti,LoadPNG,LoadNumpy,LoadDatad - revise/check all examples demos
aylward