I have this image of London's road networks.
img = Image[
Import["https://maps.googleapis.com/maps/api/staticmap?center=+51.5+\
-0.116667&zoom=10&size=600x600&scale=2&style=feature:road.highway%\
7Ccolor:0x000000%7Cweight:1%7Cvisibility:on"], ImageSize -> Medium]
After Binarize[] and ColorNegate[]:
I want to take out:
a) The text, without disrupting the edge connectivity.
b) The rectangles, again, without breaking edges.
How can I do this?
After binarizing and negating the image, I tried using MorphologicalGraph
Image[MorphologicalGraph[blackLondon, EdgeStyle -> Black,
VertexStyle -> White]]
and got this unsatisfactory result:
I also tried binarizing from 0 (the roads that I care about are pure black) and got this:
binarizedLondon2= Binarize[img, 0]
At this image, I applied morphological closing with a DiskMatrix, and managed to identify the rectangular elements.
rectangularElementsMask3 =
ColorNegate[Closing[binarized2, DiskMatrix[3]]]
I clean it up with an Opening.
rectangularElementsMask4 =
Opening[rectangularElementsMask3, DiskMatrix[7]]
then Inpaint, on the binarized image
Inpaint[binarized2, rectangularElementsMask4]
and get this result, which is still disconnected.
ContourDetect[Threshold[img, .9]]
where img is your second attached image - gets mighty close to keeping roads cleanly connected. I'd venture with some masking for the rectangles, and then a filter run over the rectangle-removed version, with the rectangles again as masks, that looks for "dangling ends" and connects them with a line would be quite nice... $\endgroup$MorphologicalPerimeter[img, .9]
on same second image is also looking like a pretty good start. $\endgroup$