%检测地板
clear all;
close all;
clc;
f=imread('F:\图像处理\练习-分割地板\12.jpg');
g=rgb2gray(f);
g1=imadjust(g,[0 1],[0 1]);
t=graythresh(g1);
g2=edge(g1,'canny',t);
se=strel('disk',3);
bw1=imdilate(g2,se);
bw2=imdilate(bw1,se);
bw2=imcomplement(bw2);
figure,imshow(bw2);
[B,L,NR,A]=bwboundaries(bw2);
[L,num]=bwlabel(bw2,8);
stats=regionprops(L,'Area');
[M,N]=size(bw2);
image=false(M,N);
max=1;
for i=2:num
if( stats(max).Area<stats(i).Area)
max=i;
end
end
bR=cat(1,B{max});
linearindex=sub2ind([M,N],bR(:,1),bR(:,2));
linearindex1=imdilate(linearindex,se);
image(linearindex1)=1;
fR=f(:,:,1);
fG=f(:,:,2);
fB=f(:,:,3);
fR(linearindex)=255;
fG(linearindex)=0;
fB(linearindex)=0;
rgb_image=cat(3,fR,fG,fB);