# Tweaking illumination/shading

**URL:** <https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511>\
**Category:** Q&A\
**Tags:** gmt\
**Created:** [March 28, 2021, 1:32pm UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511 "2021-03-28T13:32:10Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [August 9, 2023, 7:10pm UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/41 "2023-08-09T19:10:11Z")

</div>

Yes

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [August 9, 2023, 7:27pm UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/42 "2023-08-09T19:27:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Andreas](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@Andreas](https://forum.generic-mapping-tools.org/u/Andreas)\
**Post date:** [August 10, 2023, 10:07am UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/43 "2023-08-10T10:07:32Z")

</div>

For those interested:

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

See e.g.

- [Texture shading for QGIS](https://landscapearchaeology.org/2021/texture-shading/)
- [QGIS Terrain Shading](https://landscapearchaeology.org/qgis-terrain-shading/)

---

<div class="post-metadata">

**Author:** ![KristofKoch](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/kristofkoch/32/314_2.png) [@KristofKoch](https://forum.generic-mapping-tools.org/u/KristofKoch)\
**Post date:** [August 10, 2023, 10:18am UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/44 "2023-08-10T10:18:30Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [August 10, 2023, 11:03am UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/45 "2023-08-10T11:03:55Z")

</div>

Yes, so far via Julia only.

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [August 10, 2023, 11:59am UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/46 "2023-08-10T11:59:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [September 4, 2023, 7:21pm UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/47 "2023-09-04T19:21:49Z")

</div>

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

```auto
#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:

 ![texthill](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/5/5f0d2e38da158a147b64b5515605844273dbff4a.jpeg)

 ![texthill](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/3/32d756f3baea408901cc2f99cde135be030a7685.jpeg)

 ![texthill](https://canada1.discourse-cdn.com/flex047/uploads/gmt/original/2X/f/f93819182366f4393cf31b8d47321f713c3ddfe8.jpeg)

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [September 4, 2023, 7:55pm UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/48 "2023-09-04T19:55:49Z")

</div>

> [@mkononets](#):
>
> using pure `gmt` and `gdal`

> [@mkononets](#):
>
> `gdal_calc.py -A hawaii_south_textureshade_gamma.tif -B ...`

😄😄😄

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [September 4, 2023, 8:16pm UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/49 "2023-09-04T20:16:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [September 4, 2023, 9:17pm UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/50 "2023-09-04T21:17:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [September 4, 2023, 9:50pm UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/51 "2023-09-04T21:50:18Z")

</div>

> [@Joaquim](#):
>
> your _pure gmt and gdal_ is actually using Python

my point exactly.

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [September 5, 2023, 7:51am UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/52 "2023-09-05T07:51:36Z")

</div>

It looks so much nicer …

Too bad that

```auto
# texture and texture_image must be compiled from source

```

is so deterrent for on the go illustrations.

Thanks @mkononets

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [September 5, 2023, 9:37am UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/53 "2023-09-05T09:37:27Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [September 5, 2023, 10:13am UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/54 "2023-09-05T10:13:24Z")

</div>

> [@mkononets](#):
>
> The alternatives for now is to use Julia _and_ building @Joaquim’s branch of `gmt` (that is building `gmt` from scratch)

This is false.

---

<div class="post-metadata">

**Author:** ![pwessel](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/pwessel/32/30_2.png) [@pwessel](https://forum.generic-mapping-tools.org/u/pwessel)\
**Post date:** [September 5, 2023, 10:29am UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/55 "2023-09-05T10:29:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [September 5, 2023, 10:33am UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/56 "2023-09-05T10:33:14Z")

</div>

@pwessel Thanks! Personally I wanted it right now.

@Joaquim please elaborate. Thanks.

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [September 5, 2023, 11:52am UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/57 "2023-09-05T11:52:41Z")

</div>

> [@mkononets](#):
>
> @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.

---

<div class="post-metadata">

**Author:** ![mkononets](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/mkononets/32/4029_2.png) [@mkononets](https://forum.generic-mapping-tools.org/u/mkononets)\
**Post date:** [September 5, 2023, 2:44pm UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/58 "2023-09-05T14:44:04Z")

</div>

> [@Joaquim](#):
>
> a pre-build GMT that already contains what used to be a branch but now is in master.

That’s a good news!

---

<div class="post-metadata">

**Author:** ![PlanetGus](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/planetgus/32/303_2.png) [@PlanetGus](https://forum.generic-mapping-tools.org/u/PlanetGus)\
**Post date:** [September 5, 2023, 5:31pm UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/59 "2023-09-05T17:31:50Z")

</div>

Get a room you two 😉

> [@pwessel](#):
>
> Patience

Yeah yeah yeah, you know, the restlessness of youth 😁

---

<div class="post-metadata">

**Author:** ![Joaquim](https://yyz1.discourse-cdn.com/flex047/user_avatar/forum.generic-mapping-tools.org/joaquim/32/16_2.png) [@Joaquim](https://forum.generic-mapping-tools.org/u/Joaquim)\
**Post date:** [September 8, 2023, 1:45pm UTC](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511/60 "2023-09-08T13:45:41Z")

</div>

[One-liner example](https://flint.soest.hawaii.edu/t/the-lealand-texture-illumination-again/4231)

[Previous page](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511.md?page=2)

[Next page](https://forum.generic-mapping-tools.org/t/tweaking-illumination-shading/1511.md?page=4)
