问题
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