use cv2.connectedComponentswithstats to display images

Deadly 提交于 2020-01-25 06:51:11

问题


I have an image and I want to remove the white small dots from the image. I read many post and found cv2.connectedComponentsWithStats would work. But how to display the images using its output.Below is my code :

import cv2
import numpy as np
from matplotlib import pyplot as plt
src = cv2.imread("./folder/0607130001-1.png",0)
binary_map = (src > 0).astype(np.uint8)
connectivity = 4 # or whatever you prefer
output = cv2.connectedComponentsWithStats(binary_map, connectivity,cv2.CV_32S)
plt.subplot(221),plt.imshow(src,cmap='gray')
plt.title('Original')                
plt.subplot(222),plt.imshow(output,cmap = 'gray')
plt.title('Result')
plt.show()

My image is: I want to remove all small white dots from the image. I used this code but its not displaying the image.

来源:https://stackoverflow.com/questions/57282827/use-cv2-connectedcomponentswithstats-to-display-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!