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:

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.
source share