📜  Flood-fill 和 Boundary-fill 算法的区别

📅  最后修改于: 2021-09-13 02:43:45             🧑  作者: Mango

洪水填充算法:
洪水填充算法也称为种子填充算法。它确定连接到多维数组中给定节点的区域。该算法的工作原理是填充或重新着色包含不同颜色的选定区域的内部部分以及图像的边界。它通常由一张图片来说明,该图片具有以各种不同颜色区域为边界的邻域。为了绘制这些区域,我们将替换特定的内部颜色而不是发现边界颜色值。这是由于洪水填充算法而理解该方法的基本原理。
现在,有两种方法将用于通过连接像素来创建无限边界 – 4-connected 和 8-connected 方法。在 4-connected 方法中,像素最多可以有四个邻居,分别位于当前像素的右侧、左侧、上方和下方。相反,在8-connected方法中,它可以有8个,并针对四个对角线像素检查相邻位置。因此,这两种方法中的任何一种通常都不会重新绘制内部点。

边界填充算法
它遵循一种方法,即区域填充从位于区域内部的某个范围开始,并将内部向边界绘制。如果边界包含单一颜色,则填充算法在向外方向逐个像素地继续,直到遇到边界颜色。边界填充算法通常主要在交互式绘画包中实现,其中内部点很容易选择。
边界填充的功能开始于接受室内点 (x, y) 的坐标,边界颜色和填充颜色成为输入。从 (x, y) 开始,该方法检查相邻位置以发现它们是否是边界颜色的一部分。如果它们不是来自边界颜色,则用填充颜色绘制它们,并根据条件测试它们的相邻像素。当检查世界边界颜色之前的所有像素时,该过程结束。

Flood-fill 和 Boundary-fill 算法的区别:

Flood-fill Algorithm Boundary-fill Algorithm
It can process the image containing more than one boundary colours. It can only process the image containing single boundary colour.
Flood-fill algorithm is comparatively slower than the Boundary-fill algorithm. Boundary-fill algorithm is faster than the Flood-fill algorithm.
In Flood-fill algorithm a random colour can be used to paint the interior portion then the old one is replaced with a new one. In Boundary-fill algorithm Interior points are painted by continuously searching for the boundary colour.
It requires huge amount of memory. Memory consumption is relatively low in Boundary-fill algorithm.
Flood-fill algorithms are simple and efficient. The complexity of Bounndary-fill algorithm is high.

如果您希望与专家一起参加现场课程,请参阅DSA 现场工作专业课程学生竞争性编程现场课程。