8

I am a guy from a completely different discipline who need some Image Processing techniques to achieve this goal in a project. I need to derive the edges from an indoor floor plan, as shown below

enter image description here

I have tried this particular Python edge detect snippet:

from PIL import Image, ImageFilter

image = Image.open('L12-ST.jpg')
image = image.filter(ImageFilter.FIND_EDGES)
image.save('new_name.png') 

However, it is returning too much more details than I need. It basically detects all the edges including the room walls. Actaully, what I need are just the corridor walls. So I expect something like this

enter image description here

How may I do this? I am using Python, but any generic or general pointers or even some keywords are very much appreciated.

  • can you post any other example? from what i can see, the corrider seems to be the largest area and is longest. that two condition alone uniquely identify it from any other room. you can use connected component analysis to extract it – Zaw Lin Oct 23 '13 at 15:20

3 Answers3

8

here's an example. you will need to have opencv package to run it.

there's a break there because the image has artifacts. if you use a higher quality image, it's probably going to be better. if you cant have a higher quality image, may be morphological operations can be used to connect the small gaps and remove quarter circle protrusions.

enter image description here

import cv2
import numpy as np

img = cv2.imread('c:/data/floor.jpg')
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
gray=255-gray

contours,hierarchy = cv2.findContours(gray,cv2.RETR_LIST ,cv2.CHAIN_APPROX_NONE )

for cnt in contours:
    area = cv2.contourArea(cnt)
    if area>9000 and area<40000:
        cv2.drawContours(img,[cnt],0,(255,0,0),2)

cv2.imshow('img',img)
cv2.waitKey()

edit

did some preprocessing to fix the break

import cv2
import numpy as np

img = cv2.imread('c:/data/floor.jpg')

img=cv2.resize(img,(1700,700))
gray=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
gray=255-gray
gray=cv2.threshold(gray,4,255,cv2.THRESH_BINARY)[1]
gray=cv2.blur(gray,(15,1))
contours,hierarchy = cv2.findContours(gray,cv2.RETR_LIST ,cv2.CHAIN_APPROX_NONE )

for cnt in contours:
    area = cv2.contourArea(cnt)
    if area>150000 and area<500000:
        cv2.drawContours(img,[cnt],0,(255,0,0),2)

cv2.imshow('img',img)
cv2.waitKey()

enter image description here

Zaw Lin
  • 5,629
  • 1
  • 23
  • 41
  • +1 and Thanks! The result looks rather promising for this particular one. Would you mind explaining the rationale a bit? I am not sure whether it is universally applicable for all the floor plans. –  Oct 24 '13 at 02:20
  • the idea is to retain only large and long connected areas which appears to describe hallway in this plan(actually i think most hallways fit this). color is inverted so that border will be detected. the processing one is probably not very universal, it blurs only horizontally which has the effect of closing the gaps in the rooms. in this case without it , room 17 becomes part of the contour. if your hallway is vertical, then you may need to do the same operation vertically like `gray=cv2.blur(gray,(1,13))`. the threshold is necessary because there are artifacts which confuse the cc finding algo – Zaw Lin Oct 24 '13 at 06:56
  • also the longness condition is never used because it was not necesary. you can do it by something like `if width/height <0.3 or width/height>4` to retain only elongated contours. – Zaw Lin Oct 24 '13 at 06:56
0

I guess you need some pre-processing before using the edge detector since no particular difference is seen between the room walls and the corridor. One idea is to choose different colors in the cad file and then help your detector to distinguish what you're looking for. Second one is to restrict your processing region in advance. Otherwise, I don't thing there is a straight forward technique you could apply and extract the corridor. Hope it helped.

Eb Abadi
  • 585
  • 5
  • 17
0

I agree with what @Eb Abadi has said about changing the color of your CAD model (if possible). Otherwise, use some masks (exactly the same size as the rooms) to essentially blur out all the edge details of the rooms and you will be left with only the halls and the outer walls.

scap3y
  • 1,188
  • 10
  • 27
  • Newbie to image processing. Mind explaining a bit on CAD model? Why would you suggest so? –  Oct 23 '13 at 13:02