# How to get the coordinates of each room in a floor plan image through object identification method?

17 views (last 30 days)
CHINTALA NIRMAL SRINIVAS on 9 May 2020
Commented: Matt J on 17 May 2020
I have a floor plan image which contains objects and walls. I removed all the objects in it so it now contains only walls. Now I want to get the coordinates of each room.
I am new to this platform. Can somebody please help me how to get the coordinates of each room? Or Can I get the end points of each line segment?
This is the code.
function [bbox_loc,sign_objects,index1,st,furniture]=classify_objects_test1(I1)
% clear all;
% clc;
% close all;
I=I_initial;
imshow(I);
SE = strel('square',10);
I = imdilate(I,SE);
SE = strel('square',10);
I = imerode(I,SE);
wall_image=I;
wall = I;
I=I_initial;
wall=im2bw(wall);
imshow(wall);
I=im2bw(I);
I=imcomplement(I);
wall = imcomplement(wall);
I=I-wall;
% imshow(I);
I=imcomplement(I);
SE = strel('square',1);
IM2 = imdilate(I,SE);
IM2 = I;
IM2 = imerode(IM2,SE);
imwrite(IM2,'fl_0sym.tif');
se1=strel('square',8);
intm1=imerode(IM2,se1);
se2=strel('square',4);
intm2=imdilate(intm1,se2);
intm3=imdilate(intm2,se2);
imwrite(intm3,'fl_0sym1.tif');
I = imcomplement(I);
J = imfill(I);
J = ~J;
imwrite(J,'blb_0_1.jpg');
figure=I_initial;
[m,n] = size(figure);
figure1 = figure(:,:,[1 1 1]);
figure = im2bw(figure);
[m,n] = size(figure);
BW = im2bw(image);
BW = imresize(BW,[m,n]);
BW = ~BW;
%for 4,1,9,8
SE = strel('square',10);
BW = imdilate(BW,SE);
%% figure;imshow(BW);
st = regionprops(BW,'BoundingBox');
shape.Inserter = vision.ShapeInserter('LineWidth',4,'BorderColor','Custom','CustomBorderColor',uint8([255 0 0]));
str_ele=strel('disk',1,0);
for k = 1:length(st)
% k=1;
% for k = 1:1
thisBB = st(k).BoundingBox;
%figure1 = step(shape.Inserter,figure1,bbox_loc{k});
thisBBarea=thisBB(3)*thisBB(4);
if thisBB(3)>20 && thisBB(4)>20
rectangle = int32([thisBB(1),thisBB(2),thisBB(3),thisBB(4)]);
end
if(thisBBarea >870)
bbox_loc{k}=rectangle;
crop_I_new=imcrop(figure1,rectangle);
crop_I_new_gray=rgb2gray(crop_I_new);
crop_I=im2bw(crop_I_new_gray,0.7);
% figure;imshow(crop_I);
signature{k}=signature_find(crop_I);
if isempty(signature{k})
signature{k}=[99999,99999,99999];
end
figure1 = step(shape.Inserter,figure1,bbox_loc{k});
end
end
signature=signature(~cellfun('isempty',signature));
save('signature.mat','signature');
for i=1:length(signature.signature)
for j=1:length(sign_objects.sign_object2)
diff{i,j}=abs(signature.signature{1,i}-sign_objects.sign_object2{j,1}.count);
end
end
for(i=1:size(diff,1))
for(j=1:size(diff,2))
if(sign_objects.sign_object2{j,1}.count(3)>1000)
temp1(i,j)=diff{i,j}(1)+diff{i,j}(2);
else
temp1(i,j)=diff{i,j}(1)+diff{i,j}(2)+diff{i,j}(3);
end
end
end
for(i=1:size(temp1,1))
[temp1_min(i),index1(i)]=min(temp1(i,:));
disp(sign_objects.sign_object2{index1(i),2});
furniture{i,1}=sign_objects.sign_object2{index1(i),2}
figure;imshow(figure1);
bbox_loc=bbox_loc(~cellfun('isempty',bbox_loc));
end
for k = 1:length(bbox_loc)
H= text( double(bbox_loc{k}(1)),double(bbox_loc{k}(2)),sign_objects.sign_object2{index1(k),2});
set(gcf,'DefaultTextColor','blue')
end
% for i=1:size(diff,1)
% for j=1:size(diff,2)
%
% temp1(i,j)=(diff{i,j}(1));
% temp2(i,j)=(diff{i,j}(2));
% temp3(i,j)=(diff{i,j}(3));
%
%
% end
% [temp1_min(i),index1(i)]=min(temp1(i,:));
% disp(sign_objects.sign_object1{index1(i),2});
% furniture{i,1}=sign_objects.sign_object1{index1(i),2}
% end
I am attaching a zip file which contains files which will be used by this code while running.
This is the floorplan image with objects.
This is the image with only walls.

Matt J on 10 May 2020
Edited: Matt J on 10 May 2020
One approach is to close all of the doors morphologically:
e=ones(1,105);
A=imclose(imclose(~Image,e),e.');
B=imfill(A,'holes')&~A;
imshow(B)
Now, you can simply use regionprops to get all of the pixel coordinates in each room,
>> Rooms=regionprops(B,'PixelList')
Rooms =
3×1 struct array with fields:
PixelList

CHINTALA NIRMAL SRINIVAS on 11 May 2020
When I tried to draw rectangles around it, it gave the error. I used regionprops to get the bounding boxes
CHINTALA NIRMAL SRINIVAS on 17 May 2020
For floorplan where rooms are not in the form of rectangles,(they are of the form of trapezium) , closing all the doors is not done appropriately.
Could you please suggest me a solution to this problem?
Matt J on 17 May 2020
I think you should start a new question for this more complex case. It looks like it might require a very different line of solution.

Matt J on 9 May 2020

Image Analyst on 9 May 2020
Call bwskel() to get the skeleton of the walls
Then get the endpoints of that image with bwmorph. Call pdist2() to get all the distances between endpoints. If the endpoints are within a certain distance (whatever a door width is), AND either the rows are the same or the columns are the same (so we're only getting vertical or horizontal gaps), then draw a line connecting the room going across the doorway.
There are hundreds of algorithms for getting floor plans that have been published here:
Look them over and code up the most promising one.
CHINTALA NIRMAL SRINIVAS on 9 May 2020
when I use bwskel some part of the wall is missing. What should I do?
CHINTALA NIRMAL SRINIVAS on 9 May 2020
Could you please tell me what should I do to get the bounding boxes around the rooms?

R2019b

### Community Treasure Hunt

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

Start Hunting!

Translated by