Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Extract landscape lines from image

My usecase is I would like to extract certain contours/edges from a landscape image. The purpose is to simply store the contours' x,y vertices. Please see here for the original image, the desired result and the results I am getting. https://imgur.com/a/ZFQYLOv

I know of a couple of ways to extract edges but all of them also identify unwanted edges aswell. What is the best way to achieve my objective? My ideas are below although they are not achieving my objective. BTW I am using OpenCV.

  • Use canny, sobel or any edge detection method and allow detection of unwanted edges. Dilate the image to join edges. Run cv::findContours() then find the longest contours. Presumably the longest contours are my desired contours.
  • Remove 'weak' edges by blurring the original image with a big kernel. Then run Sobel, cv::findContours() on the gradient magnitude. The problem is this assumes my landscape lines/depth lines are always strong which is not always the case.
  • Is there a filter I can run on my Gradient Magnitude image that preserves strong gradient magnitude and removes weak gradients?