

{"id":120210,"date":"2024-03-06T18:00:10","date_gmt":"2024-03-06T12:30:10","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=120210"},"modified":"2024-03-06T18:53:35","modified_gmt":"2024-03-06T13:23:35","slug":"image-thresholding-in-opencv","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/image-thresholding-in-opencv\/","title":{"rendered":"Image Thresholding in OpenCV"},"content":{"rendered":"<p>Unravel the hidden patterns within images and unlock the magic of image segmentation with the power of Thresholding in OpenCV. From transforming grayscale wonders into clear-cut binary visions to conquering complex computer vision challenges.<\/p>\n<p>This article will guide you through the art of Thresholding, offering insights into its versatile techniques and applications. Get ready to witness the visual world through a new lens as we delve into the captivating realm of Thresholding magic!<\/p>\n<p>Thresholding, in simple words, is a technique used in image processing to convert a grayscale or color image into a binary image. It involves setting a specific threshold value, and any pixel intensity in the original image that is above the threshold is converted to one value (often white), while any pixel intensity below the threshold is converted to another value (often black).<\/p>\n<p>We&#8217;ll also learn how to use the built-in copyMakeBorder() function of the OpenCV package to add a border to an image.<\/p>\n<h2>Simple Thresholding in OpenCV: An Introduction to the World of Image Segmentation<\/h2>\n<p>In the fascinating realm of image processing, simple thresholding stands as one of the fundamental techniques for image segmentation. It allows us to convert grayscale images into binary images, where each pixel is assigned one of two values based on a predefined threshold. This powerful method comes with various types and parameters that cater to different scenarios, making it a versatile tool in computer vision applications.<\/p>\n<h3>Types of Simple Thresholding in OpenCV:<\/h3>\n<h4>1. Binary Thresholding: cv2.THRESH_BINARY<\/h4>\n<p>In binary thresholding, each pixel&#8217;s intensity is compared to a fixed threshold value. If the pixel intensity is higher than the threshold, it is set to a maximum value (commonly 255, representing white); otherwise, it is set to a minimum value (often 0, representing black).<\/p>\n<h4>2. Inverse Binary Thresholding: cv2.THRESH_BINARY_INV<\/h4>\n<p>Similar to binary thresholding, the roles of black and white are reversed. Pixels with intensities greater than the threshold become black, while those below the threshold become white.<\/p>\n<h4>3. Truncated Thresholding: cv2.THRESH_TRUNC<\/h4>\n<p>In truncated thresholding, pixel values above the threshold are set to the threshold value itself. This creates a flat region at the threshold level.<\/p>\n<h4>4. Tozero Thresholding: cv2.THRESH_TOZERO<\/h4>\n<p>Here, pixel values below the threshold are set to zero, while those above the threshold remain unchanged.<\/p>\n<h4>5. Tozero Inverse Thresholding: cv2.THRESH_TOZERO_INV<\/h4>\n<p>The opposite of tozero thresholding. Pixel values above the threshold are set to zero, and those below the threshold remain unchanged.<\/p>\n<p><strong>Syntax and Parameters:<\/strong><\/p>\n<p><strong>The syntax for applying simple thresholding in OpenCV is as follows:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">retval, threshold_output = cv2.threshold(input_image, threshold_value, max_value, threshold_type)<\/pre>\n<ul>\n<li><strong>Retval:<\/strong> The threshold value that was used. This may be important when using adaptive thresholding methods.<\/li>\n<li><strong>Threshold_output:<\/strong> The output binary image after thresholding.<\/li>\n<li><strong>Input_image:<\/strong> The input grayscale image on which thresholding is applied.<\/li>\n<li><strong>Threshold_value:<\/strong> The threshold value to be used for comparison.<\/li>\n<li><strong>Max_value:<\/strong> The maximum value assigned to pixels that satisfy the thresholding condition (usually 255 for white).<\/li>\n<li><strong>Threshold_type:<\/strong> The type of thresholding method to be used (e.g., cv2.THRESH_BINARY, cv2.THRESH_BINARY_INV, etc.).<\/li>\n<\/ul>\n<p><strong>Code with Explanation:<\/strong><\/p>\n<p><strong>Let&#8217;s illustrate simple thresholding using binary thresholding as an example:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import cv2\r\nimport numpy as np\r\n\r\n# Read the grayscale image\r\nimage = cv2.imread(r\"C:\\Users\\sanji\\Desktop\\DataFlair\\Thresholding in Opencv\\nature-img.jpg\", cv2.IMREAD_GRAYSCALE)\r\n\r\n# Threshold values\r\nthreshold_value = 150\r\nmax_value = 255\r\n\r\n\r\n\r\n# Binary Thresholding\r\n_, binary_threshold_output = cv2.threshold(image, threshold_value, max_value, cv2.THRESH_BINARY)\r\n\r\n# Inverse Binary Thresholding\r\n_, inverse_binary_threshold_output = cv2.threshold(image, threshold_value, max_value, cv2.THRESH_BINARY_INV)\r\n\r\n# Truncated Thresholding\r\n_, truncated_threshold_output = cv2.threshold(image, threshold_value, max_value, cv2.THRESH_TRUNC)\r\n\r\n# Tozero Thresholding\r\n_, tozero_threshold_output = cv2.threshold(image, threshold_value, max_value, cv2.THRESH_TOZERO)\r\n\r\n# Tozero Inverse Thresholding\r\n_, tozero_inverse_threshold_output = cv2.threshold(image, threshold_value, max_value, cv2.THRESH_TOZERO_INV)\r\n\r\n# Create a window for each type of thresholding\r\ncv2.namedWindow('Binary Thresholding', cv2.WINDOW_NORMAL)\r\ncv2.namedWindow('Inverse Binary Thresholding', cv2.WINDOW_NORMAL)\r\ncv2.namedWindow('Truncated Thresholding', cv2.WINDOW_NORMAL)\r\ncv2.namedWindow('Tozero Thresholding', cv2.WINDOW_NORMAL)\r\ncv2.namedWindow('Tozero Inverse Thresholding', cv2.WINDOW_NORMAL)\r\n\r\n# Display the thresholded images\r\ncv2.imshow('Binary Thresholding', binary_threshold_output)\r\ncv2.imshow('Inverse Binary Thresholding', inverse_binary_threshold_output)\r\ncv2.imshow('Truncated Thresholding', truncated_threshold_output)\r\ncv2.imshow('Tozero Thresholding', tozero_threshold_output)\r\ncv2.imshow('Tozero Inverse Thresholding', tozero_inverse_threshold_output)\r\n\r\ncv2.waitKey(0)\r\ncv2.destroyAllWindows()<\/pre>\n<p><strong>Original Image :<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Thresholding-original-image-.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-125867 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Thresholding-original-image-.webp\" alt=\"Thresholding original image\" width=\"800\" height=\"700\" \/><\/a><\/p>\n<p><strong>Binary<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Binary-thresholding.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-125868 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Binary-thresholding.webp\" alt=\"Binary thresholding\" width=\"378\" height=\"432\" \/><\/a><\/p>\n<p><strong>Inverse Binary<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Inverse-Binary-thresholding.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-125869 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Inverse-Binary-thresholding.webp\" alt=\"Inverse Binary thresholding\" width=\"381\" height=\"383\" \/><\/a><\/p>\n<p><strong>Truncated<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Truncated-thresholding-.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-125870 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Truncated-thresholding-.webp\" alt=\"Truncated thresholding\" width=\"377\" height=\"382\" \/><\/a><\/p>\n<p><strong>Tozero<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Tozero-thresholding.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-125874 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Tozero-thresholding.webp\" alt=\"Tozero thresholding\" width=\"378\" height=\"382\" \/><\/a><\/p>\n<p><strong>Tozero inverse<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Tozero-inverse-thresholding-.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-125873 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Tozero-inverse-thresholding-.webp\" alt=\"Tozero inverse thresholding\" width=\"380\" height=\"383\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>In this code, we read a grayscale image and then apply all five types of simple thresholding using the cv2.threshold() function. We create a separate window for each thresholding output and display them using the cv2.imshow() function. The images will be displayed one after the other, and you can close the window by pressing any key.<\/p>\n<h3>Adaptive Thresholding in OpenCV: Mastering Image Segmentation with Dynamic Thresholds<\/h3>\n<p>In the ever-evolving world of image processing, adaptive thresholding stands as a versatile technique for tackling varying lighting conditions and image complexities. Unlike simple thresholding, where a fixed threshold is applied globally to the entire image, adaptive thresholding employs dynamic thresholds at each pixel&#8217;s local neighborhood. This adaptive nature empowers the algorithm to adapt to local changes, making it highly effective in scenarios with uneven illumination and varying contrasts.<\/p>\n<p><strong>Types of Adaptive Thresholding and Their Functions in OpenCV:<\/strong><\/p>\n<h4>1. Adaptive Mean Thresholding: cv2.ADAPTIVE_THRESH_MEAN_C<\/h4>\n<p>Calculates the mean of the pixel intensities in a local neighborhood and uses it as the threshold value. Each pixel is compared to its local mean, which helps in handling varying illumination conditions.<\/p>\n<h4>2. Adaptive Gaussian Thresholding: cv2.ADAPTIVE_THRESH_GAUSSIAN_C<\/h4>\n<p>Identical to adaptive mean thresholding, but uses a Gaussian window to derive the threshold value based on the weighted sum of the pixel intensities in the immediate area rather than the mean.<\/p>\n<p><strong>Syntax and Parameters:<\/strong><\/p>\n<p><strong>The syntax for applying adaptive thresholding in OpenCV is as follows:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">threshold_output = cv2.adaptiveThreshold(input_image, max_value, adaptive_method, threshold_type, block_size, constant_value)<\/pre>\n<ul>\n<li><strong>Threshold_output:<\/strong> The output binary image after adaptive thresholding.<\/li>\n<li><strong>Input_image:<\/strong> The input grayscale image on which adaptive thresholding is applied.<\/li>\n<li><strong>Max_value:<\/strong> The maximum value assigned to pixels that satisfy the adaptive thresholding condition (usually 255 for white).<\/li>\n<li><strong>Adaptive_method:<\/strong> The method used to calculate the adaptive threshold. It can be cv2.ADAPTIVE_THRESH_MEAN_C or cv2.ADAPTIVE_THRESH_GAUSSIAN_C.<\/li>\n<li><strong>Threshold_type:<\/strong> The type of thresholding method to be used within the adaptive region (e.g., cv2.THRESH_BINARY, cv2.THRESH_BINARY_INV, etc.).<\/li>\n<li><strong>Block_size:<\/strong> The size of the local neighborhood (should be an odd integer).<\/li>\n<li><strong>constant_value:<\/strong> A constant value subtracted from the mean or weighted sum (only necessary for `cv2.ADAPTIVE_THRESH_MEAN_C`).<\/li>\n<\/ul>\n<p><strong>Code with Explanation:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import cv2\r\n\r\n# Read the grayscale image\r\nimage = cv2.imread(r\"C:\\Users\\sanji\\Desktop\\DataFlair\\Thresholding in Opencv\\nature-img.jpg\", cv2.IMREAD_GRAYSCALE)\r\n\r\n# Maximum pixel value for the thresholded image\r\nmax_value = 255\r\n\r\n# Adaptive Mean Thresholding\r\nblock_size_mean = 11\r\nconstant_value_mean = 2\r\nadaptive_mean_output = cv2.adaptiveThreshold(image, max_value, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, block_size_mean, constant_value_mean)\r\n\r\n# Adaptive Gaussian Thresholding\r\nblock_size_gaussian = 11\r\nconstant_value_gaussian = 2\r\nadaptive_gaussian_output = cv2.adaptiveThreshold(image, max_value, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, block_size_gaussian, constant_value_gaussian)\r\n\r\n# Create windows for each type of adaptive thresholding\r\ncv2.namedWindow('Adaptive Mean Thresholding', cv2.WINDOW_NORMAL)\r\ncv2.namedWindow('Adaptive Gaussian Thresholding', cv2.WINDOW_NORMAL)\r\n\r\n# Display the adaptive thresholded images\r\ncv2.imshow('Adaptive Mean Thresholding', adaptive_mean_output)\r\ncv2.imshow('Adaptive Gaussian Thresholding', adaptive_gaussian_output)\r\n\r\ncv2.waitKey(0)\r\ncv2.destroyAllWindows()<\/pre>\n<p><strong>Original Image :<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Adaptive-Gaussian-Thresholding.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-125876 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Adaptive-Gaussian-Thresholding.webp\" alt=\"Adaptive Gaussian Thresholding\" width=\"800\" height=\"700\" \/><\/a><\/p>\n<p><strong>Adaptive Mean Thresholding :<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Adaptive-Mean-Thresholding-.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-125877 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Adaptive-Mean-Thresholding-.webp\" alt=\" Adaptive Mean Thresholding \" width=\"375\" height=\"385\" \/><\/a><\/p>\n<p><strong>Adaptive Gaussian Thresholding :<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Adaptive-Gaussian-Thresholding-.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-125878 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Adaptive-Gaussian-Thresholding-.webp\" alt=\"Adaptive Gaussian Thresholding\" width=\"377\" height=\"386\" \/><\/a><\/p>\n<p>In this code, we read a grayscale image and then apply both types of adaptive thresholding using the cv2.adaptiveThreshold() function. We create separate windows for each adaptive thresholding output and display them using the cv2.imshow() function. The images will be displayed one after the other, and you can close the window by pressing any key.<\/p>\n<h3>Adding Borders in OpenCV: Amplifying Image Boundaries with copyMakeBorder() :<\/h3>\n<p>In the realm of image processing, adding borders to an image plays a crucial role in various applications. OpenCV offers a powerful function called copyMakeBorder(), which allows you to expand the image canvas and create a border of desired size and style. This function acts as a shield, safeguarding the image from unintended distortions and enhancing its visual appearance.<\/p>\n<p><strong>Syntax and Parameters:<\/strong><\/p>\n<p><strong>The syntax for using copyMakeBorder() in OpenCV is as follows:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">border_image = cv2.copyMakeBorder(src, top, bottom, left, right, border_type, value)<\/pre>\n<ul>\n<li><strong>Border_image:<\/strong> The output image with added borders.<\/li>\n<li><strong>Src:<\/strong> The input image to which borders are added.<\/li>\n<li><strong>top, bottom, left, right:<\/strong> The number of pixels to be added at the top, bottom, left, and right sides, respectively.<\/li>\n<li><strong>Border_type:<\/strong> The type of border to be added. It can be one of the following:<\/li>\n<li><strong> cv2.BORDER_CONSTANT:<\/strong> Adds a constant colored border. Use the value parameter to specify the color.<\/li>\n<li><strong> cv2.BORDER_REPLICATE:<\/strong> Replicates the edge pixels to form a border.<\/li>\n<li><strong> cv2.BORDER_REFLECT:<\/strong> Reflects the image content to form a border.<\/li>\n<li><strong> cv2.BORDER_WRAP:<\/strong> Wraps the image content to form a border.<\/li>\n<li><strong> cv2.BORDER_REFLECT_101:<\/strong> Reflects the image content with a slight adjustment to form a border.<\/li>\n<li><strong> value:<\/strong> The colour value to be used when `cv2.BORDER_CONSTANT` is specified as the border type.<\/li>\n<\/ul>\n<p><strong>Code with Explanation :<\/strong><\/p>\n<p><strong>Let&#8217;s demonstrate copyMakeBorder() by adding a red border to an image:<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">import cv2\r\nimport numpy as np\r\n\r\n# Read the image\r\nimage = cv2.imread(r\"C:\\Users\\sanji\\Desktop\\DataFlair\\Thresholding in Opencv\\nature-img.jpg\")\r\n\r\n# Define the border size in pixels\r\nborder_size = 20\r\n\r\n# Define the border color (in BGR format)\r\nborder_color = (0, 0, 255)  # Red color\r\n\r\n# Add the border using copyMakeBorder()\r\nborder_image = cv2.copyMakeBorder(image, border_size, border_size, border_size, border_size, cv2.BORDER_CONSTANT, value=border_color)\r\n\r\n# Display the original image\r\ncv2.imshow('Original Image', image)\r\ncv2.waitKey(0)\r\n\r\n# Display the bordered image\r\ncv2.imshow('Bordered Image', border_image)\r\ncv2.waitKey(0)\r\n\r\ncv2.destroyAllWindows()<\/pre>\n<p><strong>Original image :<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Adding-Borders-in-OpenCV-original.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-125879 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Adding-Borders-in-OpenCV-original.webp\" alt=\"Adding Borders in OpenCV original\" width=\"800\" height=\"700\" \/><\/a><\/p>\n<p><strong> Bordered Image :<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Adding-Borders-in-OpenCV-bordered-.webp\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-125880 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/11\/Adding-Borders-in-OpenCV-bordered-.webp\" alt=\"Adding Borders in OpenCV bordered\" width=\"1043\" height=\"960\" \/><\/a><\/p>\n<p>In this code, we read an image and define the desired border size (in this case, 20 pixels). We chose the border color red (BGR value of `(0, 0, 255)`). The `copyMakeBorder()` function is then used to create a new image with a red border added to all four sides. We display the original and bordered images side by side for comparison.<\/p>\n<h3>Summary<\/h3>\n<p>In conclusion, we have traversed the captivating landscape of image processing, uncovering the secrets of thresholding and the art of adaptive techniques. From wielding the power of simple thresholding to embracing the dynamic nature of adaptive methods, we have witnessed how these tools can transform raw images into meaningful insights.<\/p>\n<p>Through the magic of copyMakeBorder(), we have fortified our images with protective borders, elevating their aesthetics and safeguarding them against unwanted distortions. With newfound mastery over these techniques, we can now confidently embark on exciting computer vision endeavours, unlocking the potential to unravel complex visual challenges and unlock a world of possibilities.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Unravel the hidden patterns within images and unlock the magic of image segmentation with the power of Thresholding in OpenCV. From transforming grayscale wonders into clear-cut binary visions to conquering complex computer vision challenges.&#46;&#46;&#46;<\/p>\n","protected":false},"author":86671,"featured_media":120212,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27755],"tags":[30016,9267,30017,30015,29991,30014],"class_list":["post-120210","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-opencv-tutorials","tag-image-thresholding-in-opencv","tag-opencv","tag-opencv-image-thresholding","tag-opencv-thresholding","tag-opencv-tutorials","tag-thresholding-in-opencv"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Image Thresholding in OpenCV - DataFlair<\/title>\n<meta name=\"description\" content=\"Thresholding, in simple words, is a technique used in image processing to convert a grayscale or color image into a binary image.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/image-thresholding-in-opencv\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Image Thresholding in OpenCV - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Thresholding, in simple words, is a technique used in image processing to convert a grayscale or color image into a binary image.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/image-thresholding-in-opencv\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-06T12:30:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-06T13:23:35+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/thresholding-in-open-cv.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Image Thresholding in OpenCV - DataFlair","description":"Thresholding, in simple words, is a technique used in image processing to convert a grayscale or color image into a binary image.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/image-thresholding-in-opencv\/","og_locale":"en_US","og_type":"article","og_title":"Image Thresholding in OpenCV - DataFlair","og_description":"Thresholding, in simple words, is a technique used in image processing to convert a grayscale or color image into a binary image.","og_url":"https:\/\/data-flair.training\/blogs\/image-thresholding-in-opencv\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2024-03-06T12:30:10+00:00","article_modified_time":"2024-03-06T13:23:35+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/thresholding-in-open-cv.webp","type":"image\/webp"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/image-thresholding-in-opencv\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/image-thresholding-in-opencv\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/0e594f928e31fc96628ac40f6ae74f49"},"headline":"Image Thresholding in OpenCV","datePublished":"2024-03-06T12:30:10+00:00","dateModified":"2024-03-06T13:23:35+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/image-thresholding-in-opencv\/"},"wordCount":1352,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/image-thresholding-in-opencv\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/thresholding-in-open-cv.webp","keywords":["image thresholding in opencv","opencv","opencv image thresholding","opencv thresholding","opencv tutorials","thresholding in opencv"],"articleSection":["OpenCV Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/image-thresholding-in-opencv\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/image-thresholding-in-opencv\/","url":"https:\/\/data-flair.training\/blogs\/image-thresholding-in-opencv\/","name":"Image Thresholding in OpenCV - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/image-thresholding-in-opencv\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/image-thresholding-in-opencv\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/thresholding-in-open-cv.webp","datePublished":"2024-03-06T12:30:10+00:00","dateModified":"2024-03-06T13:23:35+00:00","description":"Thresholding, in simple words, is a technique used in image processing to convert a grayscale or color image into a binary image.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/image-thresholding-in-opencv\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/image-thresholding-in-opencv\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/image-thresholding-in-opencv\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/thresholding-in-open-cv.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/09\/thresholding-in-open-cv.webp","width":1200,"height":628,"caption":"thresholding in opencv"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/image-thresholding-in-opencv\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"OpenCV Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/opencv-tutorials\/"},{"@type":"ListItem","position":3,"name":"Image Thresholding in OpenCV"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/0e594f928e31fc96628ac40f6ae74f49","name":"TechVidvan Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c89190da3d4010c71ba476b618ab10fdc2335c82cdfa0ad5002d98d0f2473444?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c89190da3d4010c71ba476b618ab10fdc2335c82cdfa0ad5002d98d0f2473444?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c89190da3d4010c71ba476b618ab10fdc2335c82cdfa0ad5002d98d0f2473444?s=96&d=mm&r=g","caption":"TechVidvan Team"},"description":"TechVidvan Team provides high-quality content &amp; courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.","url":"https:\/\/data-flair.training\/blogs\/author\/test001\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/120210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/86671"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=120210"}],"version-history":[{"count":6,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/120210\/revisions"}],"predecessor-version":[{"id":134498,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/120210\/revisions\/134498"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/120212"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=120210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=120210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=120210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}