Hii,
I am having trouble applying the module in slicer 5.0.2. My situation isthe stl file stores the annotation results of CT data, and I want to convert it to nii format for deep learning.
When i press apply, it saysreferenceVolumeNode = slicer.util.loadVolume(reference_volume_path), which keeps giving me an error about not being able to load noad from file.2
Detailed error:
Traceback (most recent call last):
File “”, line 7, in
File “D:\Slicer 5.0.2\bin\Python\slicer\util.py”, line 908, in loadVolume
return loadNodeFromFile(filename, filetype, properties, returnNode)
File “D:\Slicer 5.0.2\bin\Python\slicer\util.py”, line 681, in loadNodeFromFile
raise RuntimeError(errorMessage)
RuntimeError: Failed to load node from file: D:\change\dicom\2.nii.gz
Below is my code
import os
import slicer
stl_path = r"D:\change\stl"
image_path = r"D:\change\dicom"
out_path = r"D:\change\nii"
patients = os.listdir(stl_path)
for patient in patients:
patient_path = os.path.join(stl_path, patient)
stl_files = os.listdir(patient_path)
output_file_path = os.path.join(out_path, patient)
os.makedirs(output_file_path, exist_ok=True)
reference_volume_path = os.path.join(image_path, patient+“.nii.gz”)
referenceVolumeNode = slicer.util.loadVolume(reference_volume_path)
for stl_file in stl_files:
stl_file_name = os.path.join(patient_path, stl_file)
output_file_name = os.path.join(output_file_path, stl_file[0:-4] + “.nii.gz”)
segmentationNode = slicer.util.loadSegmentation(stl_file_name)
outputLabelmapVolumeNode = slicer.mrmlScene.AddNewNodeByClass(‘vtkMRMLLabelMapVolumeNode’)
slicer.modules.segmentations.logic().ExportVisibleSegmentsToLabelmapNode(segmentationNode, outputLabelmapVolumeNode,
referenceVolumeNode)
slicer.util.saveNode(outputLabelmapVolumeNode, output_file_name)
slicer.mrmlScene.Clear(0)