《数字图像处理(面向新工科的电工电子信息基础课程系列教材)》例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')

禹晶、肖创柏、廖庆敏《数字图像处理(面向新工科的电工电子信息基础课程系列教材)》
禹晶、肖创柏、廖庆敏《数字图像处理》资源二维码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值