Will flood fill reach a matching region across a barrier?
floodfill expands from a seed through connected qualifying pixels and modifies the image in place.
Pixel experiment and interpretation
A black wall separates two identical gray patches. Pouring paint on the left changes only that side. Check that barriers really close before using flood fill for instance labels.
from PIL import Image, ImageDraw
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
im=row([8,8,0,8,8])
ImageDraw.floodfill(im,(0,0),99)
list(im.tobytes())Result [99, 99, 0, 8, 8]
中文
灰度相近但不连通的区域会一起被填充吗?
floodfill 从种子位置向连通的符合条件像素扩展,修改原图。
像素实验与适用边界
两块相同灰色被黑墙隔开,从左边灌漆只会改变左块。用于实例标注时还要确认屏障真的闭合。
from PIL import Image, ImageDraw
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
im=row([8,8,0,8,8])
ImageDraw.floodfill(im,(0,0),99)
list(im.tobytes())结果 [99, 99, 0, 8, 8]