Skip to content

Commit

Permalink
BUG: Fix generated partial volumes misaligned with input volume node (#…
Browse files Browse the repository at this point in the history
…147)

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.

Note: Since TIFF files don't store the directions of the volume node,
volume files opened in Slicer through the "Add Data" widget are not 
guaranteed to be loaded with the right IJK-to-RAS directions. For this 
reason, the generated volumes must be imported using the "Load Partial 
Volumes" button under the "Partial Volume Generation" group when the 
corresponding input volume node is selected in the Pre-Processing 
module.
  • Loading branch information
sbelsk authored Nov 20, 2024
1 parent 9792ad0 commit 54d8daa
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions AutoscoperM/AutoscoperM.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,19 @@ 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)

# check 3 transform files have been generated (translation, scale and combined)
# and load only the combined scale and translation transform for each generated partial volume
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")
transformFileName = os.path.join(mainOutputDir, transformSubDir, f"{nodeName}.tfm")
Expand Down

0 comments on commit 54d8daa

Please sign in to comment.