This project shows a possible way of finding contour lines on maps. These properties of the contour lines are considered here:
- contour lines are closed or they end at the edges of the map,
- in some sections more neighbor contour lines are nearly parallel,
- they are mainly slightly curved only (the lines do not have large angles like roads or buildings).
The algorithm uses the OpenCV library.
Functions used: cv::medianBlur, cv::Sobel, cv::magnitude
- Image preprocessing – using median blur
cv::Mat bl; cv::medianBlur(input, bl, params_.medianBlurKSize);
- Detecting lines and their directions – using Sobel filter (magnitudes are obtained using the magnitude function and directions are computed using atan2 from horizontal and vertical gradients)
cv::Mat_<double> grad_x; cv::Sobel(beforeSobel, grad_x, CV_64F, 1, 0, params_.sobelKSize); cv::Sobel(beforeSobel, grad_y, CV_64F, 0, 1, params_.sobelKSize);
- Finding some contour line seeds – points at lines with approximately equal directions.
cv::Mat_<double> magnitude; cv::magnitude(grad_x, grad_y, magnitude);
- Tracing lines beginning at the seeds – we are going from each seed to both directions to find the line while checking if the curves do not exceed a threshold (the more curved lines are probably not the contour lines).
- Filtering of the traced lines – only the lines having both ends at the image boundaries or the closed lines are considered as the map contour lines.
The result image shows a map with some contour lines detected. The seeds and line points are marked as follows:
- yellow – seed points
- red – closed line points
- green – points of the first part of a line ending at the image edge
- blue – points of the second part of a line ending at the image edge
Problems and possible improvements
These algorithm properties cause problems and need to be considered in the algorithm improvements:
- line intersections are not being detected – one line from each pair of the intersecting lines should always be removed,
- the algorithm uses a global magnitude threshold (the threshold determines if a point belongs to a line), but the line intensities change in most images,
- the algorithm has too many parameters which were not generalized to match more possible images,
- some contour lines are not continuous (they are splitted by labels) and thus not being detected by the algorithm.