Detecting spaces in a binary image using MATLAB

I have the following image:

image

Some lines have a space. How to determine the position of the gap in the image?


This is the result. Closing seems to create new pixels.

after closing and subtracting

+4
source share
1 answer

Can I assume that the ultimate goal is to close the gap? Than you can use morphological operations. To close the gap, you just need the so-called closing ". This is done by applying dilation " rather than " erosion ".

So, how do you find the position where the gap was closed? You can simply compare the image before and after and look at the changes.

EDIT: after your post, I decided to update the answer. So I tried some code in Matlab.

originalBW = imread('Je3ud.jpg'); imshow(originalBW); se = strel('line',8, 0); % a straight line of 8 pixels closeBW = imclose(originalBW,se_disk); figure, imshow(closeBW) subtractedBW = closeBW - originalBW; figure, imshow(subtractedBW) 

it creates the resulting image:

enter image description here

So, we found the right position, but unfortunately, we got a lot of false positives. I think you can get the desired result by considering each of them as a candidate match and getting rid of false positives. One important part of the false positives seems to be that if you check their vertical neighborhood (in the original image), you will find that there are white pixels because the white line there really wasn’t disabled (and therefore they cannot be the correct solution). Therefore, you can try to use this to drop false positives.

+6
source

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


All Articles