Mrmr
Mrmr

Reputation: 35

ITK ERROR: MaskNegatedImageFilter(000001D7CB479830): Inputs do not occupy the same physical space

I used a code to compute the 95HD and DSC to assess the segmentaion accuracy of medical image, and the following problem appered "ITK ERROR: MaskNegatedImageFilter(000001D7CB479830): Inputs do not occupy the same physical space!". I was wondeirng whether I should do resampling? does that mean the two segmentaions have to have same physical space?

Here is the code:

def compute_surface_dsc(label_a, label_b, tau=2.0):
    """Compute Surface Dice

    From: Nikolov S et al. Clinically Applicable Segmentation of Head and Neck Anatomy for
    Radiotherapy: Deep Learning Algorithm Development and Validation Study J Med Internet Res
    2021;23(7):e26151, DOI: 10.2196/26151

    Args:
        label_a (sitk.Image): A mask to compare
        label_b (sitk.Image): Another mask to compare
        tau (float): Accepted deviation between contours (in mm)

    Returns:
        float: The Surface DSC between the two labels
    """

    binary_contour_filter = sitk.BinaryContourImageFilter()
    binary_contour_filter.FullyConnectedOn()
    a_contour = binary_contour_filter.Execute(label_a)
    b_contour = binary_contour_filter.Execute(label_b)

    dist_to_a = sitk.SignedMaurerDistanceMap(
        a_contour, useImageSpacing=True, squaredDistance=False
    )

    dist_to_b = sitk.SignedMaurerDistanceMap(
        b_contour, useImageSpacing=True, squaredDistance=False
    )

    b_intersection = sitk.GetArrayFromImage(b_contour * (dist_to_a <= tau)).sum()
    a_intersection = sitk.GetArrayFromImage(a_contour * (dist_to_b <= tau)).sum()

    surface_sum = (
        sitk.GetArrayFromImage(a_contour).sum()
        + sitk.GetArrayFromImage(b_contour).sum()
    )

return (b_intersection + a_intersection) / surface_sum

Upvotes: 0

Views: 33

Answers (1)

Robbie
Robbie

Reputation: 4882

I'm one of the developers of platipy (where this code is from).

Yes, the segmentations need to occupy the same geometry because the function performs operations in image space.

You can resample like this:

label_a = sitk.Resample(label_a, label_b, sitk.Transform(), sitk.sitkNearestNeighbor, 0)

If the segmentations have different resolutions, it's probably better to resample the courser resolution (larger voxel sizes) to the finer resolution (smaller voxel sizes).

Upvotes: 0

Related Questions