Filter for deleting isolated voxels

I have a voxel representation of a volume (mask) and I need to clean all the voxels that are not connected to the main volume.
I was wondering if there is an existing filter that could help me identify isolated voxels in mask vti or vtp data.
Is there anything that could help me with this? Preferably in VTK JS but C++ would work too.

A connectivity filter ( like vtkImageConnectivityFilter) is close to what you describe. It will assign distinct labels to connected regions of the image. You can then pick the ones you want. Make sure to also check vtkImageConnectivityFilter::SetExtractionModeToLargestRegion() as well as earlier posts on discourse . I haven’t checked with vtk.js but I expect this filters to be available.