如何在涂料应用的填充操作的工作?涂料、操作、如何在、工作

2023-09-11 00:08:06 作者:超新超好的英文名 男孩

所有的绘图程序,独立于它们是如何简单或复杂的是,配备了填充工具。这基本上取代的封闭区域与另一种颜色的颜色。我知道,有不同的API来做到这一点,但我感兴趣的算法研究。什么是一个高效的算法来实现这个工具?

All paint programs, independent of how simple or complex they are, come with a fill tool. This basically replaces the color of a closed region with another color. I know that there are different APIs to do this, but I am interested in the algorithm. What would be an efficient algorithm to implement this tool?

一对夫妇的事情,我能想到的快速如下:

A couple of things I can think of quickly are:

在转换图像转换成二进制的地图,其中的彩色像素被替换为 1 和所有其他颜色 0 。 找到各地要更改,使得所有像素内的1,所有的相邻像素是0点的封闭区。 Convert image into a binary map, where pixels in the color to be replaced are 1 and all other colors are 0. Find a closed region around the point you want to change such that all the pixels inside are 1 and all the neighbouring pixels are 0.

样品图像

推荐答案

许多实现都是因为一个递归征服和除法算法。如果你做一个快速谷歌的洪水填充算法,你会发现很多资源,包括的话题

Many implementations are done as a recursive conquer and divide algorithm. If you do a quick google for "flood fill algorithm" you will find plenty of resources including the excellent wikipedia page on the topic.