def set_rocks_in_grad(self, elevation, landcover):
""" Modify the land cover to create rocks in the large gradient pixels
(large steepness)
Position arguments:
elevation -- Elevation image
landcover -- Landcover to become edited
Returned value:
Edited landcover
"""
# Compute the steepness of each pixel
grad = gaussian_gradient_magnitude(elevation, 1.0)
grad /= self.mercator.Resolution(self.__zoom)
# Get the mask of rock (with a smooth transition)
mask = (grad >= ROCK_STEEPNESS).astype(np.float)
mask = gaussian_filter(mask, 3.0)
# Blend the images
dtype = landcover.dtype
rock_image = np.zeros(landcover.shape, dtype=dtype)
rock_image[:,:] = ROCK_COLOR
for i in range(3):
rock_image[:,:,i] = (mask * rock_image[:,:,i]).astype(dtype)
landcover[:,:,i] = ((1.0 - mask) * landcover[:,:,i]).astype(dtype)
landcover += rock_image
return landcover
评论列表
文章目录