In the previous tutorial of Image Processing, we have discussed the blending of the two different images by using various techniques. In this tutorial, we shall get to know about the thresholding of the image.
Generally, the color image is converted to the grayscale image and then changed to the binary image for thresholding. The concept of thresholding will perform the segmentation of the image and then divides the image into parts of various segment colors.
The operation of the thresholding is applied on to the image by converting into the binary image. The word binary represents the two values. Hence, the binary image consists of two specific colours; generally black and white colors.
Now, let us look into an example to understand the concept of thresholding in a better way.
In this example, the image is converted into the binary image, in which the binary image has only two colors, black and white.
Let us briefly discuss the thresholding concepts by executing them in the Jupyter Notebook.
The required packages CV2 and Matplotlib can be imported into the Jupyter Notebook.
Load an image and store it in the variable
Now, view the image using a suitable function
The above image is a coloured image with a different variety of colours. Let us convert the image into the grayscale image.
The grayscale image can be applied with the operation of thresholding by converting into the binary image. To convert the image, need to apply the threshold function and mention the argument values as the image, minimum value, maximum value and the suitable image type as binary to apply the threshold operation.
This minimum value and the maximum value is the range over which the grayscale will have the specific color and out of the range with another binary color. So, the threshold value is mentioned on the range with minimum and maximum values.
The image which is converted into the binary image with threshold operation look in this way.
Similar to the above operation, the inverse operation can also be applied to obtain the binary image with the opposite band of binary colors.
Now, let us import some different image and apply the thresholding over that image accordingly.
Let us convert this image into the binary image, by applying the above discussed threshold function.
Now, let us apply another different function of adaptive thresholding to ensure the better clarity over the image. In this function, you need to mention two more arguments along with that of the previous one, out of which one ensures the block size and other is the constant.
Now, you can blend these two images using the blending concept by addWeighted function as discussed in the previous tutorial.
You can now, blend the two different images with better quality by changing the constant values and the block size by trial and error. So, this way the threshold function is used to generate the binary images accordingly.
This is all about the end of this tutorial. You can check more about the threshold function in the OpenCV documentation. For any sort of doubts or the questions in this tutorial can reach out through the comment box.