[Python] skimage flood_fill Doesn't Fill the Black part of a Binarized Image

Discussão em 'Python' iniciado por Stack, Junho 30, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to use flood_fill on a binarized image so I can get a good fill of an image. However, it only fills the image if it's a 0 pixel.

    I've tried changing the pixel value with flower[flower == 255] = 200, and I've tried different thresholds. It's important I fill the whole entire space so I can find the specific pixels on the edges of it.

    from skimage.segmentation import flood_fill
    import cv2
    import matplotlib.pyplot as plt
    import numpy as np

    fill = (260, 120) # Doesn't work
    #fill = (200, 300) # Works great

    # https://i.pinimg.com/736x/0e/a4/5f/0ea45f6b6885aa6a327ce8ae55038b17.jpg
    flower = cv2.imread('flower.png', cv2.IMREAD_GRAYSCALE)
    flower = cv2.threshold(flower, 100, 255, cv2.THRESH_BINARY)[1] # If I remove this they both work great, but the fill isn't perfect

    filled_flower = flood_fill(flower, fill, 100)

    plt.imshow(filled_flower, cmap='gray')
    plt.plot(fill[1], fill[0], 'wo')
    np.shape(filled_flower)

    Continue reading...

Compartilhe esta Página