imfill

来源:互联网 发布:软件测试数据库面试题 编辑:程序博客网 时间:2024/06/06 18:45
Fill image regions and holes.
    BW2 = imfill(BW1,LOCATIONS) performs a flood-fill operation on
    background pixels of the input binary image BW1, starting from the
    points specified in LOCATIONS. 

    BW2 = imfill(BW1,'holes') fills holes in the input image.  A hole is
    a set of background pixels that cannot be reached by filling in the
    background from the edge of the image.

    I2 = imfill(I1) fills holes in an intensity image, I1.  In this
    case a hole is an area of dark pixels surrounded by lighter pixels.

imfill - Free thought - Free Thought
需求:如上图所示,想将其中的闭合区域物体部分整体标记出来,去除掉里面的细小区域,用此函数即可达到此目的

 imfill(edgeMapTemp,'holes');
以下是结果:
imfill - Free thought - Free Thought
注意到其中的小区域已经消失,而靠近边缘处的区域也没有填充,因此此算法是flood fill算法,从边缘处开始寻找,如果有多余两处的非边缘闭合区域,则都被填充,如下图所示,将图1中最上面的非闭合区域进行闭合(只是加了一条线),再进行同样的操作后,会出现如下结果:
imfill - Free thought - Free Thought
 imfill - Free thought - Free Thought 
因此,在进行此操作时,一定要注意其中的闭合区域是否属于自己可控范围之内。
 
0 0