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”.
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.
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):
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.