Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

OpenCV Image Threshold

OpenCV Image Threshold with What is OpenCV, History, Installation, Reading Images, Writing Images, Resize Image, Image Rotation, Gaussian Blur, Blob Detection, Face Detection and Face Recognition etc.

<< Back to OPENCV

OpenCV Image Threshold

The basic concept of the threshold is that more simplify the visual data for analysis. When we convert the image into gray-scale, we have to remember that grayscale still has at least 255 values. The threshold is converted everything to white or black, based on the threshold value. Let's assume we want the threshold to be 125(out of 255), then everything that was under the 125 would be converted to 0 or black, and everything above the 125 would be converted to 255, or white. The syntax is as follows:

retval,threshold = cv2.threshold(src, thresh, maxValue, cv2.THRESH_BINARY_INV)


src: Source image, it should be a grayscale image.

thresh: It is used to classify the pixel value.

maxVal: It represents the value to be given if the pixel threshold value.

OpenCV provides different styles of threshold that is used as fourth parameter of the function. These are the following:


Let's take a sample input image

OpenCV Image Threshold

We have taken above image as an input. We describe how threshold actually works. The above image is slightly dim and little bit hard to read. Some parts are light enough to read, while other part is required more focus to read properly.

Let's consider the following example:

import cv2
img  = cv2.imread(r'C:\Users\DEVANSH SHARMA\book1.jpg',1)
retval, threshold = cv2.threshold(img, 62, 255, cv2.THRESH_BINARY)
cv2.imshow("Original Image", img)


OpenCV Image Threshold

The above program highlighted the image. Now we can easily read the content of the image.

Next TopicOpenCV Contours

Related Links:

Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf