Skip to content
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

ITK's function image_view_from_array produces 4D image with array of >10*9 inputs. #100

Closed
ViktorvdValk opened this issue Feb 8, 2021 · 5 comments

Comments

@ViktorvdValk
Copy link
Collaborator

This is the cause for the memory error in PR #99

The following script returns an image with DimSize = 10 10 3 2074148458.
While it should return an image with DimSize = 10 10 10 3.

def image_generator_3D(x1, x2, y1, y2, z1, z2):
    image = np.zeros([10, 10, 10], np.float32)
    image[z1:z2, y1:y2, x1:x2] = 1
    return image

vector_of_images = np.zeros([3, 10, 10, 10], np.float32)
i = 0
for x in range(0, 5, 2):
    image = image_generator_3D(x, x+5, x, x+5, x, x+5)
    vector_of_images[i] = image
    i += 1

vector_itk = itk.image_view_from_array(vector_of_images.T)

Or did I make a mistake here?
Note: Making a 3D image from 3 2D images does work this way.

@dzenanz
Copy link
Member

dzenanz commented Feb 8, 2021

If you replace last line by vector_itk = itk.image_view_from_array(vector_of_images), does it work then?

@ViktorvdValk
Copy link
Collaborator Author

ViktorvdValk commented Feb 8, 2021

No, same story. The DimSize of the image is then 10 10 3 1660136737. Different but still too big

@ViktorvdValk
Copy link
Collaborator Author

When I try to acces the first dimension of the vector_itk object (vector_itk[0]) I get this error:

ValueError: cannot reshape array of size 42220276663395900 into shape (1062156621,3,10,10)

While the vector_of_images is a regular numpy nd.array of [10,10,10,3], so the itk.image_view_from_array function is somehow increasing the DimSize of the itkImageF4 object.

@thewtex
Copy link
Member

thewtex commented Feb 9, 2021

This will be addressed with this PR: InsightSoftwareConsortium/ITK#2287

@thewtex
Copy link
Member

thewtex commented Feb 20, 2021

Should be addressed with the update to itk>=5.2rc2.

@thewtex thewtex closed this as completed Feb 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants