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

Differentiate 3D and 2D images in the converter numpy2vtkImage #437

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Enhancements:
- Adds methods to CILviewer and CILviewer2D #425

Bugfix:
- Differentiate 3D and 2D images in the converter `numpy2vtkImage` #437
- Edit slider min value #420
- Fix extent error when user clicks in the viewer to create a box by clicking outside of the image #425
- Fix extent error when user enlarges the box outside the image #425
Expand Down
12 changes: 8 additions & 4 deletions Wrappers/Python/ccpi/viewer/utils/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,17 @@ class Converter(object):

@staticmethod
def numpy2vtkImage(nparray, spacing=(1., 1., 1.), origin=(0, 0, 0), deep=0, output=None):

"""The method converts a numpy array to a vtk image.
The vtk extend is set and needs to differentiate between 3D and 2D images."""
DanicaSTFC marked this conversation as resolved.
Show resolved Hide resolved
shape = numpy.shape(nparray)
if (nparray.flags["FNC"]):

order = "F"
i = 0
k = 2
k = len(shape) - 1
else:
order = "C"
i = 2
i = len(shape) - 1
k = 0

nparray = nparray.ravel(order)
Expand All @@ -117,7 +118,10 @@ def numpy2vtkImage(nparray, spacing=(1., 1., 1.), origin=(0, 0, 0), deep=0, outp
img_data = output

img_data.GetPointData().AddArray(vtkarray)
img_data.SetExtent(0, shape[i] - 1, 0, shape[1] - 1, 0, shape[k] - 1)
if len(shape) == 3:
img_data.SetExtent(0, shape[i] - 1, 0, shape[1] - 1, 0, shape[k] - 1)
elif len(shape) == 2:
img_data.SetExtent(0, shape[i] - 1, 0, shape[k] - 1, 0, 0)
img_data.GetPointData().SetActiveScalars('vtkarray')
img_data.SetOrigin(origin)
img_data.SetSpacing(spacing)
Expand Down
Loading