【发布时间】:2021-08-06 04:49:20
【问题描述】:
我有一个带有组件的图像,我创建了一个蒙版并从中提取了红色区域,然后对具有某些阈值大小的组件应用了一些修复... 但是当我应用 cv2.inpaint 时,它会留下一些红色的痕迹......我不知道为什么...... 这是代码。
lower_red = np.array([0,220,0]) #lower red color limit
upper_red = np.array([100,255,255]) # upper limit
mask = cv2.inRange(hsv,lower_red,upper_red) # masking red colored areas
nb_components, output, stats, centroids = cv2.connectedComponentsWithStats(mask, 8) # finding components
sizes = stats[1:, -1]; nb_components = nb_components - 1 # getting areas of each component
min_size = 800 # threshold of component size
inpaint_mask = np.zeros((output.shape))
for i in range(0, nb_components):
if sizes[i] <= min_size:
inpaint_mask[output == i + 1] = 255
inpaint_mask = inpaint_mask.astype('uint8')
dst = cv2.inpaint(src = rgb,inpaintMask=inpaint_mask,inpaintRadius=10, flags = cv2.INPAINT_TELEA)
plt.figure(figsize=(20,20),dpi=80)
plt.imshow(dst)
这是输入图像:
输出图像:
【问题讨论】:
标签: python image opencv image-processing computer-vision