The process of separating out the parts in an image into distinct connected regions is called segmentation.
It involves partitioning the image into connected regions, each region being homogenous.
The set of all connected pixels with a particular gray level attribute is identified as a region and assigned a unique label.
The gray level threshold is the simplest way to segment a grayscale image into the background and foreground. It converts the grayscale image into a binary image where the foreground is represented by 1s and the background region by 0s.
The thresholding is not very useful when the image is having multiple foreground objects of varying gray levels. An alternative method of segmenting is performing a gray scale histogram.