我需要OpenCV的帮助我有一个复杂的躺在地上的图片,现在我需要从图片中提取这个形式,并清除它的噪音。但现在有一个标志,我需要删除和4个洞来识别。What i could doOriginal image
我目前的代码:
import cv2
import numpy as np
# Read the original image
img = cv2.imread('Amoebe_1.jpg')
# resize image
scale_down = 0.4
img = cv2.resize(img, None, fx= scale_down, fy= scale_down, interpolation= cv2.INTER_LINEAR)
# Display original image
cv2.imshow('Original', img)
cv2.waitKey(0)
# Denoising
dst = cv2.fastNlMeansDenoisingColored(img,None,20,10,10,21)
# Canny Edge Detection
edges = cv2.Canny(image=dst, threshold1=100, threshold2=200) # Canny Edge Detection
# Contour Detection
contours1, hierarchy1 = cv2.findContours(edges, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
# draw contours on the original image for `CHAIN_APPROX_SIMPLE`
image_copy1 = img.copy()
cv2.drawContours(image_copy1, contours1, -1, (0, 255, 0), 2, cv2.LINE_AA)
# see the results
cv2.imshow('Simple approximation', image_copy1)
# Display Canny Edge Detection Image
cv2.imshow('Canny Edge Detection', edges)
cv2.waitKey(0)
#Floodfill
h,w,chn = img.shape
seed = (w/2,h/2)
mask = np.zeros((h+2,w+2),np.uint8)
bucket = edges.copy()
cv2.floodFill(bucket, mask, (0,0), (255,255,255))
cv2.imshow('Mask', bucket)
cv2.waitKey(0)
cv2.destroyAllWindows()
1条答案
按热度按时间gwbalxhn1#
在ImageJ中对此进行尝试,从原始图像中提取红色通道,得到以下结果:
运行一个小的(3pix)中值滤波器和阈值处理得到一个二进制图像:
在最后一个上运行
cv.findContours()
并分析轮廓区域应该会给予你一些小洞和“眼睛”。用cv.drawContours()
和较大的物体来填充眼睛和标志区域,也许用dilate()
来填充小的差异。