FloodFill填充算法利用的是一种广度搜索的方法,将处于设定灰度的像素点设置为新像素
一些伪代码http://en.wikipedia.org/wiki/Flood_fill
openCV实现
#include <cv.h> #include <highgui.h> void main() { //以原始通道数读取图片1 IplImage* img1 = cvLoadImage("D://vc6.0//MSDev98//MyProjects//MachineVision//TestPic//Lena.bmp",CV_LOAD_IMAGE_UNCHANGED); IplImage* img2 = cvLoadImage("D://vc6.0//MSDev98//MyProjects//MachineVision//TestPic//Lena.bmp",CV_LOAD_IMAGE_UNCHANGED); //命名窗口 cvNamedWindow("Origin", CV_WINDOW_AUTOSIZE); cvNamedWindow("Fill", CV_WINDOW_AUTOSIZE); //利用3*3模板进行第一次腐蚀 cvFloodFill(img2, cvPoint(100,25),cvScalar(255), cvScalar(25), cvScalar(25), NULL, 4 | CV_FLOODFILL_FIXED_RANGE, NULL); //显示图片 cvShowImage("Origin", img1); cvShowImage("Fill", img2); cvWaitKey(0); cvReleaseImage(&img1); cvReleaseImage(&img2); }
原文:http://blog.csdn.net/lampqiu/article/details/38681123