I am trying to calculate the minimum Hausdorff distance between two segmentations. I am new to coding and wondering if someone can tell me if the code (from the Support discussion thread “Distance between two segments”) as I have it is correct according to the pictured scene:
Segment comparison is for comparing segments, so it assumes that segments are similar, therefore it computes maximum distance.
If you want to compute maximum Hausdorff distance: The methods you found are for low-level manipulations only. Instead, I would recommend to add a new vtkMRMLSegmentComparisonNode to the scene, set all the inputs into that node, and call slicer.modules.segmentcomparison.logic().ComputeDiceStatistics(mySegmentComparisonNode) to compute the results.
If you want to compute minimum distance (e.g., asses safety margin) then you can use ModelToModelDistance extension for that. You can get computed distance values from the model by using slicer.util.arrayFromModelPointData (you can then get the minimum value, a histogram of the distance distribution, etc. using numpy).
Thank you, Dr. Lasso. I wonder if you can help me to understand how to properly use slicer.util.arrayFromModelPointData and numpy to generate these values.
I assigned the model node:
modelNode = slicer.util.getNode(‘facialnerveoutput’) #facialnerveoutput is the output model from the “model to model” extension
Attempted to run:
slicer.util.arrayFromModelPointData(modelNode, ‘array1’)
AND
distances = slicer.util.arrayFromModelPointData (modelNode, ‘Array1’)
In both cases, using ‘modelNode’ or the assigned ‘facialnerveoutput’ node, I receive this error:
Traceback (most recent call last):
File “”, line 1, in
File “C:\Program Files\Slicer 4.10.2\bin\Python\slicer\util.py”, line 855, in arrayFromModelPointData
narray = vtk.util.numpy_support.vtk_to_numpy(arrayVtk)
File “C:\Program Files\Slicer 4.10.2\bin\Lib\site-packages\vtkmodules\util\numpy_support.py”, line 216, in vtk_to_numpy
typ = vtk_array.GetDataType()
AttributeError: ‘NoneType’ object has no attribute ‘GetDataType’
The distance array name is not Array1. Latest Slicer Preview Release provides more meaningful error message if you give incorrect input to arrayFromModelPointData.