标签:
OpenCV中的函数原型如下:
int floodFill(InputOutputArray image, Point seedPoint, Scalar newVal, Rect* rect=0, Scalar loDiff=Scalar(), Scalar upDiff=Scalar(), int flags=4 )
int floodFill(InputOutputArray image, Point seedPoint, Scalar newVal, Rect* rect=0, Scalar loDiff=Scalar(), Scalar upDiff=Scalar(), int flags=4 )
flags=8 | FLOODFILL_MASK_ONLY | FLOODFILL_FIXED_RANGE | (47<<8)
Mat srcImage=imread("M:/图像处理实验/floodFill/test_.bmp"); Rect ccomp; floodFill(srcImage, Point(1, 1), CV_RGB(205, 205, 205), &ccomp, Scalar(15, 15, 15), Scalar(15, 15, 15), 8 | FLOODFILL_FIXED_RANGE ); imwrite("M:/图像处理实验/floodFill/test_dst.bmp", srcImage);种子点为(1,1)。下面为原图与漫水填充后的结果对比:
eg。
Mat srcImage=imread("M:/图像处理实验/floodFill/云.bmp"); Mat mask; mask.create(((srcImage).rows + 2), ((srcImage).cols + 2), CV_8UC1); mask = Scalar::all(0); Mat ImageROI; ImageROI = mask(Rect(1, 1, (srcImage).cols, (srcImage).rows)); Mat dstImage; Mat dstImage_canny; srcImage.copyTo(dstImage_canny); cvtColor(dstImage_canny, dstImage_canny, CV_RGB2GRAY); medianBlur(dstImage_canny, dstImage_canny, 7); Canny(dstImage_canny, dstImage, 3, 3 * 3, 3); dstImage.copyTo(ImageROI); Rect ccomp; //选择了三个种子点,分别赋予了三种填充颜色。 //第一次调用floodFill时,未添加canny边缘检测后的掩模,所以云的边缘被腐蚀掉了一部分。结果就是部分云消失了。 //后两次调用floodFill时,添加了canny边缘检测后的掩模,云的边缘得到了很好的保留,但是部分颜色变化较大的区域,canny后,检验出了边缘,边缘的原来颜色得到了保留 floodFill(srcImage, Point(223, 184), CV_RGB(88,123,165), &ccomp, Scalar(35, 35, 35), Scalar(30, 30, 30), 8 | FLOODFILL_FIXED_RANGE ); floodFill(srcImage, mask, Point(48, 507), CV_RGB(108,148,184), &ccomp, Scalar(25, 25, 25), Scalar(15, 15, 15), 8 | FLOODFILL_FIXED_RANGE ); floodFill(srcImage, mask, Point(609, 582), CV_RGB(137,173,197), &ccomp, Scalar(25, 25, 25), Scalar(15, 15, 15), 8 | FLOODFILL_FIXED_RANGE ); imwrite("M:/图像处理实验/floodFill/云_dst.bmp", srcImage);
canny边缘检测后的输出,也是floodFill函数中的掩模。黑色区域可以被填充,白色部分保留原来的颜色。
EmguCV中的函数原型如下:
Public Shared Function FloodFill(src As Emgu.CV.IInputOutputArray, mask As Emgu.CV.IInputOutputArray, seedPoint As System.Drawing.Point, newVal As Emgu.CV.Structure.MCvScalar, ByRef rect As System.Drawing.Rectangle, loDiff As Emgu.CV.Structure.MCvScalar, upDiff As Emgu.CV.Structure.MCvScalar, Optional connectivity As Emgu.CV.CvEnum.Connectivity = FourConnected, Optional flags As Emgu.CV.CvEnum.FloodFillType = Default) As Integer
Dim bkGrayWhite As New Gray(255) Dim bkGrayBlack As New Gray(0) Dim img As Image(Of Bgr, Byte) = New Image(Of Bgr, Byte)("M:\图像处理实验\FloodFill\云1.bmp") Dim img_MedianBlur As Image(Of Bgr, Byte) = New Image(Of Bgr, Byte)(img.Width, img.Height) img.CopyTo(img_MedianBlur) CvInvoke.MedianBlur(img, img_MedianBlur, 7) Dim mask As Image(Of Gray, Byte) = New Image(Of Gray, Byte)(img.Width + 2, img.Height + 2, bkGrayBlack) ‘BGR CvInvoke.FloodFill(img, mask, New System.Drawing.Point(2, 2), New MCvScalar(165, 123, 88), New System.Drawing.Rectangle(0, 0, 0, 0), New MCvScalar(5, 5, 5), New MCvScalar(5, 5, 5), Emgu.CV.CvEnum.Connectivity.EightConnected, Emgu.CV.CvEnum.FloodFillType.FixedRange ) CvInvoke.cvSetImageROI(mask, New System.Drawing.Rectangle(1, 1, img.Width, img.Height)) Dim img_canny As Image(Of Gray, Byte) = New Image(Of Gray, Byte)(img.Width, img.Height, bkGrayBlack) CvInvoke.Canny(img_MedianBlur, img_canny, 5, 5 * 3) img_canny.CopyTo(mask) CvInvoke.cvResetImageROI(mask) CvInvoke.FloodFill(img, mask, New System.Drawing.Point(668, 570), New MCvScalar(197, 173, 137), New System.Drawing.Rectangle(0, 0, 0, 0), New MCvScalar(25, 25, 25), New MCvScalar(5, 5, 5), Emgu.CV.CvEnum.Connectivity.EightConnected, Emgu.CV.CvEnum.FloodFillType.FixedRange ) img.Save("M:\图像处理实验\FloodFill\云1_result.bmp")
标签:
原文地址:http://blog.csdn.net/u013162930/article/details/51792750