diff --git a/CHANGELOG.md b/CHANGELOG.md index 247fd219..36125a0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,11 +3,13 @@ ## v24.0.2 Enhancements: + - Update corner annotation with axis label #433 - Add title to ViewerCoordsDockWidget #422 - Adds methods to CILviewer and CILviewer2D #425 Bugfix: - Hides the slider when one image dimension is 1 #432 + - 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 diff --git a/Wrappers/Python/ccpi/viewer/CILViewer2D.py b/Wrappers/Python/ccpi/viewer/CILViewer2D.py index fd70c031..a84bf127 100644 --- a/Wrappers/Python/ccpi/viewer/CILViewer2D.py +++ b/Wrappers/Python/ccpi/viewer/CILViewer2D.py @@ -1692,7 +1692,8 @@ def createAnnotationText(self, display_type, data): slice_coord = self.style.image2world(slice_coord)[self.getSliceOrientation()] axis_length = self.style.image2world(axis_length)[self.getSliceOrientation()] - 1 data = (round(slice_coord), round(axis_length)) - text = "Slice %d/%d" % data + axis_label = self.axisLabelsText[self.getSliceOrientation()] + text = "%s %d/%d" % (axis_label, data[0], data[1]) else: # In all other cases, we have coordinates, and then we have an extra value diff --git a/Wrappers/Python/ccpi/viewer/utils/conversion.py b/Wrappers/Python/ccpi/viewer/utils/conversion.py index 73f10bb0..8656c649 100644 --- a/Wrappers/Python/ccpi/viewer/utils/conversion.py +++ b/Wrappers/Python/ccpi/viewer/utils/conversion.py @@ -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 extent is set and needs to differentiate between 3D and 2D images.""" 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) @@ -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)