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

Inconsistent conversion of VectorImage to numpy #4646

Closed
ncullen93 opened this issue May 5, 2024 · 2 comments · Fixed by #4648
Closed

Inconsistent conversion of VectorImage to numpy #4646

ncullen93 opened this issue May 5, 2024 · 2 comments · Fixed by #4648
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances
Milestone

Comments

@ncullen93
Copy link

In itk Python, if I have a VectorImage of size (10,10) with 2 channels, then converting it to numpy gives me an array of shape (10,10,2). But if I have a VectorImage with 1 channel, it squeezes that channel and gives me a numpy array of (10,10). Shouldn't the expected behavior be (10,10,1). Or is there a way to ensure this?

import itk
import numpy as np

arr = np.ones((10,10,2))
img = itk.image_from_array(arr, is_vector=True)
arr2 = itk.array_from_image(img)
print(arr2.shape) # (10,10,2)

arr = np.ones((10,10,1))
img = itk.image_from_array(arr, is_vector=True)
arr2 = itk.array_from_image(img)
print(arr2.shape) # (10,10)
@ncullen93 ncullen93 added the type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances label May 5, 2024
Copy link

github-actions bot commented May 5, 2024

Thank you for contributing an issue! 🙏

Welcome to the ITK community! 🤗👋☀️

We are glad you are here and appreciate your contribution. Please keep in mind our community participation guidelines. 📜
Also, please check existing open issues and consider discussion on the ITK Discourse. 📖

This is an automatic message. Allow for time for the ITK community to be able to read the issue and comment on it.

@thewtex thewtex added this to the ITK 5.4.0 milestone May 6, 2024
thewtex added a commit to thewtex/ITK that referenced this issue May 6, 2024
A VectorImage with one component should have a shape with a value of 1
for component. Also make the ndim consistent.

Closes InsightSoftwareConsortium#4646
@thewtex
Copy link
Member

thewtex commented May 6, 2024

Hi, thanks for the nice report! Patch is here: #4648

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants