Plastimatch and Python Interactor

Hello Community,

I have a (maybe easy) basic question to the Python Interactor in 3D Slicer/ SlicerRT. I want to know, which kind of the average Hausdorff-Distance the SlicerRT extension calculate (e.g. directed average or undirected average or undirected max average Hausdorff-distance).
Therefore I try to calculate the HD with the Python Interactor in 3D Slicer with the commands of Plastimatch (and compare with my manual calculation), but it doesn’t work. May somebody show me, how can I use the Plastimatch-commands in the Interactor (e.g. get_avg_average_hausdorff)?

Thank you very much!

Unfortunately you can’t call plastimatch functions from python. Those functions are not python wrapped. But you can see which functions are called here:

Thanks for the quick answer.

So did I understood it right, that the average HD in Slicer represent the sum of all minimum distances from the external contour-pixels/ voxels of one contour/ segment to the pixel/ voxel of the external border of the other contour divided by the number of pixels from the first contour (or sum of all pixels of both contours?)? = directed average HD
After that the same steps are repeated for the other contour and the sum of both (directed) distances divided by 2 or did Slicer take the maximum of the two directed distances? = undirected average HD

Thanks in advance!

It works like this:

  1. For each boundary point of the compare image, find the closest boundary point on the reference image. Then take the average of these distances.
  2. For each boundary point of the reference image, find the closest boundary point on the compare image. Then take the average of these distances.
  3. Take the average of the numbers computed in step 1 and step 2.
1 Like

All computations that Slicer can perform are accessible from Python, too.

For example, you can compute metric by calling SegmentComparison module logic and retrieve results from the associated vtkMRMLSegmentComparisonNode.

Thanks for the information.

Unfortunately I can’t call these SegmentComparison module logic’s (“std::string ComputeHausdorffDistances(vtkMRMLSegmentComparisonNode* parameterNode);”) in the Python-Interactor. First I included the “slicer includes”, after that I created a segmentation from a LabelMap-volume (created in segmentations-module) as you showed in a thread before: “https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Create_a_segmentation_from_a_labelmap_volume_and_display_in_3D” (is the “parameterNode” == this segmentation?).

May you can give me an example how I can input the syntax for this, please?

Thank you!

Please note the signature of the function. It takes a vtkMRMLSegmentComparisonNode, which is a parameter set node containing the parameters of a segment comparison run. Now if you look at this class


then you’ll see what inputs you can set to it and what outputs you gan get after the calculation.

Thanks for the help! Sorry, that I have to ask again to this…

First, I get every time an error message, when I want to get my reference segmentation node (segmentation* GetReferenceSegmentationNode();). Do I understood it right, that my “vtkMRMLSegmentationNode” = my active Segmentation (which contains the two segments for calculation of Hausdorff/ Dice…)?
Furthermore I get the error message, that the name “SetAndObserveReferenceSegmentationNode” is not defined, when I want to set my reference segmentation node…

May you show me my mistake or are there any special packages necessary, which I have to include/ install/ import?

This function from an actual working module should help:

OK, I think I got it, thank you very much!

I just have one more question to the segmentation node. May you explain me, what the “usSegmentationNode” or “mrSegmentationNode” is in your code:
self.segmentComparisonNode.SetAndObserveReferenceSegmentationNode(self.usSegmentationNode)
I thought this are the segments in the active segmentation…

This particular module compares segments from two different segmentations, one done on ultrasound (US) and the other on MR.

ok, I mean what is the input of this module.
So how I get a “usSegmentationNode” and a “mrSegmentationNode”?
Do I need two different segmentations or is it enough to have two segments to compare in one segmentation?

You can find information about this module here

There is a tutorial as well that shows you how it is used.

You can compare any two segments.

Ah ok it is this module. Is there any way to compute the Hausdorff-distances with the “Segment Comparison” - module in the python interactor as you can see here:
Bildschirmfoto 2020-05-20 um 14.11.04

I want to calculate the Hausdorff-distances for volume and not for boundary which is the default one in SlicerRT (in my example segment it would be probably the same as boundary HD, but I want to use the volume HD for an other case). Therefore I tried to do this with the python-interactor…

You have all the information for this above. Please take a look at the settings vtkMRMLSegmentComparisonNode offers.

By definition, Hausdorff distance is between boundary surfaces, so you have to provide them as inputs. Even if you think that the boundary is a trivial one, such as bone surface or skin surface, you still need to specify it (for example, by creating a segment with thresholding).

As I understand, Hausdorff distance is defined between two sets. Surface boundary is most common, but it is not the only choice.

1 Like

Hello everyone

I came across your discussion since I have a relative easy question to ask: I dowloaded the Plastimatch in 3D slicer and I would like to ask how I can use it to compare segmentations using the mean surface distance ?

I was trying to find a script online but I could not find any script which I can trust totally…

Thank you for your time reading my message:)

I assume this means that you installed the SlicerRT extension. I suggest you use the Segment Comparison module and use the mean Hausdorff metric to achieve the same result.

Hello and thanks for your answer.

As you said,yes I installed the extension in Slicer.

So regarding your answer, why the mean Hausdorff distance is the same as the mean surface distance ? The answer might be obvious but since I have not searched it yet,that is why I am asking.:slightly_smiling_face:

Στις Παρ, 24 Φεβ 2023, 16:18 ο χρήστης Csaba Pinter via 3D Slicer Community <notifications@slicer.discoursemail.com> έγραψε: