2

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 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 Overlay of Hillshade and Colorrelief using Formula from 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)
2
  • Except that one is brighter than the other, they look identical to me. Commented Nov 8, 2022 at 9:38
  • well, i guess you are right about that. i'm simply wondering where the difference in brightness comes from... in the middle ranges (around 128) the values are the same in both images but they differ at the ends (aka contrast is much larger in the 'self-made' version)
    – Zev_Zide
    Commented Nov 8, 2022 at 16:14

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.