Search code examples
opencvjavacv

Narrowing corridors and paths using opencv


I have images that are best described as mazes. The important feature is that they have what I would call corridors or paths.

I'm trying to narrow these corridors/paths without completely closing any of them off. I don't have any strict requirement for how narrow the processed corridors must be, I just need to narrow them up a good bit. However, I can never completely close one off.

Here's an unprocessed image

unprocessed image

Here's an image after applying a gaussian blur via cvSmooth(img, img, CV_GAUSSIAN, 9);

with guassian blur

The results are excellent, but I don't know how wide my corridors will be in incoming images, and they will not necessarily have such straight regular angled walls, nor have consistent corridor widths, and so such a naive solution will surely completely block some of the corridors.

I've thought about blurring a little bit at a time, running a pathfinding algo on the image to make sure I haven't closed off a corridor, but I think this will be too slow.

So, I'm looking for a fast way to narrow the corridors without risk of completely closing any off.


Solution

  • you can try these two...

    1. Use dilation with a mask of 3 X 3 Mat::ones(3,3,CV_8UC1) over the image...dilation mitght work faster than Gaussian blurring...with dilation you know that you have broadened the image by one pixel level...
    2. To check for connectivity of white path areas you can use connected component labelling...use a one scan connected component for a faster labeling...
    3. You can also play with contours of the white path as a check for connectivity... Thats all I can think about right now..!!