For the registration of multiple binairy STL files of a femur bone, I want to use Elastix. I need the transformation / rotation matrices as well for the further project. To use Elastix properly I have to convert the STL to a niftii file, so it works with ther program and stays on the same place in the coordinate system. I have a couple questions:
- I’m using the Python code beneath. I’m running it in Visual Studio Code, not in 3D slicer, is that necessary? Maybe that is the reason for the Error. If not, how can I solve the error?
- Is there another easier way to convert the STL to a niftii?
- Is there another easier way to registrate two STL’s (while keeping the same coordinate systems)?
Thanks for your help in advance! Kind Regards.
segmentationNode = util.loadSegmentation(stl_file_name)
outputLabelmapVolumeNode = slicer.mrmlScene.AddNewNodeByClass('vtkMRMLLabelMapVolumeNode')
slicer.modules.segmentations.logic().ExportVisibleSegmentsToLabelmapNode(segmentationNode, outputLabelmapVolumeNode)
slicer.util.saveNode(outputLabelmapVolumeNode, output_file_name)
I get the following error:
**---------------------------------------------------------------------------** **ImportError** Traceback (most recent call last) **
<ipython-input-10-bde7d0eba18b>** in <module> 31 output_file_name **=** **"vol_stat_T_R.nii"** 32 **---> 33** segmentationNode **=** util **.** loadSegmentation **(** stl_file_name **)** 34 outputLabelmapVolumeNode **=** slicer **.** mrmlScene **.** AddNewNodeByClass **(** **'vtkMRMLLabelMapVolumeNode'** **)** 35 slicer **.** modules **.** segmentations **.** logic **(** **)** **.** ExportVisibleSegmentsToLabelmapNode **(** segmentationNode **,** outputLabelmapVolumeNode **)**
**c:\Users\Acer\Desktop\TM-II\Stages-TM\Stage_4\Thijs van Deudekom\Slicer\Base\Python\slicer\util.py** in loadSegmentation **(filename, returnNode)** 796 If returnNode **is** **True** then a status flag **and** loaded node are returned **.** 797 """ **--> 798 ****return****** loadNodeFromFile **(** filename **,** **'SegmentationFile'** **,** **{** **}** **,** returnNode **)** 799 800 **def** loadTransform **(** filename **,** returnNode **=** **False** **)** **:**
**c:\Users\Acer\Desktop\TM-II\Stages-TM\Stage_4\Thijs van Deudekom\Slicer\Base\Python\slicer\util.py** in loadNodeFromFile **(filename, filetype, properties, returnNode)** 629 **:** raises RuntimeError **:** **in** case of failure 630 """ **--> 631 ****from****** Base **.** Python **import** mrml 632 **from** vtk **import** vtkCollection 633 properties **[** **'fileName'** **]** **=** filename **ImportError** : cannot import name 'app' from 'slicer' (C:\Users\Acer\Miniconda3\lib\site-packages\slicer\__init__.py)