Tablet edge detection - image processing?

I am a guy from a completely different discipline who needs some image processing techniques to achieve this goal in a project. I need to get the edges out of the floor plan, as shown below.

enter image description here

I tried this specific Python detection fragment:

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

However, it returns too many details than I need. It basically discovers all the edges, including the walls of the room. Actaully, I only need the walls of the corridor. So I expect something like this

enter image description here

How can i do this? I use Python, but any generic or generic pointers or even some keywords are really appreciated.

+6
source share
3 answers

here is an example. you will need the opencv package to run it.

there is a gap because the image has artifacts. if you use a higher quality image, it will probably be better. if you cannot have a higher quality image, there may be morphological operations that can be used to join small gaps and remove the protrusions of the quarter circle.

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 gap

 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

+7
source

I think you need pre-processing before using the edge detector, since there is not much difference between the walls of the room and the corridor. One idea is to select different colors in the cad file and then help your detector distinguish what you are looking for. Secondly, it is necessary to limit the processing area in advance. Otherwise, I do not know if there is a direct technique that you could apply and extract the corridor. Hope this helps.

0
source

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

0
source

Source: https://habr.com/ru/post/956523/


All Articles