Numpy array and Compose without LoadImaged #5479
-
Hello, I'm trying to apply the transformations using Compose in a loaded numpy array. It seems to me that some transformation is not done correctly because the prediction result is different when the numpy array is already loaded in memory and I try to apply the transformations. When I use LoadImaged to load Nifti file it works correctly. Is there a better way to use Compose to apply transformations to an array already loaded into memory? The parte of code:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
UPDATE: The problem seems to be that Spacingd needs some information that my dictionary with only numpy array doesn't have.
What information is needed for Spacingd to work? What keys are needed to use in my dictionary? |
Beta Was this translation helpful? Give feedback.
-
Indeed as you've pointed out the transform
Based on this you should have a dictionary item like assuming your monai version is >= 0.9, I think your input should be a MetaTensor rather than a numpy array. The MetaTensor carries the although now looking at the code again I think it should work even without MetaTensor, the affine would just be assumed to be identity so I am guessing you have an older MONAI version and should be fine if you upgrade to at least 0.9 |
Beta Was this translation helpful? Give feedback.
Indeed as you've pointed out the transform
SpacingD
needs some additional meta data beyond just the image array; from the documentation:Based on this you should have a dictionary item like
image_meta_dict
in your data which has anaffine
field... however looking at the code this argument was deprecated since MetaTensor was introduced in MONAI 0.9. (the above documentation blurb needs to be updated-- would be good to open an issue for that)assuming your monai version is >= 0.9, I think your input should be a MetaTensor rather than a …