I am trying to create a colorized hillshade using gdal and store it as a new file. I'd like to use the 'overlay' method (see also: Overlay)
Unfortunately, it doesn't produce what I'd expect (which would be what I see in QGIS overlaying two layers.
The two images below show the difference:
Image 1) Overlay of hillshade and colorrelief using QGIS with gamma = 0.5
Image 2) Overlay of hillshade and colorrelief using GDAL and the formula from the link above; also with gamma = 0.5
Can anyone point me to what the QGIS renderer is doing differently?
Here's the code I'm using:
# load data:
hs = rio.open(os.path.join(path, hs_in))
hs_arra = hs.read(1)
cr = rio.open(os.path.join(path, cr_in))
crr_arr = cr.read(1)
crg_arr = cr.read(2)
crb_arr = cr.read(3)
# define gamma:
gamma = 0.5
# calculate gamma-corrected hillshade
ghs = ((hs_arra/255)**(1/gamma))*255
red = np.where(ghs < 128, 2*(ghs/255)*(crr_arr/255)*255, (1-2*(1-ghs/255)*(1-crr_arr/255))*255)
green = np.where(ghs < 128, 2*(ghs/255)*(crg_arr/255)*255, (1-2*(1-ghs/255)*(1-crg_arr/255))*255)
blue = np.where(ghs < 128, 2*(ghs/255)*(crb_arr/255)*255, (1-2*(1-ghs/255)*(1-crb_arr/255))*255)