Repository navigation
Conversation
| ) | ||
|
|
||
| metatensor = monai.data.MetaTensor( | ||
| self.array.copy(), |
There was a problem hiding this comment.
Are you sure this copy is necessary? I imagine the conversion to metatensor copies anyway and the memcopy could be quite slow, so best to avoid it if possible
| if ensure_channel_first: | ||
| metatensor = monai.transforms.EnsureChannelFirst()(metatensor) |
There was a problem hiding this comment.
If there is a channel dim in the Volume and ensure_channel_first is False, the channel is placed last in the metatensor. I'm not sure this makes sense since torch never uses this format. I think it would be more expected behavior to move it first
There was a problem hiding this comment.
This seems to be consistent with the default behavior that MONAI uses for data loading. I saved a 4D NIfTI with NiBabel since it is also channel last and the LoadImage transform also produces a channel last metatensor without specifying ensure_channel_first=True.
There was a problem hiding this comment.
It is a more sensible default in my opinion, but I think it should follow the behavior of the corresponding MONAI features.
| def to_monai( | ||
| self, | ||
| convert_to_ras: bool = True, | ||
| ensure_channel_first: bool = False, | ||
| ) -> 'monai.data.MetaTensor': # noqa: F821 |
There was a problem hiding this comment.
I think we should probably add an option to squeeze the first spatial dimension (usually the slice dimension) if it is singleton
| if array.ndim > 4: | ||
| raise ValueError( | ||
| 'Monai conversion does not currently support' | ||
| ' volumes with multiple channel dimensions.' | ||
| ) |
There was a problem hiding this comment.
this test could be moved before the detach and numpy conversion
| ) | ||
|
|
||
|
|
||
| try: |
There was a problem hiding this comment.
Do you need to test for ITK too, since you are using the ITKReader?
There was a problem hiding this comment.
The tests are currently run with none of the optional dependencies or with all of them, so there should not be a situation where the test is run and monai is installed but itk is not.
| @@ -0,0 +1,695 @@ | |||
| import numpy as np | |||
There was a problem hiding this comment.
Should probably add a test with ensure_channels_first=True for both a volume with and without a channel dim to check it deals with them correctly
Co-authored-by: Chris Bridge <chrisbridge44@googlemail.com>
…version' into feature/monai_volume_conversion Merge with girhub cli changes
No description provided.