matlab中连通域标注,matlab 标注连通域

clear;

clc;

f=imread('c:\1.jpg');

gray_level=graythresh(f);

f=im2bw(f,gray_level);

[l,n]=bwlabel(f,8)

imshow(f)

hold on

for k=1:n

[r,c]=find(l==k);

rbar=mean(r);

cbar=mean(c);

plot(cbar,rbar,'Marker','o','MarkerEdgeColor','k','MarkerFaceColor','k','MarkerSize',10);

plot(cbar,rbar,'Marker','*','MarkerEdgecolor','w');

end

主要概念:

1.       4连接  8连接

0   1   0

1   p   1  ===>  4连接,p为当前像素点。

0   1   0

1   1   1

1   p   1  ====》8连接, p为当前像素点。

1   1   1

2.       bwlabel()函数

语法:   [ L, num]=bwlabel(f,conn)

其中f是一副二值图像,conn用来指定期望的连接(不是4就是8),默认为8,输出L称为标记矩阵,参数num给出所找到连接分量的总数。

3.       find()函数

该函数非常有用,会返回指定条件的索引值,在标记矩阵中的作用是返回对应对象的索引。

I = FIND(X) returns the linear indices corresponding to

the nonzero entries of the array X.  X may be a logical expression.

Use IND2SUB(SIZE(X),I) to calculate multiple subscripts from

the linear indices I.

find(bwlabel(bw)==2)表示的意思是连通域2中的数值所在向量的位置。

4.       mean()函数

求数组平均值

matlab函数_连通区域

1、 matlab函数bwareaopen——删除小面积对象 格式:BW2 = bwareaopen(BW,P,conn) 作用:删除二值图像BW中面积小于P的对象,默认情况下使用8邻域。 算法: (1)Determine the connected components. L = bwlabeln(BW, conn); (2)Compute the area of each component. S = regionprops(L, 'Area'); (3)Remove small objects. bw2 = ismember(L, find([S.Area] >= P)); 2、matlab函数bwarea——计算对象面积 格式:total = bwarea(BW) 作用:估计二值图像中对象的面积。 注:该面积和二值图像中对象的像素数目不一定相等。 3、matlab函数imclearborder——边界对象抑制 格式:IM2 = imclearborder(IM,conn) 作用:抑制和图像边界相连的对象。若IM是二值图,imclearborder将删除和图像边界相连的对象。默认情况conn=8。 注:For grayscale images, imclearborder tends to reduce the overall intensity level in addition to suppressing border structures. 算法: (1)Mask image is the input image. (2)Marker image is zero everywhere except along the border, where it equals the mask image. 4、matlab函数bwboundaries——获取对象轮廓 格式:B = bwboundaries(BW,conn)(基本格式) 作用:获取二值图中对象的轮廓,和OpenCV中cvFindContours函数功能类似。B是一个P×1的cell数组,P为对象个数,每个cell 是Q×2的矩阵,对应于对象轮廓像素的坐标。 5、matlab函数imregionalmin——获取极小值区域 格式:BW = imregionalmin(I,conn) 作用:寻找图像I的极小值区域(regional maxima),默认情况conn=8。 Regional minima are connected components of pixels with a constant intensity value, and whose external boundary pixels all have a higher value. 6、matlab函数bwulterode——距离变换的极大值 格式:BW2 = bwulterode(BW,method,conn) 作用:终极腐蚀。寻找二值图像BW的距离变换图的区域极大值(regional maxima)。用于距离变换的距离默认为euclidean,连通性为8邻域。 7、regionprops统计被标记的区域的面积分布,显示区域总数。 函数regionprops语法规则为:STATS = regonprops(L,properties) 该函数用来测量标注矩阵L中每一个标注区域的一系列属性。 L中不同的正整数元素对应不同的区域,例如:L中等于整数1的元素对应区域1;L中等于整数2的元素对应区域2;以此类推。 返回值STATS是一个长度为max(L()的结构数组,结构数组的相应域定义了每一个区域相应属性下的度量。 Properties可以是由逗号分割的字符串列表、包含字符串的单元数组、单个字符串'all'或者'basic'。如果properties等于字符串'all',则表4.1中的度量数据都将被计算;如果properties等于字符串'basic',则属性:'Area','Centroid'和'BoundingBox'将被计算。表1就是所有有效的属性字符串

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值