# Identification of rooms in a floorplan

9 views (last 30 days)
CHINTALA NIRMAL SRINIVAS on 17 May 2020
Commented: darova on 21 May 2020
I have a floorplan image with only walls. I want to identify the room coordinates of the floorplan.
This code actually closes the doors and identifies the rooms in the floorplan. This works well when shape of the rooms is rectangles. But It does not work well when the shape is either trapezium or L shape. Can somebody help me please?
Also it is not closing all the doors properly.
e=ones(1,105);
A=imclose(imclose(~Image,e),e.');
B=imfill(A,'holes')&~A;
imshow(B)  Show 1 older comment
CHINTALA NIRMAL SRINIVAS on 19 May 2020
L shape in the sense the shape of the room.In the example floorplan is L shaped but the rooms are rectangles. In the case where the rooms are either trapezium shaped or L shaped, the above code is not working properly
Matt J on 19 May 2020
CHINTALA NIRMAL SRINIVAS on 20 May 2020
Not all the doors are closed but if I increase the number in ones() then they are being closed

darova on 19 May 2020
I skeletonized the image and found endpoints with bwmorph. Found shortest distances and connected points
I1 = im2bw(I0); % binarize image
I2 = bwmorph(~I1,'skel',inf); % make thin lines
I3 = bwmorph(I2,'spur',10); % remove spurs
B = bwmorph(I3,'endpoints'); % find free ends (endpoints)
[ii,jj] = find(B); % find rows and columns of endpoints
D = pdist2([ii(:) jj(:)],[ii(:) jj(:)]); % find distances
D(D<1e-3) = nan; % remove zeros
[~,ix] = min(D); % find shortest distances
for i = 1:length(ix)
i1 = ii(i):ii(ix(i));
j1 = jj(i):jj(ix(i));
I3(i1,j1) = 1; % connect door ends
end
I4 = imdilate(I3,ones(15)); % make lines thicker
imshowpair(I0,I4) % display original and modificated images
Result darova on 21 May 2020
• does the regionprops() gives only rectangular bounding boxes?
rectangular box can be only rectangular
• Also it is not giving correct answer for other images.
It's because there is no space between walls and margins  [m,n,~] = size(I0);
I1 = ones(m+2,n+2);
I1(2:end-1,2:end-1) = im2bw(I0); % binarize image
Are your images always have white background?
CHINTALA NIRMAL SRINIVAS on 21 May 2020
Yes they always have white backgrounds. How can I get the coordinates of each room if the bounding box is only rectangular in shape. I mean how can I get the coordinates of those rooms which are not in rectangular shape
darova on 21 May 2020
You can label image with bwlabel and select each region separately
[L,n] = bwlabel(I);
for i = 1:n
I = L == i;
imshow(I)
pause(0.5)
end

R2020a

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!