I trying to extract roads from Sentinel-2 images using the python api from google earth engine. I am following an article that calculates a road index and then uses a bottom-hat morphological filter to accentuate the roads before classification.
Since GEE does not have the bottom-hat filter, I tried to implement it but I am not sure it is working correctly, speacilly because the output image I am getting doesn't seem to have any changes, even with a different values in the variable radius.
Considering that Bottom-hat filtering is the equivalent of subtracting the input image from the result of performing a morphological closing operation on the input image, and the closing operation in gee is done using the focalMax()
, this is the code I have done:
def bottom_hat_morph_filter(image,radius):
kernel = ee.Kernel.circle(radius) #pixels
closing = image.focalMax(kernel=kernel,iterations=1)
bottom_hat = closing.subtract(image)
return bottom_hat
Am I missing something?