《数字图像处理(面向新工科的电工电子信息基础课程系列教材)》例8-10
连通分量分析
面积开运算保留前三个大目标。
numPixels =
11
3575
1
3
3
10
6
79
99
name = 'pedestrian';
suffix = '.bmp';
BW = imread(['images/', name, suffix]);
%% Find the number of connected components in the image.
CC = bwconncomp(BW);
%% Create a label matrix using labelmatrix.
L = labelmatrix(CC);
cmap = colormap(jet(CC.NumObjects));
RGB = label2rgb(L, cmap, 'k', 'Shuffle');
subplot(221), imshow(BW), title('Binary Image')
subplot(222), imshow(RGB), title('Label Matrix')
%%
S = regionprops(CC, 'Area');
numPixels = vertcat(S.Area)
%%
subplot(223), bar(numPixels)
xlabel('Index')
ylabel('Number of pixels')
%%
thres = 30;
openedBW = bwareaopen(BW,thres);
% for i = 1: CC.NumObjects
% numPixels = sum(BW(CC.PixelIdxList{i}));
% if numPixels < thres
% BW(CC.PixelIdxList{i}) = 0;
% end
% end
subplot(224), imshow(openedBW), title('Area Opening')
禹晶、肖创柏、廖庆敏《数字图像处理(面向新工科的电工电子信息基础课程系列教材)》
禹晶、肖创柏、廖庆敏《数字图像处理》资源二维码
原文地址:https://blog.csdn.net/u013600306/article/details/142640178
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!