We can make our results even more visually appealing and informative if we can combine the colorized image with the shaded relief image. Again, since we are dealing with arrays, we may deduce that this kind of composition can be achieved by performing an arithmetic operation between the two arrays.
In image processing, this is called alpha blending. Basically, a transparency is applied to both of the images and then they are blended into a new one. In the next steps, we are going to create a function that performs this operation:
if __name__ == '__main__':
block of the raster_data.py
file:if __name__ == '__main__': raster_data = RasterData('output/dem.tif') raster_data.adjust_values().create_hillshade( 10, 60).write_image('output/shaded.png')
alpha_blend
method to the RasterData
class:#... def alpha_blend(self, raster_data, alpha=0.5): """Blend this raster data with another one. :param raster_data: RasterData instance. :param alpha: Amount of transparency to apply. """ shade = cv2.cvtColor(raster_data.data, cv2.COLOR_GRAY2BGR) result = (1-alpha) * self.data + alpha * shade self.data = result return self
if __name__ == '__main__':
block again to test the code:if __name__ == '__main__': shaded = RasterData('output/shaded.png') classified = RasterData('output/classified.png') classified.alpha_blend(shaded).write_image( 'output/color_shade.png')
You should see this beautiful output. Note how the combination of the shaded relief with the colorized image produces a map that transmits a lot of information even for untrained eyes.
3.129.24.180