regionprops统计被标记的区域的面积分布,显示区域总数。
配合[L,num]=bwlabel(bw,8);
%另一篇博文里有函数regionprops语法规则为:
STATS = regionprops(C,properties)
properties字符串列表
Area
EquivDiameter
MajorAxisLength
BoundingBox
EulerNumber
MinorAxisLength
Centroid
Extent
Orientation
ConvexArea
Extrema
PixelIdxList
ConvexHull
FilledArea
PixelList
ConvexImage
FilledImage
Solidity
Eccentricity
Image
表1 属性字符串列表----
度量图像区域的属性或功能
'Area'
图像各个区域中像素总个数
'BoundingBox' 包含相应区域的最小矩形
'Centroid' 每个区域的质心(重心)
'MajorAxisLength' 与区域具有相同标准二阶中心矩的椭圆的长轴长度(像素意义下)
'MinorAxisLength' 与区域具有相同标准二阶中心矩的椭圆的短轴长度(像素意义下)
'Eccentricity' 与区域具有相同标准二阶中心矩的椭圆的离心率(可作为特征)
'Orientation' 与区域具有相同标准二阶中心矩的椭圆的长轴与x轴的交角(度)
'Image' 与某区域具有相同大小的逻辑矩阵
'FilledImage' 与某区域具有相同大小的填充逻辑矩阵
'FilledArea' 填充区域图像中的on像素个数
'ConvexHull' 包含某区域的最小凸多边形
'ConvexImage' 画出上述区域最小凸多边形
'ConvexArea' 填充区域凸多边形图像中的on像素个数
'EulerNumber' 几何拓扑中的一个拓扑不变量——欧拉数
'Extrema' 八方向区域极值点
'EquivDiameter' 与区域具有相同面积的圆的直径
'Solidity' 同时在区域和其最小凸多边形中的像素比例
'Extent' 同时在区域和其最小边界矩形中的像素比例
'PixelIdxList' 存储区域像素的索引下标
'PixelList' 存储上述索引对应的像素坐标
OpenCV:二值图像连通区域分析与标记算法实现
OpenCV_连通区域分析(Connected Component Analysis-Labeling
matlab图像处理特殊命令
5.bwarea
功能:
计算二进制图像对象的面积.
语法:
total = bwarea(BW)
举例
BW = imread('circles.tif');
imshow(BW);
附录 MATLAB图像处理命令 321
bwarea(BW)
ans =
15799
相关命令:
bweuler, bwperim
6.bweuler.功能:计算二进制图像的欧拉数.语法:eul = bweuler(BW,n)举例BW = imread('circles.tif');imshow(BW);bweuler(BW)ans =-2相关命令:bwmorph, bwperim
7.bwfill功能:填充二进制图像的背景色.语法:BW2 = bwfill(BW1,c,r,n)BW2 = bwfill(BW1,n)[BW2,idx] = bwfill(...)BW2 = bwfill(x,y,BW1,xi,yi,n)[x,y,BW2,idx,xi,yi] = bwfill(...)BW2 = bwfill(BW1,'holes',n)[BW2,idx] = bwfill(BW1,'holes',n)举例MATLAB高级应用——图形及影像处理 322BW1 =[1 0 0 0 0 0 0 01 1 1 1 1 0 0 01 0 0 0 1 0 1 01 0 0 0 1 1 1 01 1 1 1 0 1 1 11 0 0 1 1 0 1 01 0 0 0 1 0 1 01 0 0 0 1 1 1 0]BW2 = bwfill(BW1,3,3,8)BW2 =1 0 0 0 0 0 0 01 1 1 1 1 0 0 01 1 1 1 1 0 1 01 1 1 1 1 1 1 01 1 1 1 0 1 1 11 0 0 1 1 0 1 01 0 0 0 1 0 1 01 0 0 0 1 1 1 0I = imread('blood1.tif');BW3 = ~im2bw(I);BW4 = bwfill(BW3,'holes');imshow(BW3)figure, imshow(BW4)相关命令:
bwselect, roifill
8.bwlabel功能:标注二进制图像中已连接的部分.语法:附录 MATLAB图像处理命令 323L = bwlabel(BW,n)[L,num] = bwlabel(BW,n)举例BW = [1 1 1 0 0 0 0 01 1 1 0 1 1 0 01 1 1 0 1 1 0 01 1 1 0 0 0 1 01 1 1 0 0 0 1 01 1 1 0 0 0 1 01 1 1 0 0 1 1 01 1 1 0 0 0 0 0]L = bwlabel(BW,4)L =1 1 1 0 0 0 0 01 1 1 0 2 2 0 01 1 1 0 2 2 0 01 1 1 0 0 0 3 01 1 1 0 0 0 3 01 1 1 0 0 0 3 01 1 1 0 0 3 3 01 1 1 0 0 0 0 0[r,c] = find(L==2);rc = [r c]rc =2 53 52 63 6相关命令:bweuler, bwselect
9.bwmorph功能:提取二进制图像的轮廓.语法:BW2 = bwmorph(BW1,operation)BW2 = bwmorph(BW1,operation,n)举例BW1 = imread('circles.tif');MATLAB高级应用——图形及影像处理 324imshow(BW1);BW2 = bwmorph(BW1,'remove');BW3 = bwmorph(BW1,'skel',Inf);imshow(BW2)figure, imshow(BW3)相关命令:bweuler, bwperim, dilate, erode
10.bwperim功能:计算二进制图像中对象的周长.语法:BW2 = bwperim(BW1,n)举例BW1 = imread('circbw.tif');BW2 = bwperim(BW1,8);imshow(BW1)figure, imshow(BW2)附录 MATLAB图像处理命令 325相关命令:bwarea, bweuler, bwfill
11.bwselect
功能:
在二进制图像中选择对象.
语法:
BW2 = bwselect(BW1,c,r,n)
BW2 = bwselect(BW1,n)
[BW2,idx] = bwselect(...)
举例
BW1 = imread('text.tif');
c = [16 90 144];
r = [85 197 247];
BW2 = bwselect(BW1,c,r,4);
imshow(BW1)
figure, imshow(BW2)
相关命令:
bwfill, bwlabel, impixel, roipoly, roifill