Classical Computer Vision-Based Image Segmentation methods like Thresholding, Region-Based, Edge Detection Based and Morphological Segmentation are explained in 1 post to make a quick start with this domain
Image segmentation is the process of subdivision a digital image into multiple segments (objects). The goal of segmentation is to change the representation of an image into something more meaningful and easier to analyze.
We can assemble different segmentation methods as shown below.
- Classical Computer Vision-Based Approaches
- Region-Based Methods
- Edge / Boundary Based Methods
- Clustering Based Methods
- Neural Networks
In this post, I will review Classical Computer Vision-Based Approaches, you can reach to my Clustering Based Methods post, and stay tuned for Neural Networks post!
Thresholding is the simplest way to segment images by dividing the image pixels into different groups concerning their intensity values. Usually, it’s used to obtain Binary images segmenting the image in two parts. The main idea is to select a threshold T, change the pixel values lower than this threshold value to 0 (background pixel) and the higher ones to 1 (foreground pixel). If you want to keep the image data type, you can select 0 for background pixels and the maximum value you can have with that data type as foreground pixel values. For example, if you work with uint8 data type images, the maximum value that your image pixels can take is 255, so assigning 255 to foreground pixels and 0 for background pixels is an applicable way too.
The threshold value is chosen at the beginning and it can’t be changed during the process. You can manually choose that threshold value or use the Otsu thresholding method to obtain a threshold automatically according to the histogram of your image.
Threshold value T is chosen manually.
You can apply Basic Thresholding very easily using OpenCV’s threshold function with cv2.THRESH_BINARY option.
import numpy as npimg = cv2.imread("dog.jpg", cv2.IMREAD_GRAYSCALE)
_, segmented1 = cv2.threshold(img, 127,255,cv2.THRESH_BINARY)
print(segmented1)cv2.imshow("Segmented Output Image", segmented1)
Here, 127 is the threshold value, 255 is the value to be assigned for foreground pixels.
OpenCV’s threshold function returns a segmented image with the same data type of input image. So if you would like 1…
Continue reading: https://towardsdatascience.com/image-segmentation-with-classical-computer-vision-based-approaches-80c75d6d995f?source=rss—-7f60cf5620c9—4