# stl file stores the annotation results of CT data, and I want to convert it to nii format for deep learning.

**URL:** <https://discourse.slicer.org/t/stl-file-stores-the-annotation-results-of-ct-data-and-i-want-to-convert-it-to-nii-format-for-deep-learning/27898>\
**Category:** Support\
**Tags:** segmentation, dicom, python, 3d-model\
**Created:** [February 18, 2023, 4:53am UTC](https://discourse.slicer.org/t/stl-file-stores-the-annotation-results-of-ct-data-and-i-want-to-convert-it-to-nii-format-for-deep-learning/27898 "2023-02-18T04:53:18Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![missile](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/missile/32/18447_2.png) [@missile](https://discourse.slicer.org/u/missile)\
**Post date:** [February 17, 2023, 5:18pm UTC](https://discourse.slicer.org/t/stl-file-stores-the-annotation-results-of-ct-data-and-i-want-to-convert-it-to-nii-format-for-deep-learning/27898/2 "2023-02-17T17:18:19Z")

</div>

Hello sir, I don’t know if you have time, but I would like to ask you a question.

My situation is the same as yours, the stl file stores the annotation results of CT data, and I want to convert it to nii format for deep learning. I reproduced the code from your post into the Python interactor in slicer, but I keep getting

referenceVolumeNode = slicer.util.loadVolume(reference\_volume\_path), which keeps giving me an error about not being able to load noad from file.

I’m very confused and I’m looking forward to your help when you have time.

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)

---

_[View the full topic](https://discourse.slicer.org/t/stl-file-stores-the-annotation-results-of-ct-data-and-i-want-to-convert-it-to-nii-format-for-deep-learning/27898)._
