我使用CC = bwconncomp(BW)标记了图像。现在我必须删除面积较小的标签。我使用下面的代码来查找区域。
[B,L] = bwboundaries(Bw,'noholes');
stats = regionprops(L,'Area','perimeter');
area = [stats.Area];
但现在如何删除面积较小的标签???
答案 0 :(得分:1)
易。使用bwareaopen
。这将获取二进制图像以及您要强制执行的最小区域。输出是相同的图像,但所有区域都低于最小区域。
因此,假设thresh
是您要为图像中的对象保留的最小区域,请执行以下操作:
%// Remove those labels that are below an area of thresh
out = bwareaopen(L ~= 0, thresh);
%// Make a copy of the original label matrix and
%// only copy the labels that appeared in the above result over
Lfinal = zeros(size(L));
Lfinal(out) = L(out);
Lfinal
包含删除较小区域的最终标签矩阵。在您的情况下,您可能希望从具有最大区域的对象中消除那些小于特定量的对象...所以可能执行以下操作:
thresh = round(0.1*max(area));
这会看一下标签矩阵中最大的区域,占10%。面积低于此最大面积10%的任何对象都将从标签矩阵中删除。