Identify hillside regionos on a map view
Old school CV techniques remain effective to find regions of interest.
Hillside regions on a map are those marked in shades with dense contour lines passing through. Identifying those hillsides regions in a mask while filtering out other distracting elements can be useful for location based applicaitons. The following code snippet demonstrates the combination of blurring and OTSU thresholding of a map view suffices to find the hillsides given a map view.
from matplotlib import pyplot as plt
import numpy as np
import cv2 as cv
import base64
img = cv.imread('/content/drive/MyDrive/Colab Notebooks/assets/contour.png', cv.IMREAD_GRAYSCALE)
ksz = 21
blurGau = cv.GaussianBlur(img, (ksz, ksz), 0)
blurMedian = cv.medianBlur(img, ksz)
fig, axs = plt.subplots(2, 3, figsize=(15, 8))
for row, (blur, blurred) in enumerate([('GaussianBlur', blurGau),
('MedianBlur', blurMedian)]):
(T, threshOtsu) = cv.threshold(blurred, 200, 255, cv.THRESH_BINARY+cv.THRESH_OTSU)
images = [img, blurred, threshOtsu]
titles = ["Orginal", blur, f"{blur} THRESH_OTSU"]
for col, (image, title) in enumerate(zip(images, titles)):
ax = axs[row, col]
ax.imshow(image, 'gray')
ax.set_title(title)
ax.set_xticks([])
ax.set_yticks([])
plt.tight_layout()
plt.show()