ITKReader doesn't return numpy array
See original GitHub issueDescribe the bug
Currently, we use the itk.array_view_from_image()
to get data array:
https://github.com/Project-MONAI/MONAI/blob/dev/monai/data/image_reader.py#L316
But actually, it’s not numpy array, so following logic which depends on numpy.ndarray type will fail.
loader = LoadImage()
img, meta = loader(dicom_path)
print(type(img))
Get the output:
<class 'itk.itkPyBufferPython.NDArrayITKBase'>
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
data not read completelyideal = 5734400 : actual = 2700286M ...
Hi @zivy, I am trying to read in and mhd file in pytorch, and convert it to a numpy array that is then...
Read more >Need to transpose array obtained from itk instead of reversing ...
In ITKReader, itk.size(img) should not be reversed since it outputs correct size of an image. Instead, itk.array_view_from_image(img, keep_axes= ...
Read more >Read numpy array image in ITK - python - Stack Overflow
I am trying to figure out how to read an numpy image array into ITK using python and I can't find a way...
Read more >Images - | notebook.community
We have two options for converting from SimpleITK to numpy: GetArrayFromImage(): returns a copy of the image data. You can then freely modify...
Read more >03_Image_Details
We have two options for converting from SimpleITK to numpy: GetArrayFromImage(): returns a copy of the image data. You can then freely modify...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @wyli ,
After some testing, I feel it’s better to also update ITK reader to use
np.asarray()
, because some operations ofNDArrayITKBase
is different fromndarray
, very easy to cause unknown errors. For example:The output is:
The check for
isinstance(mean, np.ndarray)
will fail here.What do you think?
Thanks.
NDArrayITKBase is a subclass of ndarray, shouldn’t we enhance/fix the relevant failing logic instead of converting them to ndarray, is this a duplicate ticket of #2885?