Flood fill algorithm
Flood fill算法是从一个区域中提取若干个连通的点与其他相邻区域区分开的经典算法。因为其思路类似洪水从一个区域扩散到所有能到达的区域而得名。在GNU Go和扫雷中,Flood Fill算法被用来计算需要被清除的区域。
https://www.educative.io/edpresso/what-is-the-flood-fill-algorithm
The flood fill algorithm is used to determine the properties of the area around a particular cell in a block. The algorithm is implemented in the bucket fill tool of the Microsoft Paint program(桶填充), which colors the similarly colored pixels, or cells, with another color.
//Flood fill algorithm implemented in Javaclass Example {public static int M=8; public static int N=8;static void floodFill(int [][] myScreen, int x, int y, int currColor, int newColor) { // Base cases if (x < 0 || x >= Example.M || y < 0 || y >= Example.N) return; if (myScreen[x][y] != currColor) return; if (myScreen[x][y] == currColor) return; // Replace the color at cell (x, y) myScreen[x][y] = newColor; // Recursively call for north, east, south and west floodFill(myScreen, x+1, y, currColor, newColor); floodFill(myScreen, x-1, y, currColor, newColor); floodFill(myScreen, x, y+1, currColor, newColor); floodFill(myScreen, x, y-1, currColor, newColor); }static void findColor(int [][] myScreen, int x, int y, int newColor) { int currColor = myScreen[x][y]; floodFill(myScreen, x, y, currColor, newColor); } public static void main( String args[] ) {int [][] myScreen= new int [][]{{3, 2, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 0, 0}, {1, 0, 0, 1, 1, 0, 1, 1}, {1, 2, 2, 2, 2, 0, 1, 0}, {1, 1, 1, 2, 2, 0, 1, 0}, {1, 1, 1, 2, 2, 2, 2, 0}, {1, 1, 1, 1, 1, 2, 1, 1}, {1, 1, 1, 1, 1, 2, 2, 1}, }; //printing initial screenSystem.out.println("Initial myScreen : "); for (int i=0; i<Example.M; i++) { for (int j=0; j<Example.N; j++) {System.out.print(myScreen[i][j] + " ");}System.out.print("\n");}int x = 4, y = 4, newColor = 3; findColor(myScreen, x, y, newColor); System.out.print("\n");System.out.println("Updated myScreen : "); //printing updatedscreenfor (int i=0; i<Example.M; i++) { for (int j=0; j<Example.N; j++) {System.out.print(myScreen[i][j] + " ");}System.out.print("\n");}}
}
see the programme in geeksfoegeeks:
https://www.geeksforgeeks.org/flood-fill-algorithm-implement-fill-paint/
(x,y)变颜色,(x,y)周围的像素也变色
Flood fill algorithm相关推荐
- 图像处理------泛洪填充算法(Flood Fill Algorithm) 油漆桶功能
泛洪填充算法(Flood Fill Algorithm) 泛洪填充算法又称洪水填充算法是在很多图形绘制软件中常用的填充算法,最熟悉不过就是 windows paint的油漆桶功能.算法的原理很简单,就 ...
- 算法介绍 | 泛洪算法(Flood fill Algorithm)
算法别名: 漫水填充算法.种子填充算法(Seed Fill) 作用: 用于确定连接到多维数组中给定节点的区域,可以用来标记或者分离图像的一部分,实现如Ps中自动选区功能. 基本思想: 顾名思义就像洪水 ...
- 洪水填充算法_洪水填充(Flood fill)算法
洪水填充(Flood fill)算法 从一个起始节点开始把附近与其连通的节点提取出或填充成不同颜色颜色,直到封闭区域内的所有节点都被处理过为止,是从一个区域中提取若干个连通的点与其他相邻区域区分开(或 ...
- AcWing 1113. 红与黑【《信息学奥赛一本通》】【DFS】【BFS】【Flood Fill】
AcWing 1113. 红与黑 一.题目链接 二.题目分析 (一)算法标签 (二)解题思路 三.AC代码 解法一(BFS): 解法二(DFS): 四.其它题解 一.题目链接 AcWing 1113. ...
- 算法提高课学习——2.搜索——2.1.Flood Fill算法
Flood Fill Flood Fill算法用于求图中的连通块数量,一般用BFS实现,不过也可以使用DFS来实现,更加简洁,但同时也可能会有爆栈的风险 对于图中的任意一个点,我们从该点出发标记它所有 ...
- Flood Fill
文章目录 前言 一.Flood Fill 二.例题,代码 AcWing 1097. 池塘计数 本题分析 AC代码 AcWing 1098. 城堡问题 本题分析 AC代码 AcWing 1106. 山峰 ...
- BFS 之Flood Fill 算法
一个很重要的点:只有边权为1时才能应用BFS算法 习题篇:(12条消息) BFS 之Flood Fill 算法(二)_Dream.Luffy的博客-CSDN博客 算法介绍: 一如往常,我们先看看Fl ...
- BFS Flood Fill and 最短路模型
Flood Fill 可以在线性的复杂度内找到某点所在连通块 1.Lake Counting #include <cstring> #include <iostream> #i ...
- Flood Fill算法总结
最近一直跟着y总在刷蓝桥杯的课,借此我来对里面涉及到的Flood Fill算法做一个我目前接触到的所有的flood fill算法的总结 总 首先,这本质上是一个搜索算法.他的作用是对一个图(目前我用到 ...
最新文章
- Linux中vi的常用命令和快捷键使用
- python学习日常-编码与字符串格式化
- truncate table 非常慢_你真的知道怎么分析mysql的慢sql吗?
- Js里面IF(var)表示什么意思?js中if的写法、含义
- Android GUI之Window、WindowManager
- springMVC中添加命名空间(edit namespace)
- 网页排版规则:你需要知道的
- JSK-23223 数字反转【进制】
- H5页面快速搭建之高级字体应用实践
- ofo在MaxCompute的大数据开发之路
- API调用,API传参,面向对接开发,你真的会写接口文档吗?
- 加拿大办理电动自行车申请GCC认证
- 披着“云”衣裳的狗——搜狗输入法“云”版本尝鲜记
- 一篇博客收能收录计算机网络?
- C/C++ 16bit转8bit
- pmp复习资料链接-2021.06.20考试(中培)
- 实时数据库简介和比较
- 7-4 愿天下有情人都是失散多年的兄妹 (25 分)
- IDEA-第一个Javaweb项目
- Android工程师进阶34讲学习笔记