Segment Comparison Tables: more than one comparison in a single table


I’m hugely impressed with SlicerRT’s segment comparison module.
We are fortunate enough to have two independent clinical automatic segmentation algorithms - i’d like to use SlicerRT to compare the homologous structures as part of the commissioning.

At the moment I can only compare one set of structures at a time and copy and paste the results into Excel. I’d like to be able to add subsequent comparisons to the same table.

Or better yet create an extension to compare multiple segments at once - this would have to do some sort of match based on the structure name, then export the results as CSV.

Some advice to get me started would be hugely appreciated.


Operating system: Windows 10
Slicer version: 29738

You can write a short Python script that iterates through the segments and puts the results into a table. There is only a C++ example to do this, but you can run the same in Python, just need to change the syntax (see hints here, you can find lots of Python examples in the script repository, and you can ask questions here if you get stuck at any point).

Just a quick example to get you started:

referenceSegmentationNode = getNode('Segmentation')
referenceSegmentID = referenceSegmentationNode.GetSegmentation().GetSegmentIdBySegmentName("Segment_1")
compareSegmentationNode = getNode('Segmentation')
compareSegmentID = referenceSegmentationNode.GetSegmentation().GetSegmentIdBySegmentName("Segment_2")

paramNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentComparisonNode")

segmentComparisonLogic = slicer.modules.segmentcomparison.logic()

maxHD = paramNode.GetMaximumHausdorffDistanceForBoundaryMm()
averageHD = paramNode.GetAverageHausdorffDistanceForBoundaryMm()
print(f"Maximum Hausdorff distance: {maxHD}")
print(f"Average Hausdorff distance: {averageHD}")

You can add a loop that iterates through all the segments and puts the result into a table node. See example of creating and populating a table node here and here (create columns, add values to columns, then add the columns to the table).