public static int LabelConnectedComponents(ref Bitmap image)
{
AForge.Imaging.Filters.ConnectedComponentsLabeling filter = new AForge.Imaging.Filters.ConnectedComponentsLabeling();
//and apply!
image = filter.Apply(image);
//return object count
return filter.ObjectCount;
}