OPENCV — NORMAL TO BINARY IMAGE CONVERSION.

Powerful learning
1 min readJan 6, 2023

--

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

  1. openv — read,write and show an image -link
  2. opencv — color image to grayscale image -link
  3. opencv- to print image property — link
  4. opencv — Resize an image-link
  5. opencv — normal image to blurred image -link
  6. opencv-normal to binary image — link
  7. opencv- videostreaming (turn on webam) — link
  8. 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)

--

--

Powerful learning

Mini blog on Free certifications, internships and webinars