Binary Morphological Filter with Padding

I am using binary morphological image filter with large structuring element radius to find the convex hull between the lungs.

However I haven’t been able to build a satsfatory convex hull yet as some holes have remained in the processed image. If I increased the structuring element radius beyond a limit I would get segmentation fault.

So I tryed to add some padding, saving the original image in a larger image (10 times larger) with blank space in the borders and tried again to apply the filter with a larger radius.

Yet, the padding does not seem to work as I am only able to apply morphological closing with the same radius as I was using before. I get the error “Failed to allocate memory to an image”.

Am I doing something wrong?

Thanks in advance

Morphological operations with large radii are very slow. But I would not expect them to allocate a lot of memory. You can try the approximation to that by use of signed distance field. You will still need to pad the image to avoid image boundary effects.

How do I use a signed distance field as an approximation to the convex hull ? Thanks!

Hello @Oddone-Scatena,

I believe what you are trying to do is a dilation with a large structuring element. That does not create a convex hull. The usage of a distance map to mimic dilation is straightforward, see SinpleITK code below (it’s in 2D but the usage of the distance map is exactly the same for 2D and 3D):

import SimpleITK as sitk

binary_label_image = sitk.Image([256,256], sitk.sitkUInt8)
binary_label_image[20:50, 25:125] = 1
binary_label_image[70:95, 40:140] = 1

distance_threshold = 20
dilated_binary_label_image = sitk.SignedMaurerDistanceMap(binary_label_image, insideIsPositive=False, squaredDistance=False, useImageSpacing=True)<distance_threshold

1 Like

I assume this zero-initializes the image?


The signed distance field when used 2 times works well producing the convex hull between the lungs and is much more faster than the binary morphological closing filter.

Red is the convex hull and yellow the original lungs.

1 Like