Connectivity defines which pixels are connected to other pixels.
If the foreground is 4-connected, the image has one background object, all the pixels are set to 0 . 4-connected Pixels are connected if their edges touch. This means that a pair of adjoining pixels are part of the same object only if they are both on and are connected along the horizontal or vertical direction. Pixels are connected if their edges or corners touch. This means that if two adjoining pixels are on, they are part of the same object, regardless of whether they are connected along the horizontal, vertical, or diagonal direction.