bwlabel、regionprops

L = bwlabel(BW,n)
返回一个和BW大小相同的L矩阵,包含了标记了BW中每个连通区域的类别标签,这些标签的值为1、2、num(连通区域的个数)。n的值为4或8,表示是按4连通寻找区域,还是8连通寻找,默认为8。
四连通或八连通是图像处理里的基本感念:而8连通,是说一个像素,如果和其他像素在上、下、左、右、左上角、左下角、右上角或右下角连接着,则认为他们是联通的;4连通是指,如果像素的位置在其他像素相邻的上、下、左或右,则认为他们是连接着的,连通的,在左上角、左下角、右上角或右下角连接,则不认为他们连通。
[L,num] = bwlabel(BW,n)
这里num返回的就是BW中连通区域的个数。

举例说明: BW =     1     1     1     0     0     0     0     0     1     1     1     0     1     1     0     0     1     1     1     0     1     1     0     0     1     1     1     0     0     0     1     0     1     1     1     0     0     0     1     0     1     1     1     0     0     0     1     0     1     1     1     0     0     1     1     0     1     1     1     0     0     0     0     0 按4连通计算,方形的区域,和翻转的L形区域,有用是对角连接,不属于连通,所以分开标记,连通区域个数为3


L = bwlabel(BW,4) 
结果如下:
L =
    1     1     1     0     0     0     0     0
    1     1     1     0     2     2     0     0
    1     1     1     0     2     2     0     0
    1     1     1     0     0     0     3     0
    1     1     1     0     0     0     3     0
    1     1     1     0     0     0     3     0
    1     1     1     0     0     3     3     0
    1     1     1     0     0     0     0     0
而8连通标记,它们是连通的: 
[L, num] = bwlabel(BW,8) 
L =
    1     1     1     0     0     0     0     0
    1     1     1     0     2     2     0     0
    1     1     1     0     2     2     0     0
    1     1     1     0     0     0     2     0
    1     1     1     0     0     0     2     0
    1     1     1     0     0     0     2     0
    1     1     1     0     0     2     2     0
    1     1     1     0     0     0     0     0
这里
num =
    2

[r,c] = find(L==2);
rc = [r c]
rc =
 
     2     5
     3     5
     2     6
     3     6
 

regionprops

功能:用来度量图像区域属性的函数.
语法:STATS = regionprops(L,properties)
描 述:测量标注矩阵 L中每一个标注区域的一系列属性。L 中不同的正整数元素对应不同的区域, 例如:L 中等于整数1的元素对应区域1;L 中等于整数2的元素对应区域2;以此类推。
返回值STATS 是一个长度为 max(L(:))的结构 数组,结构数组的相应域定义了每一个区域相应属性下的度量。 properties 可以是由逗号分割的字符串列表,包含字符串的单元 数组,单个字符串 'all' 或者 'basic'。如果 properties 等于字符串 'all',则所有下述字串列表中的度量数据都将被计算,如果properties 没有指定或者等于 'basic',则属性 'Area'、'Centroid' 和'BoundingBox' 将被计算。
'Area' 图像各个区域中像素总个数 'BoundingBox' 包含相应区域的最小矩形 'Centroid' 每个区域的质心(重心)
p3=im2bw(p3);
[L,num]=bwlabel(p3,8); imshow(L);
stats=regionprops(L,'Area');   clo=size(stats,1);   disp('area……');   for i=1:clo   disp(stats(i).Area);   end
03-13
### bwlabel Function Usage in Image Processing In the context of image processing within MATLAB, `bwlabel` is a fundamental function used to label connected components in binary images. This process assigns labels to different objects (connected regions) found in an input binary image. The syntax for using this function includes: ```matlab L = bwlabel(BW); [L, num] = bwlabel(BW); ``` Here, `BW` represents the binary image where each pixel has values either as 0s or 1s indicating background and foreground respectively[^1]. The output argument `L`, known as the labeled matrix, contains integers that represent distinct objects identified by connectivity criteria. Each object receives its own unique integer value starting from 1 up through the total number of detected objects. Additionally, when requesting two outputs (`L` and `num`), `num` returns the count of these separate entities present inside the original picture. Connectivity can be defined based on whether pixels are adjacent horizontally/vertically only (4-connectivity) or also diagonally (8-connectivity). By default, `bwlabel` uses 8-connectivity unless specified otherwise via additional parameters during invocation: ```matlab L = bwlabel(BW, conn); ``` Where `conn` could take one of two possible scalar inputs: 4 or 8 representing respective types of connectivities mentioned above. After labeling with `bwlabel`, further operations such as measuring properties about individual blobs like area size, centroid location etc., become feasible utilizing other functions provided under regionprops command set available in MATLAB's Image Processing Toolbox.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值