I want to remove the small connected object from my 3D volume in Python (i.e. objects having less than N adjacent pixels in 3D). I found a relevant example using OpenCV at this link, but the method does not seem to work for 3D objects (it only works on 2D images).
Is there any alternative I can use to remove objects smaller than N adjacent pixels from the input 3D binary mask?
Edit: I found a possible solution that seems to work. I leave it in the answers.