Python 洪水填充算法-我的实现中的错误

Python 洪水填充算法-我的实现中的错误,python,python-3.x,algorithm,image-processing,scikit-image,Python,Python 3.x,Algorithm,Image Processing,Scikit Image,我试图学习如何在Python中实现洪水填充算法(基于队列)。 根据这一页,我准备了我的版本。不幸的是,我已经花了很多时间,我无法找到我有错误的地方。你能帮我吗 我修改了scikit图像中的原始示例: 将numpy导入为np 将matplotlib.pyplot作为plt导入 从skimage导入数据,筛选 #从skimage.segmentation导入洪水,洪水填充 从DFS循环中的flood_algorithm import flood_fill#中,您错误地使用了起点。您应该在弹出的点上色

我试图学习如何在Python中实现洪水填充算法(基于队列)。 根据这一页,我准备了我的版本。不幸的是,我已经花了很多时间,我无法找到我有错误的地方。你能帮我吗

我修改了scikit图像中的原始示例:

将numpy导入为np
将matplotlib.pyplot作为plt导入
从skimage导入数据,筛选
#从skimage.segmentation导入洪水,洪水填充

从DFS循环中的flood_algorithm import flood_fill#中,您错误地使用了
起点。您应该在弹出的
点上色并展开,如:

    while q:
        point = q.popleft()
        
        if is_inside_image(point, input_array.shape):
            if input_array[point[0]][point[1]] == source_colour:
                input_array[point[0]][point[1]] = target_colour
                
                q.append((point[0] + 1, point[1]))
                q.append((point[0] - 1, point[1]))
                q.append((point[0]    , point[1] + 1))
                q.append((point[0]    , point[1] - 1))

在DFS循环中,您错误地使用了
起点
。您应该在弹出的
点上色并展开,如:

    while q:
        point = q.popleft()
        
        if is_inside_image(point, input_array.shape):
            if input_array[point[0]][point[1]] == source_colour:
                input_array[point[0]][point[1]] = target_colour
                
                q.append((point[0] + 1, point[1]))
                q.append((point[0] - 1, point[1]))
                q.append((point[0]    , point[1] + 1))
                q.append((point[0]    , point[1] - 1))

唯一检查颜色的点是
start\u点
。您从队列中弹出的
从未用于任何用途。非常感谢。您唯一检查过的点是
起点
。您从队列中弹出的
从未用于任何事情。非常感谢。
    while q:
        point = q.popleft()
        
        if is_inside_image(point, input_array.shape):
            if input_array[point[0]][point[1]] == source_colour:
                input_array[point[0]][point[1]] = target_colour
                
                q.append((point[0] + 1, point[1]))
                q.append((point[0] - 1, point[1]))
                q.append((point[0]    , point[1] + 1))
                q.append((point[0]    , point[1] - 1))