How to use vtkImageConnectivityFilter

This post should help: