OPENCV — NORMAL TO BINARY IMAGE CONVERSION.
I am a Youtuber. My channel name is Powerful Learning. I post free certifications, free internships and free webinars.
I have already posted opencv beginner level tutorials and code on medium and Youtube. Kindly take a look
- openv — read,write and show an image -link
- opencv — color image to grayscale image -link
- opencv- to print image property — link
- opencv — Resize an image-link
- opencv — normal image to blurred image -link
- opencv-normal to binary image — link
- opencv- videostreaming (turn on webam) — link
- opencv-moving object detection -link
Code for normal to binary image conversion
import cv2
from google.colab.patches import cv2_imshow
#since google google colab doesnt support cv2.imshow() function you have to import its own cv2_imshow() package
image = cv2.imread(“powerful learning (5).png”)
#upload an sample image in google colab. I have uploaded an image name “powerful learning (5).png”.
grayimage =cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
#converting colored image to grayscale image
thresholdimage = cv2.threshold(grayimage,180,255,cv2.THRESH_BINARY)[1]
#SOURCE, THRESHOLD VALUE, MAXIMUM VALUE, BINARY
#any image pixel’s intensity value greater than the threshold is assigned the maximum intensity (white), or otherwise is assigned the minimum intensity (black)
cv2.imwrite(“TI.png”,thresholdimage)
cv2_imshow(image)
#displaying normal image
cv2_imshow(grayimage)
cv2_imshow(thresholdimage)