4
$\begingroup$

There is an image from wolfram documentation

enter image description here

I want to find and highlight lines on the following image

enter image description here

I tried:

img = Import["http://imgur.com/NbNwYWC.png"]

lines = ImageLines[EdgeDetect[img], MaxFeatures -> 5]

HighlightImage[img, {Red, Thick, Line /@ lines}]

but...

enter image description here

$\endgroup$
  • 3
    $\begingroup$ Increasing the size of the edge filter gives much better results, but I'm sure someone with more experience with image processing functions can come up with a more reliable way: ImageLines[EdgeDetect[img, 20], MaxFeatures -> 9] $\endgroup$ – Martin Ender Feb 2 '17 at 10:30
  • $\begingroup$ I can only suggest one segment which is positioned almost perfectly: HighlightImage[img, {White, Style[Line[{{361, 686}, {136, 39}}], Antialiasing -> False]}]. $\endgroup$ – Alexey Popkov Mar 15 '17 at 18:14
  • $\begingroup$ play w/ Binarize too: ImageLines[EdgeDetect[Binarize[img, .2], 20], MaxFeatures -> 5] $\endgroup$ – george2079 Mar 15 '17 at 20:58
5
$\begingroup$

First thing I did was to Binarize the image. I tried several different variations, but ChanVeseBinarize worked the best. I picked gray as my foreground color and black as the background. The streets are mostly in the shadows, and I used gray on a hunch. Later, I tried DominantColors on the image, and the 2nd and 3rd colors were two grays, so I think there is a good reason that gray works well.

img=Import["https://i.stack.imgur.com/BlNpX.png"]
img2=ChanVeseBinarize[img,{{Gray,Black}}]

Binarized

Then, run EdgeDetect on the Binarized image. Making the range too big or too small affected the line fitting and the angles of the final lines. (This image is omitted because I can only post 2 links.)

img3=EdgeDetect[img2,10]

Finally, run ImageLines and composite the image.

lines=ImageLines[img3,MaxFeatures->10];
img4=Show[img,Graphics[{Thick,White,Line/@lines}]]

Final

I tried several other preprocessing steps, but with my limited skills, the above worked the best. I would think there is some combination of manipulating color and contrast at first, then binarizing the image, and finally dilating/eroding the resulting black and white image in the right way to help accent the streets. However, I couldn't beat the above combination.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.