Error: in arrayFromVolume nshape = tuple(reversed(volumeNode.GetImageData().GetDimensions())) AttributeError: 'NoneType' object has no attribute 'GetDimensions'

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")

:grinning:

The error indicates that the chosen volume is empty (no image data is set). Probably you did not select the correct volume.

Please use the latest Slicer Stable Release. Lots of improvements and fixes have been implemented in the past 1.5 years - maybe one of them will help finding the root cause of the issue more easily.