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

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_initial=imread("C:\\Users\\User\\Desktop\\tkinter_codes\\floorplans\\ROBIN\\Dataset_3roomsmall\\Cat1_1.jpg");
%I_initial = imread('room_4.png');
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 = imread('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);
image = imread('blb_0_1.jpg');
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');
signature=load('signature.mat');
sign_objects=load('sign_object2');
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.

 Akzeptierte Antwort

Matt J
Matt J am 10 Mai 2020
Bearbeitet: Matt J am 10 Mai 2020
One approach is to close all of the doors morphologically:
load('Walls')
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

7 Kommentare

Could you please tell me how can I get the bounding boxes around the rooms? I am unable to get.
regionprops will give those as well.
No I mean when I try to get bounding boxes it is giving error like unrecognised variable 'rectangle' (that function which I use for getting bounding boxes).Could you please tell me what should I write?
I don't know what you mean by "that function". Why not simply do,
regionprops(B,'BoundingBox')
When I tried to draw rectangles around it, it gave the error. I used regionprops to get the bounding boxes
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?
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

7 Kommentare

Could you please tell me how can I extract the corner points to a file?
But, just scanning your code, it looks like you get the bounding boxes, so that gives you the coordinates of each room, right?
Also since the size of the wall line is large, there are two corner points at one corner. I want to have one point at one corner. I tried to skeleton the image but the skeletonization was not done properly. Could you please tell me a solution?
I am getting the bounding boxes of the objects in the floorplan. But How can I get the coordintes of room?
I am unable to bound the rooms with bounding boxes.
Call bwskel() to get the skeleton of the walls
skelImage = bwskel(~mask);
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.
when I use bwskel some part of the wall is missing. What should I do?
Could you please tell me what should I do to get the bounding boxes around the rooms?

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by