用matlab求连通域高度并操作

来源:百度知道 编辑:UC知道 时间:2024/07/08 23:58:57
如题
我要对一个二值图像的各个连通域求高度,并根据高度,删去一些高度过大和过小的连通域。
请给出matlab源代码
补充完整答案:
% bw 是二值图像
[L,nm] = bwlabel(bw,8);
for i = 1:nm
[r,c] = find(L == i);
left = min(c);
right = max(c);
top = min(r);
buttom = max(r);
width(i) = left - right + 1;
height(i) = buttom - top + 1;
end
% width 和 height 分别存各联通阈的宽度和高度

% bw 是二值图像
[L,nm] = bwlabel(bw,8);
for i = 1:nm
[r,c] = find(L == i);
left = min(c);
right = max(c);
top = min(r);
buttom = max(r);
width(i) = right - left;
height(i) = top - buttom;
end
% width 和 height 分别存各联通阈的宽度和高度