My Question is related to OpenCV / Matplotlib only. However, to understand the problem bear with me for a few lines of ML / Computer vision side of stuff :
I am working on a Image segmentation problem on floor plan dataset. I would be using Fully Convolutional Networks (FCN) for the same.
Now, FCNs require for an image, a corresponding segmented image. For example :

The image on the left is actual image, while image on the right is the proper "ANNOTATION" of the image. Essentially, every object (class) is completely filled with its own colour - car, road, buildings, etc.
Now, in my case, I'm working with floor plan data. An example floorplan image looks like this :

The relevant entities in such images are walls, doors, etc.
Problem I have gotten data annotated for a HUGE bunch of such images, however it is not annotated in the above form. Walls are annotated as simple lines --- which means they're 1px thick only and do not actually fill the area/thickness of the walls in actual image. See the following example :

See the 2 lines representing walls on top left in above image. While wall is thick, what I have as annotated data is just those pink 1px thick lines.
However, what I would require is actually filled region of walls completely. For example :

What I want to do now is, programmatically, convert these lines to filled regions, i.e., based on having data about lines for every wall, I wish to create a filled version of walls inside which these lines reside.
So, essentially the question is this : If I have a thin line inside a rectangular region, can I somehow get the whole rectangular region that it is representing? If I can I could fill it with its colour and I can annotate the way it's needed.
Some assumptions we can make : - Lines will always be representing the walls inside which they are - Walls would usually be thicker lines only having some dark colour compared to rest of the image
It would be very difficult and expensive to get data annotated again, hence I'm asking this in case this could be programmatically achieved.
I have very thin knowledge of opencv and matplotlib and hence this could be a newbie question. It might be a very very simple thing to do. In such a case, please let me know the algorithm, or function I need to read up on.
Thanks.
Editing my answer to cover @Prune condition. I would probably try some logic such as:
Let me know if the 4th condition is not met. In this case, for horizontal lines, for example, we would need to iterate up/down along the horizontal line, looking for the smaller distance between the dark pixels, and then get this y-coordinates to help draw the rectangle.
Normally, you could use a simple "fill" algorithm for this, as suggest in Mariana's answer. However, you need to extend only so far as the given line -- you cannot continue down the west wall of that office area. I'm assuming that each end result will be a rectangle aligned to the drawing axes.
Instead, you need a "wave-front" fill: extend the entire line north and south (the line dimension that is more than a single pixel) so far as all of the adjacent pixels are gray. Then do the same with the east-west direction. You could perform the extension by replicating the line to the adjacent pixel row/column.
I don't know of a package that will support this directly, but most will do a vectorized copy-paste or equivalent change.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With