Hi,
I use 3D slicer for a while, but am rather new with the python usage in slicer.
I have to convert a lot of nifti files to dicom-seg format, which is a cumbersome task, so I wanted to do that in a batch as the nifti files with every CT dicom are named the same.
I tried first to do it with one scan and used the following code:
‘’’
import slicer
from DICOMLib import DICOMUtils
import DICOMScalarVolumePlugin
import DICOMSegmentationPlugin
segmentationNode = r’path_to_segmentation_in_nifti’
dicomDataDir = r’path_to_CT_in_dicom’
outputFolder = r’path_to_output_folder’
loadedNodeIDs = # this list will contain the list of all loaded node IDs
with DICOMUtils.TemporaryDICOMDatabase() as db:
DICOMUtils.importDicom(dicomDataDir, db)
patientUIDs = db.patients()
for patientUID in patientUIDs:
loadedNodeIDs.extend(DICOMUtils.loadPatientByUID(patientUID))
Associate segmentation node with a reference volume node
shNode = slicer.vtkMRMLSubjectHierarchyNode.GetSubjectHierarchyNode(slicer.mrmlScene)
referenceVolumeShItem = shNode.GetItemByDataNode(loadedNodeIDs)
studyShItem = shNode.GetItemParent(referenceVolumeShItem)
segmentationShItem = shNode.GetItemByDataNode(segmentationNode)
shNode.SetItemParent(segmentationShItem, studyShItem)
Export to DICOM
exporter = DICOMSegmentationPlugin.DICOMSegmentationPluginClass()
exportables = exporter.examineForExport(segmentationShItem)
for exp in exportables:
exp.directory = outputFolder
exporter.export(exportables)
‘’’
But I get an error when trying to read in the referenceVolume:
Traceback (most recent call last):
File “”, line 1, in
TypeError: GetItemByDataNode argument 1: method requires a VTK object
I’m not sure how to get this NodeIDs into a VTK object. Could anyone help me give the golden tip.
Thanks!