{"id":18876,"date":"2026-10-19T18:41:44","date_gmt":"2026-10-19T18:41:44","guid":{"rendered":"https:\/\/www.8ration.com\/blogs\/?p=18876"},"modified":"2026-10-21T12:21:04","modified_gmt":"2026-10-21T12:21:04","slug":"morphology-in-computer-vision-techniques-examples-and-uses","status":"publish","type":"post","link":"https:\/\/www.8ration.com\/blogs\/morphology-in-computer-vision-techniques-examples-and-uses\/","title":{"rendered":"Morphology in Computer Vision: A Complete Guide to Techniques, Examples, and Applications"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Morphology in computer vision is a family of image operations that change the shape of objects in a picture. A small template called a structuring element slides across the image and decides which pixels to keep, add or remove. With two basic moves (erosion and dilation) and a few combinations of them, you can wipe out speckle noise, close gaps in broken lines, separate touching objects and pull out outlines.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">These operations are old by software standards. Georges Matheron created mathematical morphology in collaboration with <\/span><a href=\"https:\/\/cfsg-mining.minesparis.psl.eu\/home\/georges-matheron\/\" target=\"_blank\" rel=\"nofollow\"><span style=\"font-weight: 400;\">Jean Serra<\/span><\/a><span style=\"font-weight: 400;\"> at the \u00c9cole des Mines de Paris in the mid-1960s. Their methods still run inside OCR engines, medical imaging tools and factory inspection lines because they are fast and predictable and easy to tune.<\/span><\/p>\n\t\t<div data-elementor-type=\"section\" data-elementor-id=\"15039\" class=\"elementor elementor-15039\" data-elementor-post-type=\"elementor_library\">\n\t\t\t<div class=\"elementor-element elementor-element-525d842 e-con-full e-flex e-con e-parent\" data-id=\"525d842\" data-element_type=\"container\" data-e-type=\"container\" data-settings=\"{&quot;background_background&quot;:&quot;gradient&quot;}\">\n\t\t\t\t<div class=\"elementor-element elementor-element-83d5b21 elementor-widget elementor-widget-n-accordion\" data-id=\"83d5b21\" data-element_type=\"widget\" data-e-type=\"widget\" data-settings=\"{&quot;default_state&quot;:&quot;expanded&quot;,&quot;max_items_expended&quot;:&quot;one&quot;,&quot;n_accordion_animation_duration&quot;:{&quot;unit&quot;:&quot;ms&quot;,&quot;size&quot;:400,&quot;sizes&quot;:[]}}\" data-widget_type=\"nested-accordion.default\">\n\t\t\t\t\t\t\t<div class=\"e-n-accordion\" aria-label=\"Accordion. Open links with Enter or Space, close with Escape, and navigate with Arrow Keys\">\n\t\t\t\t\t\t<details id=\"e-n-accordion-item-1380\" class=\"e-n-accordion-item\" open>\n\t\t\t\t<summary class=\"e-n-accordion-item-title\" data-accordion-index=\"1\" tabindex=\"0\" aria-expanded=\"true\" aria-controls=\"e-n-accordion-item-1380\" >\n\t\t\t\t\t<span class='e-n-accordion-item-title-header'><div class=\"e-n-accordion-item-title-text\"> Key Takeaways: <\/div><\/span>\n\t\t\t\t\t\t\t<span class='e-n-accordion-item-title-icon'>\n\t\t\t<span class='e-opened' ><svg aria-hidden=\"true\" class=\"e-font-icon-svg e-fas-caret-up\" viewBox=\"0 0 320 512\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"><path d=\"M288.662 352H31.338c-17.818 0-26.741-21.543-14.142-34.142l128.662-128.662c7.81-7.81 20.474-7.81 28.284 0l128.662 128.662c12.6 12.599 3.676 34.142-14.142 34.142z\"><\/path><\/svg><\/span>\n\t\t\t<span class='e-closed'><svg aria-hidden=\"true\" class=\"e-font-icon-svg e-fas-sort-down\" viewBox=\"0 0 320 512\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"><path d=\"M41 288h238c21.4 0 32.1 25.9 17 41L177 448c-9.4 9.4-24.6 9.4-33.9 0L24 329c-15.1-15.1-4.4-41 17-41z\"><\/path><\/svg><\/span>\n\t\t<\/span>\n\n\t\t\t\t\t\t<\/summary>\n\t\t\t\t<div role=\"region\" aria-labelledby=\"e-n-accordion-item-1380\" class=\"elementor-element elementor-element-32b2e80 e-con-full e-flex e-con e-child\" data-id=\"32b2e80\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-9118172 bullet_points elementor-widget elementor-widget-html\" data-id=\"9118172\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"html.default\">\n\t\t\t\t\t<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Morphology works on the shape of image regions and not on color or texture.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Every operation depends on a structuring element. Its shape and size decide what gets removed or kept.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Erosion shrinks bright regions and dilation grows them. Opening and closing combine the two in different orders.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Computer vision open morphology (erosion then dilation) removes small bright noise and keeps larger objects close to their original size.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Top hat and black hat transforms pull out small bright or dark details from an uneven background.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Deep learning has not replaced morphology. Teams still use it to clean segmentation masks before and after a neural network runs.<\/span><\/li>\n<\/ul>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/details>\n\t\t\t\t\t<\/div>\n\t\t\t\t\t<script type=\"application\/ld+json\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@type\":\"FAQPage\",\"mainEntity\":[{\"@type\":\"Question\",\"name\":\"Key Takeaways:\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Morphology works on the shape of image regions and not on color or texture.\\nEvery operation depends on a structuring element. Its shape and size decide what gets removed or kept.\\nErosion shrinks bright regions and dilation grows them. Opening and closing combine the two in different orders.\\nComputer vision open morphology (erosion then dilation) removes small bright noise and keeps larger objects close to their original size.\\nTop hat and black hat transforms pull out small bright or dark details from an uneven background.\\nDeep learning has not replaced morphology. Teams still use it to clean segmentation masks before and after a neural network runs.\"}}]}<\/script>\n\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\n<h2><b>How Morphology in Computer Vision Works<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Morphology needs an image, a structuring element and a rule. Once you see how those pieces fit, every operation that follows becomes a variation on one idea you can reason through without formulas.<\/span><\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-18896 size-full\" src=\"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/yz0sd14nq0sut3rawevm.webp\" alt=\"\" width=\"1050\" height=\"420\" srcset=\"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/yz0sd14nq0sut3rawevm.webp 1050w, https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/yz0sd14nq0sut3rawevm-300x120.webp 300w, https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/yz0sd14nq0sut3rawevm-1024x410.webp 1024w, https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/yz0sd14nq0sut3rawevm-768x307.webp 768w\" sizes=\"(max-width: 1050px) 100vw, 1050px\" \/><\/p>\n<h3><b>Binary Images and Foreground Pixels<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Most morphology tutorials start with a binary image. Each pixel is either foreground (white, value 1 or 255) or background (black, value 0). Text on a scanned page, a cell under a microscope and a crack on a metal part all become white shapes on a black field after thresholding.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Morphology treats those white shapes as sets of points. It asks a geometric question at every pixel. Does the template fit inside the shape here? Does it touch the shape here? The answer decides the output pixel.<\/span><\/p>\n<h3><b>The Structuring Element<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">The structuring element is a small matrix of ones and zeros with a center point called the anchor. It plays the same part a kernel plays in blurring. The difference is that morphology uses it as a probe and not as a set of weights.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Shape matters more than most beginners expect. A square element treats every direction the same way along the grid. An elliptical element gives rounder results. A cross only looks at the four direct neighbors. A long horizontal line will erase vertical strokes and leave horizontal ones alone, and document tools use exactly that trick to find table rules on a scanned form.<\/span><\/p>\n<table style=\"width: 100%; border-collapse: collapse;\">\n<thead>\n<tr>\n<th style=\"padding: 14px; background: #1269ff; color: #fff; text-align: center; border: 1px solid #e5e7eb;\">Structuring element<\/th>\n<th style=\"padding: 14px; background: #1269ff; color: #fff; text-align: center; border: 1px solid #e5e7eb;\">OpenCV flag<\/th>\n<th style=\"padding: 14px; background: #1269ff; color: #fff; text-align: center; border: 1px solid #e5e7eb;\">Typical use<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\"><strong>Rectangle<\/strong><\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">cv.MORPH_RECT<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">General noise removal and blocky objects such as text<\/td>\n<\/tr>\n<tr style=\"background: #f8fafc;\">\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\"><strong>Ellipse<\/strong><\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">cv.MORPH_ELLIPSE<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Round objects such as cells, coins and blobs<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\"><strong>Cross<\/strong><\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">cv.MORPH_CROSS<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Thin structures where diagonal growth should be limited<\/td>\n<\/tr>\n<tr style=\"background: #f8fafc;\">\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\"><strong>Custom line (for example 40 x 1)<\/strong><\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Built with NumPy<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Detecting horizontal or vertical lines in forms and tables<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-weight: 400;\">Size controls strength. A 3 x 3 element nibbles one pixel off each border. A 15 x 15 element removes anything thinner than 15 pixels. Pick a size a little larger than the noise you want gone and smaller than the smallest object you want to keep.<\/span><\/p>\n<h3><b>Grayscale Morphology<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Morphology also works on grayscale images. Here erosion takes the minimum value under the structuring element and dilation takes the maximum. Dark regions spread under erosion and bright regions spread under dilation. Grayscale morphology is what makes the top hat transform useful on X-rays, fundus photos and unevenly lit product shots.<\/span><\/p>\n\t\t<div data-elementor-type=\"section\" data-elementor-id=\"14783\" class=\"elementor elementor-14783\" data-elementor-post-type=\"elementor_library\">\n\t\t\t<div class=\"elementor-element elementor-element-09a4ac2 e-con-full e-flex e-con e-parent\" data-id=\"09a4ac2\" data-element_type=\"container\" data-e-type=\"container\" data-settings=\"{&quot;background_background&quot;:&quot;gradient&quot;}\">\n\t\t\t\t<div class=\"elementor-element elementor-element-6f0d772 elementor-widget elementor-widget-heading\" data-id=\"6f0d772\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Need shape analysis inside your next app?<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9f6fb42 elementor-widget elementor-widget-text-editor\" data-id=\"9f6fb42\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\tTalk to 8ration&#8217;s AI team about adding image cleanup and object detection to your product.\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-8414934 elementor-widget elementor-widget-button\" data-id=\"8414934\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"button.default\">\n\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-button elementor-button-link elementor-size-sm\" href=\"https:\/\/www.8ration.com\/services\/ai-development\/\" target=\"_blank\">\n\t\t\t\t\t\t<span class=\"elementor-button-content-wrapper\">\n\t\t\t\t\t\t<span class=\"elementor-button-icon\">\n\t\t\t\t<svg aria-hidden=\"true\" class=\"e-font-icon-svg e-fab-telegram-plane\" viewBox=\"0 0 448 512\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"><path d=\"M446.7 98.6l-67.6 318.8c-5.1 22.5-18.4 28.1-37.3 17.5l-103-75.9-49.7 47.8c-5.5 5.5-10.1 10.1-20.7 10.1l7.4-104.9 190.9-172.5c8.3-7.4-1.8-11.5-12.9-4.1L117.8 284 16.2 252.2c-22.1-6.9-22.5-22.1 4.6-32.7L418.2 66.4c18.4-6.9 34.5 4.1 28.5 32.2z\"><\/path><\/svg>\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t<span class=\"elementor-button-text\">Talk to Our AI Team<\/span>\n\t\t\t\t\t<\/span>\n\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\n<h2><b>The Core Morphological Operations<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Six operations cover most real work. Each one below shows what it does to an image, when to reach for it and the OpenCV call that runs it, so you can match problems to fixes.<\/span><\/p>\n<h2><img decoding=\"async\" class=\"alignnone size-full wp-image-18895\" src=\"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/yyz9rveheagi2lb0i9rl.webp\" alt=\"\" width=\"1050\" height=\"420\" srcset=\"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/yyz9rveheagi2lb0i9rl.webp 1050w, https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/yyz9rveheagi2lb0i9rl-300x120.webp 300w, https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/yyz9rveheagi2lb0i9rl-1024x410.webp 1024w, https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/yyz9rveheagi2lb0i9rl-768x307.webp 768w\" sizes=\"(max-width: 1050px) 100vw, 1050px\" \/><\/h2>\n<h3><b>Erosion<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Erosion keeps a foreground pixel only if the whole structuring element fits inside the foreground at that spot. The OpenCV documentation puts it plainly: a pixel &#8220;will be considered 1 only if all the pixels under the kernel is 1, otherwise it is eroded (made to zero).&#8221;<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The visible effect is shrinkage. Objects get thinner. Small white dots vanish. Two blobs joined by a thin bridge come apart. Erosion is the tool for separating touching coins or cells before you count them.<\/span><\/p>\n<h3><b>Dilation<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Dilation does the reverse. A pixel turns white if the structuring element touches any white pixel at that spot. Objects grow. Holes shrink. Broken strokes in a letter join up again.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Erosion and dilation are duals. Eroding the foreground gives the same result as dilating the background and then inverting. That relationship explains why opening and closing mirror each other.<\/span><\/p>\n<h3><b>Opening<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Opening is erosion followed by dilation with the same structuring element. The erosion wipes out anything too small to hold the element. The dilation then grows the survivors back to roughly their old size. Small bright noise disappears and the larger shapes keep their outline.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Opening has a useful property: running it twice gives the same result as running it once. Mathematicians call this idempotence. For a pipeline it means you can apply opening without worrying that a second pass will keep eating away at your objects.<\/span><\/p>\n<h3><b>Closing<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Closing runs the steps the other way: dilation first and then erosion. It fills small dark holes inside objects and joins nearby fragments. A scanned signature with gaps in the ink or a segmentation mask with pinholes both come out solid after closing.<\/span><\/p>\n<h3><b>Morphological Gradient<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">The gradient subtracts the eroded image from the dilated image. What is left is a band along every edge, so you get a clean outline of each object. It works well when you need object boundaries and do not want the noise that a derivative filter such as Sobel tends to pick up.<\/span><\/p>\n<h3><b>Top Hat and Black Hat<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">The top hat transform subtracts the opening from the original image. Opening removes bright details smaller than the structuring element, so the difference holds exactly those details. The black hat transform subtracts the original from its closing and returns small dark details instead.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Both earn their place on images with uneven lighting. A top hat with a large element flattens a gradient background and leaves small bright features standing out. A black hat does the same for dark features such as blood vessels on a retinal photo or dark text on a shadowed page.<\/span><\/p>\n<table style=\"width: 100%; border-collapse: collapse;\">\n<thead>\n<tr>\n<th style=\"padding: 14px; background: #1269ff; color: #fff; text-align: center; border: 1px solid #e5e7eb;\">Operation<\/th>\n<th style=\"padding: 14px; background: #1269ff; color: #fff; text-align: center; border: 1px solid #e5e7eb;\">Steps<\/th>\n<th style=\"padding: 14px; background: #1269ff; color: #fff; text-align: center; border: 1px solid #e5e7eb;\">Main effect<\/th>\n<th style=\"padding: 14px; background: #1269ff; color: #fff; text-align: center; border: 1px solid #e5e7eb;\">OpenCV call<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\"><strong>Erosion<\/strong><\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Minimum under element<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Shrinks objects and removes specks<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">cv.erode<\/td>\n<\/tr>\n<tr style=\"background: #f8fafc;\">\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\"><strong>Dilation<\/strong><\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Maximum under element<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Grows objects and fills gaps<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">cv.dilate<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\"><strong>Opening<\/strong><\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Erosion then dilation<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Removes small bright noise<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">cv.MORPH_OPEN<\/td>\n<\/tr>\n<tr style=\"background: #f8fafc;\">\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\"><strong>Closing<\/strong><\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Dilation then erosion<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Fills small dark holes<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">cv.MORPH_CLOSE<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\"><strong>Gradient<\/strong><\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Dilation minus erosion<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Extracts outlines<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">cv.MORPH_GRADIENT<\/td>\n<\/tr>\n<tr style=\"background: #f8fafc;\">\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\"><strong>Top hat<\/strong><\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Image minus opening<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Isolates small bright details<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">cv.MORPH_TOPHAT<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\"><strong>Black hat<\/strong><\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Closing minus image<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Isolates small dark details<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">cv.MORPH_BLACKHAT<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2><\/h2>\n<h2><b>Computer Vision Open Morphology in Practice With OpenCV<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Theory makes more sense once you run it. The steps below build a short OpenCV pipeline that cleans a scanned document and shows you how kernel size and operation order change the output.<\/span><\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-18893\" src=\"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/f674nhrvazelzhubbnik.webp\" alt=\"\" width=\"1050\" height=\"420\" srcset=\"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/f674nhrvazelzhubbnik.webp 1050w, https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/f674nhrvazelzhubbnik-300x120.webp 300w, https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/f674nhrvazelzhubbnik-1024x410.webp 1024w, https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/f674nhrvazelzhubbnik-768x307.webp 768w\" sizes=\"(max-width: 1050px) 100vw, 1050px\" \/><\/p>\n<h3><b>A Cleanup Pipeline in Python<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">The snippet loads a grayscale scan and turns it into a binary image with Otsu thresholding. It then removes speckle with an opening and seals broken strokes with a closing.<\/span><\/p>\n<pre id=\"code-snippet-source-76\" class=\"code-snippet-source linkable-line-numbers\"><code class=\"language-php line-numbers\">&lt;?php\n\nimport cv2 as cv\nimport numpy as np\n\nimg = cv.imread(&quot;scan.png&quot;, cv.IMREAD_GRAYSCALE)\n_, binary = cv.threshold(img, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)\n\nkernel = cv.getStructuringElement(cv.MORPH_ELLIPSE, (3, 3))\nopened = cv.morphologyEx(binary, cv.MORPH_OPEN, kernel)\nclosed = cv.morphologyEx(opened, cv.MORPH_CLOSE, kernel)\n\ncv.imwrite(&quot;clean.png&quot;, closed)\n<\/code><\/pre>\n<p><span style=\"font-weight: 400;\">Note the inverted threshold. OpenCV treats white as foreground, so dark ink on a white page has to flip before morphology can see the letters as objects.<\/span><\/p>\n<h3><b>Choosing Kernel Size and Iterations<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Start small. A 3 x 3 element with one iteration is the safe default. If noise survives, raise the size or set the iterations argument higher in cv.erode or cv.dilate. Two iterations with a 3 x 3 element behave much like one pass with a 5 x 5 element, though the corners differ a little.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Watch the smallest real object in your image. When the element gets wider than its thinnest part, opening will delete it along with the noise. Thin text strokes and hairline cracks are the usual victims.<\/span><\/p>\n<h3><b>Getting the Order Right<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Opening followed by closing gives a different result from closing followed by opening. If your image has more bright speckle than holes, open first so the closing does not glue noise onto your objects. If broken objects matter more than noise, close first. Test both orders on a handful of real samples before you lock the pipeline in.<\/span><\/p>\n<h2><b>Advanced Morphological Techniques<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">The six core operations combine into more powerful tools. These four techniques show up in production systems for shape matching, measurement and segmenting objects that touch or overlap one another in crowded scenes.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-18891\" src=\"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/bfjlxnokt5fknridajsh.webp\" alt=\"\" width=\"1050\" height=\"420\" srcset=\"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/bfjlxnokt5fknridajsh.webp 1050w, https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/bfjlxnokt5fknridajsh-300x120.webp 300w, https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/bfjlxnokt5fknridajsh-1024x410.webp 1024w, https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/bfjlxnokt5fknridajsh-768x307.webp 768w\" sizes=\"(max-width: 1050px) 100vw, 1050px\" \/><\/p>\n<h3><b>Hit-or-Miss Transform<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">The hit-or-miss transform looks for an exact local pattern. It uses one element that must match the foreground and another that must match the background. Developers use it to find line endpoints, corners or isolated pixels. OpenCV exposes it as cv.MORPH_HITMISS.<\/span><\/p>\n<h3><b>Skeletonization<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">A skeleton reduces each shape to a one-pixel-wide center line that keeps its topology. Repeated erosion and opening build it step by step. Skeletons help with fingerprint ridge analysis, handwriting recognition and measuring the length of roads or vessels in an image.<\/span><\/p>\n<h3><b>Morphological Reconstruction<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Reconstruction grows a marker image inside a mask image until it can grow no further. It removes objects that touch the image border, fills holes of any size and keeps only the objects you marked. Unlike opening, it restores the exact original shape of each object it keeps.<\/span><\/p>\n<h3><b>Watershed Segmentation<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Watershed treats a grayscale image as terrain and floods it from marked low points. Where floods meet, it draws a boundary. Morphology prepares the markers. The usual recipe uses opening to clean the mask and dilation to find sure background. It also uses a distance transform with a threshold to find sure foreground. The result separates objects that touch, such as cells in a cluster or coins in a pile.<\/span><\/p>\n<h2><b>Morphology Computer Vision Examples Across Industries<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Morphology shows up wherever a camera feeds a decision. These examples show how specific operations solve specific problems, from hospital imaging to factory floors and the phone cameras people use every day.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The commercial pull is large. Grand View Research projects that the global computer vision market will<\/span><a href=\"https:\/\/www.grandviewresearch.com\/press-release\/global-computer-vision-market\" target=\"_blank\" rel=\"nofollow\"> <span style=\"font-weight: 400;\">reach USD 58.29 billion by 2030<\/span><\/a><span style=\"font-weight: 400;\"> and grow at a CAGR of 19.8% from 2025 to 2030.<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-18894\" src=\"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/kc2ddixuahcacqtr9hsm.webp\" alt=\"\" width=\"1050\" height=\"420\" srcset=\"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/kc2ddixuahcacqtr9hsm.webp 1050w, https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/kc2ddixuahcacqtr9hsm-300x120.webp 300w, https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/kc2ddixuahcacqtr9hsm-1024x410.webp 1024w, https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/kc2ddixuahcacqtr9hsm-768x307.webp 768w\" sizes=\"(max-width: 1050px) 100vw, 1050px\" \/><\/p>\n<h3><b>Medical Imaging<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Retinal vessel segmentation is a clear case. Kumar, Samal and Suraj used a top-hat transformation along with CLAHE and 2-D Gabor wavelet filters to pull blood vessels out of fundus photos. On the DRIVE database their unsupervised method reached an average accuracy of <\/span><a href=\"https:\/\/arxiv.org\/abs\/1908.04123\" target=\"_blank\" rel=\"nofollow\"><span style=\"font-weight: 400;\">94.32%<\/span><\/a><span style=\"font-weight: 400;\">. Hospitals that build<\/span><a href=\"https:\/\/www.8ration.com\/industries\/healthcare-software-development-services\/\" target=\"_blank\"> <span style=\"font-weight: 400;\">healthcare software<\/span><\/a><span style=\"font-weight: 400;\"> use similar steps to count cells, outline tumors and clean organ masks before measurement. Remote care tools such as<\/span><a href=\"https:\/\/www.8ration.com\/industries\/telemedicine-app-development\/\" target=\"_blank\"> <span style=\"font-weight: 400;\">telemedicine apps<\/span><\/a><span style=\"font-weight: 400;\"> that accept photos from patients face the same cleanup problem with less control over lighting.<\/span><\/p>\n<h3><b>Document Scanning and OCR<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">OCR engines depend on clean characters. Opening removes dust and scanner speckle. Closing repairs letters broken by faded ink. Long horizontal and vertical line elements find table borders so the engine can read forms cell by cell. Banking, legal and logistics apps that scan receipts or IDs run these steps before any text recognition model sees the image.<\/span><\/p>\n<h3><b>Manufacturing Quality Inspection<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">On a production line a camera checks parts for cracks, scratches and missing features. Black hat transforms bring out thin dark scratches on shiny metal. Opening removes glare spots that would trigger false alarms. Plants that invest in<\/span><a href=\"https:\/\/www.8ration.com\/industries\/manufacturing-software-solutions\/\" target=\"_blank\"> <span style=\"font-weight: 400;\">manufacturing software<\/span><\/a><span style=\"font-weight: 400;\"> often pair these steps with sensors on connected machines through IoT application development.<\/span><\/p>\n<h3><b>Agriculture and Remote Sensing<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Satellite and drone images of fields need shape analysis. Opening removes isolated pixels from a crop mask. Closing joins field patches split by shadows. Watershed with morphological markers separates touching tree crowns or plants for counting. Growers using<\/span><a href=\"https:\/\/www.8ration.com\/industries\/agriculture-software-development-services\/\" target=\"_blank\"> <span style=\"font-weight: 400;\">agriculture software<\/span><\/a><span style=\"font-weight: 400;\"> rely on that kind of cleanup to estimate stand counts and spot gaps in planting.<\/span><\/p>\n<h3><b>Automotive and Driver Assistance<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Lane detection systems threshold the road image and then clean it. Closing joins dashed lane markings into continuous lines. Opening removes reflections and small debris.<\/span><a href=\"https:\/\/www.8ration.com\/industries\/automotive-software-development-services\/\" target=\"_blank\"> <span style=\"font-weight: 400;\">Automotive software<\/span><\/a><span style=\"font-weight: 400;\"> teams also use morphology on parking camera feeds and on masks from obstacle detection models.<\/span><\/p>\n<h3><b>Augmented Reality and Mobile Cameras<\/b><\/h3>\n<p><span style=\"font-weight: 400;\">Phone cameras run morphology in real time. Portrait modes clean the person mask before blurring the background.<\/span><a href=\"https:\/\/www.8ration.com\/services\/augmented-reality-app\/\" target=\"_blank\"> <span style=\"font-weight: 400;\">Augmented reality apps<\/span><\/a><span style=\"font-weight: 400;\"> close holes in hand and surface masks so virtual objects sit on the right pixels. Cheap operations matter here because the phone has to process every frame of a live preview.<\/span><\/p>\n<table style=\"width: 100%; border-collapse: collapse;\">\n<thead>\n<tr>\n<th style=\"padding: 14px; background: #1269ff; color: #fff; text-align: center; border: 1px solid #e5e7eb;\">Industry<\/th>\n<th style=\"padding: 14px; background: #1269ff; color: #fff; text-align: center; border: 1px solid #e5e7eb;\">Problem<\/th>\n<th style=\"padding: 14px; background: #1269ff; color: #fff; text-align: center; border: 1px solid #e5e7eb;\">Morphological operation<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\"><strong>Healthcare<\/strong><\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Faint vessels on uneven background<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Top hat or black hat<\/td>\n<\/tr>\n<tr style=\"background: #f8fafc;\">\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\"><strong>Healthcare<\/strong><\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Touching cells in a cluster<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Distance transform and watershed<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\"><strong>Documents<\/strong><\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Speckle and broken letters<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Opening then closing<\/td>\n<\/tr>\n<tr style=\"background: #f8fafc;\">\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\"><strong>Documents<\/strong><\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Table borders on forms<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Opening with long line elements<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\"><strong>Manufacturing<\/strong><\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Thin scratches on metal<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Black hat<\/td>\n<\/tr>\n<tr style=\"background: #f8fafc;\">\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\"><strong>Agriculture<\/strong><\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Touching plants or tree crowns<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Watershed with morphological markers<\/td>\n<\/tr>\n<tr>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\"><strong>Automotive<\/strong><\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Dashed lane markings<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Closing with a vertical element<\/td>\n<\/tr>\n<tr style=\"background: #f8fafc;\">\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\"><strong>AR and mobile<\/strong><\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Holes in a person or hand mask<\/td>\n<td style=\"padding: 12px; text-align: center; border: 1px solid #e5e7eb;\">Closing and hole filling<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\t\t<div data-elementor-type=\"section\" data-elementor-id=\"15275\" class=\"elementor elementor-15275\" data-elementor-post-type=\"elementor_library\">\n\t\t\t<div class=\"elementor-element elementor-element-88c286b e-con-full e-flex e-con e-parent\" data-id=\"88c286b\" data-element_type=\"container\" data-e-type=\"container\" data-settings=\"{&quot;background_background&quot;:&quot;gradient&quot;}\">\n\t\t\t\t<div class=\"elementor-element elementor-element-a22a2f8 elementor-widget elementor-widget-heading\" data-id=\"a22a2f8\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Want to know what a vision feature will cost?<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-086527d elementor-widget elementor-widget-text-editor\" data-id=\"086527d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\tGet a quick estimate for your image processing or AI app based on features, platforms and timeline.\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-2cfa9e9 elementor-widget elementor-widget-button\" data-id=\"2cfa9e9\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"button.default\">\n\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-button elementor-button-link elementor-size-sm\" href=\"https:\/\/www.8ration.com\/app-development-cost-calculator\/\" target=\"_blank\">\n\t\t\t\t\t\t<span class=\"elementor-button-content-wrapper\">\n\t\t\t\t\t\t<span class=\"elementor-button-icon\">\n\t\t\t\t<svg aria-hidden=\"true\" class=\"e-font-icon-svg e-fab-telegram-plane\" viewBox=\"0 0 448 512\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\"><path d=\"M446.7 98.6l-67.6 318.8c-5.1 22.5-18.4 28.1-37.3 17.5l-103-75.9-49.7 47.8c-5.5 5.5-10.1 10.1-20.7 10.1l7.4-104.9 190.9-172.5c8.3-7.4-1.8-11.5-12.9-4.1L117.8 284 16.2 252.2c-22.1-6.9-22.5-22.1 4.6-32.7L418.2 66.4c18.4-6.9 34.5 4.1 28.5 32.2z\"><\/path><\/svg>\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t<span class=\"elementor-button-text\">Calculate Your App Cost<\/span>\n\t\t\t\t\t<\/span>\n\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\n<h2><b>Where Morphology Fits Next to Deep Learning<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Neural networks now handle most detection and segmentation tasks. Morphology did not disappear. It moved to the edges of the pipeline.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Before the network, morphology cleans and normalizes input. A top hat flattens uneven lighting. Opening strips sensor noise that would confuse a small model. After the network, morphology fixes the mask. Segmentation models often output masks with pinholes, ragged borders and stray islands of pixels. One closing and one opening fix most of that. Those two calls cost far less than retraining the model to handle every edge case.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Morphology also suits tight hardware. A wearable, a drone or a low-end Android phone may not run a large model at full frame rate. Classic morphology runs on almost anything and gives the same output for the same input every time. That determinism makes testing simpler, and regulated sectors such as healthcare value results they can explain.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Some research goes further and builds morphological layers into networks so the model learns its own structuring elements. That work is still mostly academic. In production code the pattern stays simple: the network finds the objects and morphology tidies them.<\/span><\/p>\n<h2><b>How 8ration Approaches Computer Vision Work<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">We build software that uses cameras and images as input. Our<\/span><a href=\"https:\/\/www.8ration.com\/services\/ai-development\/\" target=\"_blank\"> <span style=\"font-weight: 400;\">AI development<\/span><\/a><span style=\"font-weight: 400;\"> team works on object detection, image segmentation and the processing steps around them, and morphology sits inside many of those pipelines.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Our projects usually start with sample images from the client. Real images expose the problems that matter, such as uneven lighting, glare, motion blur or low resolution from older devices. We test classic operations like opening, closing and top hat transforms against those samples before we decide whether a neural network is needed at all. Some projects need only a well-tuned OpenCV pipeline. Others need a trained model with morphology handling cleanup before and after it.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">We ship these features inside mobile, web and wearable apps. That includes on-device processing for<\/span><a href=\"https:\/\/www.8ration.com\/mobile-app-development\/android-app-development\/\" target=\"_blank\"> <span style=\"font-weight: 400;\">Android<\/span><\/a><span style=\"font-weight: 400;\"> and<\/span><a href=\"https:\/\/www.8ration.com\/mobile-app-development\/ios-app-development\/\" target=\"_blank\"> <span style=\"font-weight: 400;\">iOS<\/span><\/a><span style=\"font-weight: 400;\"> where speed and battery use limit what the app can run. Our software testing team checks vision features against image sets that cover the lighting and device conditions users will actually have.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Morphology in computer vision is a family of image operations that change the shape of objects in a picture. A small template&#8230;<\/p>\n","protected":false},"author":17,"featured_media":18892,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[274],"tags":[],"class_list":["post-18876","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-computer-vision"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Morphology in Computer Vision: Techniques, Examples and Uses<\/title>\n<meta name=\"description\" content=\"Learn how morphology in computer vision cleans and shapes images with erosion, dilation and opening. See OpenCV code and real examples. Read the guide.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.8ration.com\/blogs\/morphology-in-computer-vision-techniques-examples-and-uses\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Morphology in Computer Vision: Techniques, Examples and Uses\" \/>\n<meta property=\"og:description\" content=\"Learn how morphology in computer vision cleans and shapes images with erosion, dilation and opening. See OpenCV code and real examples. Read the guide.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.8ration.com\/blogs\/morphology-in-computer-vision-techniques-examples-and-uses\/\" \/>\n<meta property=\"og:site_name\" content=\"8ration\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-19T18:41:44+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-10-21T12:21:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/bxcy9f7nisq8sq0zgqzy.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1050\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Roshaan Faisal\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Roshaan Faisal\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/morphology-in-computer-vision-techniques-examples-and-uses\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/morphology-in-computer-vision-techniques-examples-and-uses\\\/\"},\"author\":{\"name\":\"Roshaan Faisal\",\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/#\\\/schema\\\/person\\\/66810ee4d961fdca44fbd0280de1c420\"},\"headline\":\"Morphology in Computer Vision: A Complete Guide to Techniques, Examples, and Applications\",\"datePublished\":\"2026-10-19T18:41:44+00:00\",\"dateModified\":\"2026-10-21T12:21:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/morphology-in-computer-vision-techniques-examples-and-uses\\\/\"},\"wordCount\":2466,\"publisher\":{\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/morphology-in-computer-vision-techniques-examples-and-uses\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/bxcy9f7nisq8sq0zgqzy.webp\",\"articleSection\":[\"Computer Vision\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/morphology-in-computer-vision-techniques-examples-and-uses\\\/\",\"url\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/morphology-in-computer-vision-techniques-examples-and-uses\\\/\",\"name\":\"Morphology in Computer Vision: Techniques, Examples and Uses\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/morphology-in-computer-vision-techniques-examples-and-uses\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/morphology-in-computer-vision-techniques-examples-and-uses\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/bxcy9f7nisq8sq0zgqzy.webp\",\"datePublished\":\"2026-10-19T18:41:44+00:00\",\"dateModified\":\"2026-10-21T12:21:04+00:00\",\"description\":\"Learn how morphology in computer vision cleans and shapes images with erosion, dilation and opening. See OpenCV code and real examples. Read the guide.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/morphology-in-computer-vision-techniques-examples-and-uses\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/morphology-in-computer-vision-techniques-examples-and-uses\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/morphology-in-computer-vision-techniques-examples-and-uses\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/bxcy9f7nisq8sq0zgqzy.webp\",\"contentUrl\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/bxcy9f7nisq8sq0zgqzy.webp\",\"width\":1050,\"height\":420},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/morphology-in-computer-vision-techniques-examples-and-uses\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blogs\",\"item\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Computer Vision\",\"item\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/category\\\/computer-vision\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Morphology in Computer Vision: A Complete Guide to Techniques, Examples, and Applications\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/#website\",\"url\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/\",\"name\":\"8ration\",\"description\":\"Top Software Development Company in USA | Custom IT Solutions\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/#organization\",\"name\":\"8ration\",\"url\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/wp-content\\\/uploads\\\/2025\\\/07\\\/8ration.webp\",\"contentUrl\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/wp-content\\\/uploads\\\/2025\\\/07\\\/8ration.webp\",\"width\":1722,\"height\":637,\"caption\":\"8ration\"},\"image\":{\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/#\\\/schema\\\/person\\\/66810ee4d961fdca44fbd0280de1c420\",\"name\":\"Roshaan Faisal\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/Roshaan-Faisal-96x96.png\",\"url\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/Roshaan-Faisal-96x96.png\",\"contentUrl\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/Roshaan-Faisal-96x96.png\",\"caption\":\"Roshaan Faisal\"},\"description\":\"A DevOps Engineer and Technical Advisor with 7+ years of experience in AWS, Docker, Kubernetes, and Terraform, specializing in deployment automation for web, mobile, and game applications, and passionate about sharing practical DevOps and cloud engineering knowledge through blogging.\",\"sameAs\":[\"https:\\\/\\\/www.8ration.com\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/roshaan-faisal\\\/\"],\"url\":\"https:\\\/\\\/www.8ration.com\\\/blogs\\\/author\\\/roshaan-faisal\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Morphology in Computer Vision: Techniques, Examples and Uses","description":"Learn how morphology in computer vision cleans and shapes images with erosion, dilation and opening. See OpenCV code and real examples. Read the guide.","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:\/\/www.8ration.com\/blogs\/morphology-in-computer-vision-techniques-examples-and-uses\/","og_locale":"en_US","og_type":"article","og_title":"Morphology in Computer Vision: Techniques, Examples and Uses","og_description":"Learn how morphology in computer vision cleans and shapes images with erosion, dilation and opening. See OpenCV code and real examples. Read the guide.","og_url":"https:\/\/www.8ration.com\/blogs\/morphology-in-computer-vision-techniques-examples-and-uses\/","og_site_name":"8ration","article_published_time":"2026-10-19T18:41:44+00:00","article_modified_time":"2026-10-21T12:21:04+00:00","og_image":[{"width":1050,"height":420,"url":"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/bxcy9f7nisq8sq0zgqzy.webp","type":"image\/webp"}],"author":"Roshaan Faisal","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Roshaan Faisal","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.8ration.com\/blogs\/morphology-in-computer-vision-techniques-examples-and-uses\/#article","isPartOf":{"@id":"https:\/\/www.8ration.com\/blogs\/morphology-in-computer-vision-techniques-examples-and-uses\/"},"author":{"name":"Roshaan Faisal","@id":"https:\/\/www.8ration.com\/blogs\/#\/schema\/person\/66810ee4d961fdca44fbd0280de1c420"},"headline":"Morphology in Computer Vision: A Complete Guide to Techniques, Examples, and Applications","datePublished":"2026-10-19T18:41:44+00:00","dateModified":"2026-10-21T12:21:04+00:00","mainEntityOfPage":{"@id":"https:\/\/www.8ration.com\/blogs\/morphology-in-computer-vision-techniques-examples-and-uses\/"},"wordCount":2466,"publisher":{"@id":"https:\/\/www.8ration.com\/blogs\/#organization"},"image":{"@id":"https:\/\/www.8ration.com\/blogs\/morphology-in-computer-vision-techniques-examples-and-uses\/#primaryimage"},"thumbnailUrl":"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/bxcy9f7nisq8sq0zgqzy.webp","articleSection":["Computer Vision"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.8ration.com\/blogs\/morphology-in-computer-vision-techniques-examples-and-uses\/","url":"https:\/\/www.8ration.com\/blogs\/morphology-in-computer-vision-techniques-examples-and-uses\/","name":"Morphology in Computer Vision: Techniques, Examples and Uses","isPartOf":{"@id":"https:\/\/www.8ration.com\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.8ration.com\/blogs\/morphology-in-computer-vision-techniques-examples-and-uses\/#primaryimage"},"image":{"@id":"https:\/\/www.8ration.com\/blogs\/morphology-in-computer-vision-techniques-examples-and-uses\/#primaryimage"},"thumbnailUrl":"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/bxcy9f7nisq8sq0zgqzy.webp","datePublished":"2026-10-19T18:41:44+00:00","dateModified":"2026-10-21T12:21:04+00:00","description":"Learn how morphology in computer vision cleans and shapes images with erosion, dilation and opening. See OpenCV code and real examples. Read the guide.","breadcrumb":{"@id":"https:\/\/www.8ration.com\/blogs\/morphology-in-computer-vision-techniques-examples-and-uses\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.8ration.com\/blogs\/morphology-in-computer-vision-techniques-examples-and-uses\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.8ration.com\/blogs\/morphology-in-computer-vision-techniques-examples-and-uses\/#primaryimage","url":"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/bxcy9f7nisq8sq0zgqzy.webp","contentUrl":"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/10\/bxcy9f7nisq8sq0zgqzy.webp","width":1050,"height":420},{"@type":"BreadcrumbList","@id":"https:\/\/www.8ration.com\/blogs\/morphology-in-computer-vision-techniques-examples-and-uses\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blogs","item":"https:\/\/www.8ration.com\/blogs\/"},{"@type":"ListItem","position":2,"name":"Computer Vision","item":"https:\/\/www.8ration.com\/blogs\/category\/computer-vision\/"},{"@type":"ListItem","position":3,"name":"Morphology in Computer Vision: A Complete Guide to Techniques, Examples, and Applications"}]},{"@type":"WebSite","@id":"https:\/\/www.8ration.com\/blogs\/#website","url":"https:\/\/www.8ration.com\/blogs\/","name":"8ration","description":"Top Software Development Company in USA | Custom IT Solutions","publisher":{"@id":"https:\/\/www.8ration.com\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.8ration.com\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.8ration.com\/blogs\/#organization","name":"8ration","url":"https:\/\/www.8ration.com\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.8ration.com\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2025\/07\/8ration.webp","contentUrl":"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2025\/07\/8ration.webp","width":1722,"height":637,"caption":"8ration"},"image":{"@id":"https:\/\/www.8ration.com\/blogs\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.8ration.com\/blogs\/#\/schema\/person\/66810ee4d961fdca44fbd0280de1c420","name":"Roshaan Faisal","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/04\/Roshaan-Faisal-96x96.png","url":"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/04\/Roshaan-Faisal-96x96.png","contentUrl":"https:\/\/www.8ration.com\/blogs\/wp-content\/uploads\/2026\/04\/Roshaan-Faisal-96x96.png","caption":"Roshaan Faisal"},"description":"A DevOps Engineer and Technical Advisor with 7+ years of experience in AWS, Docker, Kubernetes, and Terraform, specializing in deployment automation for web, mobile, and game applications, and passionate about sharing practical DevOps and cloud engineering knowledge through blogging.","sameAs":["https:\/\/www.8ration.com\/","https:\/\/www.linkedin.com\/in\/roshaan-faisal\/"],"url":"https:\/\/www.8ration.com\/blogs\/author\/roshaan-faisal\/"}]}},"_links":{"self":[{"href":"https:\/\/www.8ration.com\/blogs\/wp-json\/wp\/v2\/posts\/18876","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.8ration.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.8ration.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.8ration.com\/blogs\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.8ration.com\/blogs\/wp-json\/wp\/v2\/comments?post=18876"}],"version-history":[{"count":6,"href":"https:\/\/www.8ration.com\/blogs\/wp-json\/wp\/v2\/posts\/18876\/revisions"}],"predecessor-version":[{"id":18897,"href":"https:\/\/www.8ration.com\/blogs\/wp-json\/wp\/v2\/posts\/18876\/revisions\/18897"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.8ration.com\/blogs\/wp-json\/wp\/v2\/media\/18892"}],"wp:attachment":[{"href":"https:\/\/www.8ration.com\/blogs\/wp-json\/wp\/v2\/media?parent=18876"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.8ration.com\/blogs\/wp-json\/wp\/v2\/categories?post=18876"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.8ration.com\/blogs\/wp-json\/wp\/v2\/tags?post=18876"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}