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}]


enter image description here

  • 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$ Feb 2, 2017 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$ Mar 15, 2017 at 18:14
  • $\begingroup$ play w/ Binarize too: ImageLines[EdgeDetect[Binarize[img, .2], 20], MaxFeatures -> 5] $\endgroup$
    – george2079
    Mar 15, 2017 at 20:58

1 Answer 1


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.



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.)


Finally, run ImageLines and composite the image.



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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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