Tweaking illumination/shading

Yes

OK, once finished with something else I will have a look and merge.

For those interested:

The Leland Brown shading is implemented in qgis with the ‘Terrain Shading’ plugin.

See e.g.

After merging it into master it is only available via Julia and not via GMT directly or did I miss something?

Yes, so far via Julia only.

While we want to add it, no time for 6.5 of course, but later.

using gmt and gdal from CLI (improvements are very welcome):

#Death Valley National Park, CA, USA
#(Mesquite Flats area, -R-117.33/-116.84/36.51/36.84). Steep mountains and large alluvial fans:
ROI="-R-117.33/-116.84/36.51/36.84"

## Hawaii, -R-156/-155.5/19/19.5
#ROI="-R-156/-155.5/19/19.5"

## Alp mountains -R10.13/10.43/45.46/45.85
#ROI="-R10.13/10.43/45.46/45.85"

gmt makecpt -Cgray -T0/65535/1 -N > textureshade.cpt # texture_image produces a uint16 GeoTIFF image
gmt makecpt -Cgray -T0/255/1 -N > hillshade.cpt # gdaldem hillshade produces a uint8 GeoTIFF image

gmt grdcut @srtm_relief_03s -Ghawaii_south.nc $ROI
gmt grdcut @srtm_relief_03s -Ghawaii_south.flt=gd:EHdr $ROI
# texture and texture_image must be compiled from source
DETAIL=1.0
CONTRAST=+2.0
Source_Code/texture $DETAIL hawaii_south.flt hawaii_south_texture.flt
Source_Code/texture_image $CONTRAST hawaii_south_texture.flt hawaii_south_textureshade.tif
# embedding projection info into the textureshade image
gdal_edit.py -a_srs hawaii_south_textureshade.prj hawaii_south_textureshade.tif

gmt grdcut @srtm_relief_03s -Ghawaii_south.nc $ROI
# creating hillshade GeoTIFF
gdaldem hillshade hawaii_south.flt hawaii_south_hillshade.tif -s 111120 -z 4.0 -compute_edges

GAMMA=0.5
#gamma textureshade, texture_image produces a uint16 GeoTIFF image
gdal_calc.py -A hawaii_south_textureshade.tif \ 
    --calc="uint16(((A / 65535.)**(1/$GAMMA)) * 65535)" \
    --overwrite --outfile=hawaii_south_textureshade_gamma.tif

# blend hillshade with texture shade
gdal_calc.py -A hawaii_south_textureshade_gamma.tif -B hawaii_south_hillshade.tif --allBands=B \
--calc="uint8( ( \
                 2 * (A/65535.)*(B/255.)*(A<32768) + \
                 ( 1 - 2 * (1-(A/65535.))*(1-(B/255.)) ) * (A>=32768) \
               ) * 255 )" --type=Byte --outfile=bat_final.tif --overwrite

# plotting source reilef, shaded relief, texture shade after gamma correction, and hillshade blended with that texture shade
J=-Jx6i
gmt begin texthill jpg -C
 gmt set MAP_FRAME_TYPE=plain FORMAT_GEO_MAP="ddd.x" FONT_ANNOT_PRIMARY=auto
 gmt subplot begin 2x2 -Fs9c
 gmt subplot set 0
    gmt grdimage hawaii_south.nc $J -BWSne
    gmt colorbar -Rhawaii_south.nc $J -DJBC+h -By+lm -Bxaf
 gmt subplot set 1
    gmt grdimage hawaii_south_hillshade.tif -Chillshade.cpt $J -BWSne
 gmt subplot set 2
    gmt grdimage hawaii_south_textureshade_gamma.tif -Ctextureshade.cpt $J -BWSne
 gmt subplot set 3
   gmt basemap -Rbat_final.tif $J -BWSne
   gmt grdimage bat_final.tif -Chillshade.cpt $J -t20
 gmt subplot end
gmt end

the result:

:smile::smile::smile:

I knew there must be a smart ass with remarks just regarding pure gmt and gdal.

Don’t need to be rude.
In case you haven’t realize, your pure gmt and gdal is actually using Python too.

my point exactly.

It looks so much nicer …

Too bad that

# texture and texture_image must be compiled from source

is so deterrent for on the go illustrations.

Thanks @mkononets

@PlanetGus This is true, but building the texture shading software is not difficult. Links to the software archive and its manual are kindly provided in this very thread by @Andreas and @KristofKoch as well as the compilation instructions. The alternatives for now is to use Julia and building @Joaquim’s branch of gmt (that is building gmt from scratch) or not using texture shading at all.

This is false.

Don’t forget that we will implement this in GMT once we can get 6.5 and new and updated remote data sets off our backs. Patience.

@pwessel Thanks! Personally I wanted it right now.

@Joaquim please elaborate. Thanks.

Julia users do not build GMT themselves. They use a pre-build GMT that already contains what used to be a branch but now is in master.

And it happens that was working on the Julia solution to make this illumination a one liner.

That’s a good news!

Get a room you two :wink:

Yeah yeah yeah, you know, the restlessness of youth :grin:

One-liner example