Hello everyone and expert
slicer 4.11.20210226
I wanna get the coordinates and HU data from my segment. i wrote a script to use python. but there is a problem. it occurs an Error: Traceback (most recent call last):
- File “”, line 1, in *
- File “D:\3D\Slicer 4.11.20210226\bin\Python\slicer\util.py”, line 1439, in arrayFromVolume*
- nshape = tuple(reversed(volumeNode.GetImageData().GetDimensions()))*
AttributeError: ‘NoneType’ object has no attribute ‘GetDimensions’
i found out all the forum and didnt get an answer about it. could u help me? Thanks a lot in advance!
my script:
segmentationNode =slicer.mrmlScene.GetNodeByID("kortikalis")
masterVolumeNode = slicer.util.getNode("8: Schulter li. 3.0 sag - imageType DERIVED-PRIMARY-AXIAL-CT_SOM5 SPO")
labelmapVolumeNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLLabelMapVolumeNode")
slicer.modules.segmentations.logic().ExportVisibleSegmentsToLabelmapNode(segmentationNode,labelmapVolumeNode,masterVolumeNode)
volumeArray = slicer.util.arrayFromVolume(masterVolumeNode)
labelArray = slicer.util.arrayFromVolume(labelmapVolumeNode)
labelValue = slicer.mrmlScene.GetNodeByID('LabelMapVolume')
segmentVoxels = volumeArray[labelArray==labelValue]
import numpy as np
coordinates = np.where(labelArray==labelValue)
hu = volumeArray[coordinates]
coordinateWithHU = np.zeros([len(coordinates[0]),4])
coordinateWithHU[:,0:3] = np.array(coordinates).T
coordinateWithHU[:,3] = hu
slicer.util.pip_install('pandas')
import pandas as pd
pd.DataFrame(coordinateWithHU).to_csv("c:/tmp/coordshu.csv")