From 0dc40ebbcec2e9f9c5778074862e225901f701df Mon Sep 17 00:00:00 2001 From: Shelly Belsky Date: Sat, 16 Nov 2024 09:29:43 -0500 Subject: [PATCH] BUG: Fix generated partial volumes misaligned with input volume node This commit fixes how the generated PV tiffs are loaded, to ensure that the partial volume nodes preserve the original RAS/LPS orientation of the input volume node. Previously, the generated tiff files were always loaded in LPS-like orientation (e.g., the IJK-to-RAS Direction Matrix would have -1 in the first two diagonal entries). This would work correctly on most data we have tested against, when the data is also originally in LPS orientation. However, for data this is inherently in RAS directions (e.g., the IJK-to-RAS Direction Matrix would have 1 in the first two diagonal entries), or for cropped volume nodes (cropping is observed to flip the volume from RAS to LPS directions or vice-versa), the loaded PVs would appear misaligned. --- AutoscoperM/AutoscoperM.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/AutoscoperM/AutoscoperM.py b/AutoscoperM/AutoscoperM.py index 71e63ff..aa6dd0e 100644 --- a/AutoscoperM/AutoscoperM.py +++ b/AutoscoperM/AutoscoperM.py @@ -768,9 +768,17 @@ def onLoadPV(self): ) return + # get the IJK to RAS direction matrix from original input volume + parentVolume = self.ui.volumeSelector.currentNode() + parentIJKToRAS = vtk.vtkMatrix4x4() + parentVolume.GetIJKToRASDirectionMatrix(parentIJKToRAS) + for i in range(len(vols)): nodeName = os.path.splitext(os.path.basename(vols[i]))[0] volumeNode = slicer.util.loadVolume(vols[i]) + # ensure we maintain the original RAS/LPS directions from the parent volume + volumeNode.SetIJKToRASDirectionMatrix(parentIJKToRAS) + translationTransformFileName = os.path.join(mainOutputDir, transformSubDir, f"{nodeName}_t.tfm") scaleTranformFileName = os.path.join(mainOutputDir, transformSubDir, f"{nodeName}_scale.tfm") if not os.path.exists(translationTransformFileName):