Thresholding is a type of image segmentation, where we change the pixels of an image to make the image easier to analyze.
Before we converted the image from RGB to Grayscale and now we will convert the image to binary i.e., the image will only have two colors namely, black and white.
We do this by setting the pixel value to 255(White) if the pixel value is greater than the threshold value and setting the pixel value to 0(Black) otherwise.
# find the best threshold value
# let us take 125 as the best threshold value
thresh = 125# now we compare it with pixel value
# assign the output to a variable 'binary'
binary = pixel_value > image# now to show the output
show_image(binary, 'After thresholding')