From 4241540933befe0db5c33c8034c55c579c2ce6fd Mon Sep 17 00:00:00 2001 From: DanicaSTFC <138598662+DanicaSTFC@users.noreply.github.com> Date: Tue, 27 Aug 2024 16:42:49 +0100 Subject: [PATCH 1/2] Differentiate 3D and 2D images in the converter `numpy2vtkImage` (#437) --- CHANGELOG.md | 1 + Wrappers/Python/ccpi/viewer/utils/conversion.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9040b5a..a1279070 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 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) From 1bcf7a3da8dd8cd8fd865516bc235751b95baef3 Mon Sep 17 00:00:00 2001 From: DanicaSTFC <138598662+DanicaSTFC@users.noreply.github.com> Date: Tue, 27 Aug 2024 16:45:27 +0100 Subject: [PATCH 2/2] Update corner annotation with axis label (#433) --- CHANGELOG.md | 1 + Wrappers/Python/ccpi/viewer/CILViewer2D.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1279070..1b043447 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## v24.0.2 Enhancements: + - Update corner annotation with axis label #433 - Add title to ViewerCoordsDockWidget #422 - Adds methods to CILviewer and CILviewer2D #425 diff --git a/Wrappers/Python/ccpi/viewer/CILViewer2D.py b/Wrappers/Python/ccpi/viewer/CILViewer2D.py index 38a47d8b..90be5929 100644 --- a/Wrappers/Python/ccpi/viewer/CILViewer2D.py +++ b/Wrappers/Python/ccpi/viewer/CILViewer2D.py @@ -1682,7 +1682,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