我想填补建筑区域以获得整个建筑物的外部边界,而不是填满边界的整个区域。 输入图片Input http://porterdrivecampus.stanford.edu/sites/default/files/shared/images/som/plans/3172_floorplan_1st.gif
I = imread( 'http://porterdrivecampus.stanford.edu/sites/default/files/shared/images/som/plans/3172_floorplan_1st.gif'); BVO = bwarea(imfill(I, '孔')); TotPix = numel(I);
if BVO>(TotPix*0.95)
BW = imfill(I1,[1 1],8); %filling inner hole
B=imclearborder(BW);
nI1=imfill(B,'holes');
else
nI1=imfill(nI101,'holes');
end
figure;
imshow(nI1);
答案 0 :(得分:0)
尝试一下
clc,clear
[I,map] = imread('1kuuZ.gif');
I1 = ind2rgb(I,map); % convert indixed image to rgb
I2 = im2bw(I1,graythresh(I1)+0.3); % binarize
% figure, imshow(I2), title('binarized image');
[L,n] = bwlabel(I2);
% figure, imshow(L,rand(n,3)), title('labeled image');
prop = regionprops(L,'Area'); % find area of each label
area = cat(1,prop.Area);
[~,ix] = max(area); % find biggest area
I3 = ~(L==ix); % extract biggest area
% figure, imshow(I3), title('biggest area image');
I4 = bwareaopen(I3,500); % clear area (remove small regions)
% figure, imshow(I4), title('biggest area (cleared) image');
[L,n] = bwlabel(I4);
prop = regionprops(L,'Area'); % find background
area = cat(1,prop.Area);
I5 = L==ix; % extract biggest area (floor)
% figure, imshow(I5), title('floor area image');
I6 = edge(I5);
% figure, imshow(I5), title('floor area final image');
% comparing of original and final images
I7 = imdilate(I6,ones(5));
I8 = I2 & ~I7;
Ic = cat(3,I7*0,I8,I7);
figure, imshow(Ic), title('comparison image');
过程