Can someone guide me for applying thresholding technique to input raster image using Python.
I intend to extract impervious surfaces from a high resolution raster such as roads, sideways and rooftops etc.
Can someone guide me for applying thresholding technique to input raster image using Python.
I intend to extract impervious surfaces from a high resolution raster such as roads, sideways and rooftops etc.
You can use the OpenCV package in Python for image thresholding. This example shows not only how to perform the binary image thresholding, but also the limitations of this method. Here, I use a 1m spatial resolution NAIP image that shows a dirt road surrounded by arid vegetation. You can see that the road is extracted but there is also a significant amount of exposed soil and other background noise that is also extracted. There are a variety of other thresholding methods available in OpenCV that you may want to investigate.
import cv2
import numpy as np
from matplotlib import pyplot as plt
# Read the geotiff as greyscale image
img = cv2.imread(r'C:\your\path\roads_naip.tif',0)
# Apply the binary threshold. The second parameter "150" can be adjusted here.
ret,thresh1 = cv2.threshold(img,150,255,cv2.THRESH_BINARY)
titles = ['Original Image','Binary']
images = [img, thresh1]
for i in xrange(2):
plt.subplot(1,2,i+1),plt.imshow(images[i],'gray')
plt.title(titles[i])
plt.xticks([]),plt.yticks([])
plt.show()
Well, thank you so much @Aaron. The problem has solved. I have realized that the above code needs to be slightly modified for the case of Google Earth imagery regarding its conversion to grey-scale intensity image. Following is the output of my modified code. Impervious surfaces of building rooftops have been extracted. Nevertheless, the results can be much improved through the combination of different thresholding techniques of OpenCV package.