简体   繁体   中英

How to remove the noise from the image to set the pixel value in connected components?

I have applied the ostu thresholding at an input image.After this I appled the connected components analysis.I want to remove the noise in which connected components with less than 25 is considered as noise.

## 8 adjacency connectivity method to search the document image.
connectivity = 8                  

## find the connected components 

output = cv2.connectedComponentsWithStats(invr_binary, connectivity, cv2.CV_32S) 
## it contain fou variable

(numLabels, labels, stats, centroids) = output

what is the next steps I could not understand?

I have used the stats to remove the noise.Stats: Statistics on each connected component, including the bounding box coordinates and area (in pixels).

def imshow(image):
    plt.figure(figsize=(20,10)
    plt.imshow(image)

areas = stats[1:,cv2.CC_STAT_AREA]
result = np.zeros((labels.shape), np.uint8)
for i in range(0, numLabels - 1):
    if areas[i] >= 25:   #keep
    result[labels == i + 1] = 255
imshow(result)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM