def flood_fill_edges(img, stride):
"""
Check the strideth pixel along each edge of the image.
If it is white, floodfill the image black from that point.
"""
black = 0
white = 255
(rows, cols) = img.shape
msk = np.zeros((rows+2, cols+2, 1), np.uint8)
# Left and right edges
i = 0
while i < rows:
if img[i, 0] == white:
cv2.floodFill(img, msk, (0, i), black)
if img[i, cols-1] == white:
cv2.floodFill(img, msk, (cols-1, i), black)
i += stride
# Top and bottom edges
i = 0
while i < cols:
if img[0, i] == white:
cv2.floodFill(img, msk, (i, 0), black)
if img[rows-1, i] == white:
cv2.floodFill(img, msk, (i, rows-1), black)
i += stride
评论列表
文章目录