我正在使用bwconncomp处理代码来检测图像中的blob。该代码现在绘制白色的最大斑点(下面的部分);你如何建议修改它以便绘制超过100像素的blob?感谢。
这里是处理blob检测和绘图的代码部分:
CC = bwconncomp(Iobr);
numPixels = cellfun(@numel,CC.PixelIdxList)
[biggest,idx] = max(numPixels);
Iobr(CC.PixelIdxList{idx}) = 255;
figure, imshow(Iobr);
答案 0 :(得分:1)
方法#1 基于无循环bwlabel
-
threshold = 100;
[L,num] = bwlabel( Iobr );
counts = sum(bsxfun(@eq,L(:),1:num));
B1 = bsxfun(@eq,L,permute(find(counts>threshold),[1 3 2]));
Iobr = sum(B1,3)>0;
figure, imshow(Iobr);
方法#2 bwconncomp
基于
threshold = 100;
CC = bwconncomp(Iobr);
count_pixels = cellfun(@numel,CC.PixelIdxList);
for k = 1:numel(count_pixels)
if count_pixels(k)<=threshold
Iobr(CC.PixelIdxList{k}) = 0;
end
end
答案 1 :(得分:0)
可悲的是,你没有一个有效的例子,但是既然你正在处理BW图像,那么regionprops应该可以工作:
BW = imread('coins.png');
% convert to BW
BW2 = BW > 80;
figure
imshow(BW2)
% properties
thresh = 2500; % Threshold of 2500 px
[B,L] = bwboundaries(BW2);
props = regionprops(L, 'Area');
sel_idx = find([props.Area] > thresh);
hold all
for n = 1:length(sel_idx)
plot(B{sel_idx(n)}(:,2), B{sel_idx(n)}(:,1), 'r')
end