Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

cv2 leave only the biggest blob

import cv2
import numpy as np

# Read input
img = cv2.imread('images/t6igVVk.png', cv2.IMREAD_GRAYSCALE)

# Generate intermediate image; use morphological closing to keep parts of the brain together
inter = cv2.morphologyEx(img, cv2.MORPH_CLOSE, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5)))

# Find largest contour in intermediate image
cnts, _ = cv2.findContours(inter, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
cnt = max(cnts, key=cv2.contourArea)

# Output
out = np.zeros(img.shape, np.uint8)
cv2.drawContours(out, [cnt], -1, 255, cv2.FILLED)
out = cv2.bitwise_and(img, out)

cv2.imshow('img', img)
cv2.imshow('inter', inter)
cv2.imshow('out', out)
cv2.waitKey(0)
cv2.destroyAllWindows()
Comment

PREVIOUS NEXT
Code Example
Python :: Exception Type with except block: 
Python :: Freqtrade - sell after x candels 
Python :: pytorch pad to square 
Python :: round up 
Python :: what is python virtual environment 
Python :: pyspark pivot max aggregation 
Python :: error 302 heroku django 
Python :: how to import the whall library in python 
Python :: convert c code to python code online 
Python :: keep calm and carry on memes 
Python :: for in range loop python 
Python :: loading model 
Python :: python 3.7.8 download 
Python :: python convert string to raw string 
Python :: using progress bar with rich python 
Python :: sort an array in python 
Python :: python hide terminal 
Python :: how to make dice roll in python 
Python :: python order list of dictionaries by value 
Python :: index in for loop 
Python :: how to plot using pyplot 
Python :: datetime am pm python 
Python :: py scrapy 
Python :: python find lcm 
Python :: how to store a return value in a variable in python 
Python :: how to check if a string contains spaces in python 
Python :: pip path windows 10 
Python :: char in python 
Python :: docstring python 
Python :: what does filename = path(file).stem python 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =