Use orient scaler volume in python interactor for batch processing

Operating system:windows
Slicer version:5.0.3
Expected behavior:i want to orient my .nii volumes to axial dicom volumes in python code but I can not find any example of that. please help me!
Actual behavior:

You can find example of how to export a volume to DICOM using Python in the script repository.

Thank you for your quick response.
i used this code but it export my volume to saggital slices and I want axial slice…
i wrote this for changing to axial but not working and I got the same result as before:

volumeNode = slicer.util.loadVolume(r"F:\arshad\payannameh\New folder (3)\MRI\ADNI_002_S_0413_MR_MPR__GradWarp__B1_Correction__N3_Br_20070821171714281_S22557_I69527.nii", {"name ": ‘alzheimerMRI’})

axialSliceToRas=vtk.vtkMatrix3x3()
sliceNode = getNode(“ADNI_002_S_0413_MR_MPR__GradWarp__B1_Correction__N3_Br_20070821171714281_S22557_I69527”)
red_logic = slicer.app.layoutManager().sliceWidget(“Red”).sliceLogic()
red_cn = red_logic.GetSliceCompositeNode()
red_logic.GetSliceCompositeNode().SetBackgroundVolumeID(sliceNode.GetID())

outputFolder = r"F:\arshad\payannameh\New folder (3)\axial\New folder"

slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(slicer.mrmlScene)
patientItemID = shNode.CreateSubjectItem(shNode.GetSceneItemID(), “test patient”)
studyItemID = shNode.CreateStudyItem(patientItemID, “test study”)
volumeShItemID = shNode.GetItemByDataNode(sliceNode)
shNode.SetItemParent(volumeShItemID, studyItemID)

import DICOMScalarVolumePlugin
exporter = DICOMScalarVolumePlugin.DICOMScalarVolumePluginClass()
exportables = exporter.examineForExport(volumeShItemID)
for exp in exportables:
exp.directory = outputFolder
exp.setTag(‘PatientID’, “test patient”)
exp.setTag(‘StudyID’, “test study”)

exporter.export(exportables)

In addition, can I use orient scaler volume module to achieve my goal?
if yes how to use it in python interaction?

I was able to find the solution with your help:

volumeNode = slicer.util.loadVolume(inputdir)

slicer.util.selectModule('OrientScalarVolume')
orient_scalar = slicer.modules.orientscalarvolume


outputVolume = slicer.vtkMRMLScalarVolumeNode()
slicer.mrmlScene.AddNode(outputVolume)
outputVolume.CreateDefaultDisplayNodes()
outputVolume.SetName("output_orient")

parametersOrient = {}
parametersOrient["inputVolume1"] = volumeNode
parametersOrient["outputVolume"] = outputVolume
parametersOrient["orientation"] = 'Axial'

orientNode = None
orientNode = slicer.cli.runSync(orient_scalar, None, parametersOrient)        
shNode = slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(slicer.mrmlScene)
patientItemID = shNode.CreateSubjectItem(shNode.GetSceneItemID(), "test patient")
studyItemID = shNode.CreateStudyItem(patientItemID, "test study")
volumeShItemID = shNode.GetItemByDataNode(outputVolume)
shNode.SetItemParent(volumeShItemID, studyItemID)

import DICOMScalarVolumePlugin
exporter = DICOMScalarVolumePlugin.DICOMScalarVolumePluginClass()
exportables = exporter.examineForExport(volumeShItemID)
for exp in exportables:
    exp.directory = outputdir
    exp.setTag('PatientID', "test patient")
    exp.setTag('StudyID', "test study")

exporter.export(exportables)
1 Like