-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactoring the image writer modules #3595
Comments
#3443 is now a working POC, it provides (essential new features in
they are non-breaking changes, the primary usage will be: MONAI/monai/transforms/io/array.py Lines 353 to 356 in 3206fa6
and has the basic support for MONAI/tests/test_save_image.py Lines 26 to 32 in 3206fa6
Please let me know any high-level comments, then I'll revise the design and submit smaller PRs to add these components into the core codebase. After these I believe we can deprecate |
Thanks @wyli for the great work to totally enhance our IO part! writer_cls(output_dtype=self.output_dtype, scale=self.scale)
.set_data_array(img, channel_dim=0, squeeze_end_dims=self.squeeze_end_dims)
.set_metadata(meta_dict=meta_data, resample=self.resample, **self.resample_dict)
.write(filename, verbose=self.print_log) I am not sure whether this "Java style" Thanks. |
thanks, it is possible to have a basic approach with the input arguments in one place: write_cls.write(data, meta_dict, channel_dim, resample, filename, ...) but
the current approach divide the routine into |
may want to support metadata from existing objects img = nibabel.load('img')
writer.set_metadata(img) this is not implemented but should be feasible without changing the API |
It's rare in Python, it's more of a C++ thing I felt. I'm not totally sure it's a good pattern or not. A lot of the use cases for this involve making up for a shortcoming in a language which would otherwise force a cumbersome chain of method calls in separate statements. It makes sense when you want to provide an API for a configurable sequence of operations. Other language mechanisms like variable arguments or operator overload can be used instead (C++'s use of Here since any other use beyond these methods being called in this specific sequence isn't probably going to arise with these writers we could just have the call sequence as normal and not worry about returning writer_obj = writer_cls(output_dtype=self.output_dtype, scale=self.scale)
writer_obj.set_data_array(img, channel_dim=0, squeeze_end_dims=self.squeeze_end_dims)
writer_obj.set_metadata(meta_dict=meta_data, resample=self.resample, **self.resample_dict)
writer_obj.write(filename, verbose=self.print_log) |
with the latest from monai.data import ITKReader, ITKWriter
from monai.transforms import LoadImage, SaveImage
loader = LoadImage(reader=ITKReader)
data, meta = loader("avg152T1_LR_nifti.nii.gz")
saver = SaveImage(output_ext=".nrrd", writer=ITKWriter)
saver(data, meta) if you are still interested in converting the format in Project-MONAI/MONAILabel#211 @SachidanandAlle @diazandr3s |
We can start using this from core api directly.. we were waiting for this be available |
This is a follow-up on the image writer of the previous I/O module proposals.
Goal and anticipated benefits
The current image writing module has been primarily built around the NIfTI specifications using the nibabel package as the backend.
The goal is to redesign the module in order to decouple the universal and the backend-specific implementations.
This will make it easier to bring in various writer backends such as ITK-Python, therefore supporting different image formats and more powerful writer module customisations.
related tickets: #2620 #2613 Project-MONAI/MONAILabel#211
proof of concept #3443
Details
The writer module should have (1) universal logic (2) backend-specific logic (3) mechanism for defaulting/selecting backends. Specifically:
(1) In the context of image writing, the universal logic handles the image-related outputs from the deep learning workflows, such as:
(2) The backend-specific logic includes
(3) The backend selection logic operates based on the user-specified parameters, backend system availability, and current system default configurations.
The text was updated successfully, but these errors were encountered: