Root Mean Square Surface Distance - Mauerer Distances Map. how to calculate it?

Below it’s my code for trying to calculate the symmetric root mean square distance. But I am not getting the right values.
I can’t figure out where is the mistake in my approach.

segmented_surface_mask = sitk.LabelContour(segmentation)
segmented_surface_ref = sitk.LabelContour(reference_segmentation)


# init signed mauerer distance as reference metrics
self.reference_distance_map = sitk.Abs(sitk.SignedMaurerDistanceMap(reference_segmentation, squaredDistance=False, useImageSpacing=True))
self.mask_distance_map = sitk.Abs(sitk.SignedMaurerDistanceMap(segmentation, squaredDistance=False, useImageSpacing=True))

# init label_1 intensity statistics filter
label_intensity_statistics_filter = sitk.LabelIntensityStatisticsImageFilter()
label_intensity_statistics_filter.Execute(segmented_surface_mask, self.reference_distance_map)
label_1 =255
self.n1 = label_intensity_statistics_filter.GetNumberOfPixels(label_1)
label_intensity_statistics_filter.Execute(segmented_surface_ref, self.mask_distance_map)
self.n2 = label_intensity_statistics_filter.GetNumberOfPixels(label_1)

 def get_rms_symmetric_dist(self):      
        '''compute the root mean square distance'''
        
        # square the Mauerer distances
        mask_distance_map_float = sitk.GetArrayFromImage(self.mask_distance_map)
        mask_distance_map_float = np.flip(mask_distance_map_float ,2)
        mask_distance_map_squared =  mask_distance_map_float ** 2
        
        reference_distance_map_float = sitk.GetArrayFromImage(self.reference_distance_map)
        reference_distance_map_float = np.flip(reference_distance_map_float,2)
        reference_distance_map_squared = reference_distance_map_float ** 2
        
        # sum the distances
        mask_distance_map_sum = mask_distance_map_squared.sum()
        reference_distance_map_sum = reference_distance_map_squared.sum()
        
        return np.sqrt(1. / (self.n1 + self.n2)) * np.sqrt(mask_distance_map_sum  + reference_distance_map_sum)

@ral_san
Looking at the get_rms_symmetric_dist function:

  1. Why do you flip the numpy array axis?
  2. You don’t seem to take into account the surfaces, it looks like you are working with the original distance maps.

I have updated the notebook which I am guessing you started with to use symmetric surface distances, see here. It made the code slightly more complex, but not too bad. You should be able to base your code on that example.

Let us know if you encounter any issues.