@@ -1528,12 +1528,8 @@ def hillshade(self, elevation, vert_exag=1, dx=1, dy=1, fraction=1.):
1528
1528
Increases or decreases the contrast of the hillshade. Values
1529
1529
greater than one will cause intermediate values to move closer to
1530
1530
full illumination or shadow (and clipping any values that move
1531
- beyond 0 or 1). Values less than one will cause full shadow or
1532
- full illumination to move closer to a value of 0.5, thereby
1533
- decreasing contrast. Note that this is not mathematically or
1534
- visually the same as increasing/decreasing the vertical
1535
- exaggeration.
1536
-
1531
+ beyond 0 or 1). Note that this is not visually or mathematically
1532
+ the same as vertical exaggeration.
1537
1533
Returns
1538
1534
-------
1539
1535
intensity : ndarray
@@ -1557,12 +1553,16 @@ def hillshade(self, elevation, vert_exag=1, dx=1, dy=1, fraction=1.):
1557
1553
+ np .cos (alt ) * np .cos (slope )
1558
1554
* np .cos (az - aspect ))
1559
1555
1560
- intensity -= intensity .min ()
1561
- intensity /= intensity .ptp ()
1562
- if fraction != 1.0 :
1563
- intensity = fraction * (intensity - 0.5 ) + 0.5
1564
- if np .abs (fraction ) > 1 :
1565
- np .clip (intensity , 0 , 1 , intensity )
1556
+ # Apply contrast stretch
1557
+ imin , imax = intensity .min (), intensity .max ()
1558
+ intensity *= fraction
1559
+ if np .abs (fraction ) > 1 :
1560
+ np .clip (intensity , imin , imax , intensity )
1561
+
1562
+ # Rescale to 0-1, keeping range before contrast stretch
1563
+ intensity -= imin
1564
+ intensity /= (imax - imin )
1565
+
1566
1566
return intensity
1567
1567
1568
1568
def shade (self , data , cmap , norm = None , blend_mode = 'hsv' ,
@@ -1608,11 +1608,8 @@ def shade(self, data, cmap, norm=None, blend_mode='hsv',
1608
1608
Increases or decreases the contrast of the hillshade. Values
1609
1609
greater than one will cause intermediate values to move closer to
1610
1610
full illumination or shadow (and clipping any values that move
1611
- beyond 0 or 1). Values less than one will cause full shadow or
1612
- full illumination to move closer to a value of 0.5, thereby
1613
- decreasing contrast. Note that this is not mathematically or
1614
- visually the same as increasing/decreasing the vertical
1615
- exaggeration.
1611
+ beyond 0 or 1). Note that this is not visually or mathematically
1612
+ the same as vertical exaggeration.
1616
1613
Additional kwargs are passed on to the *blend_mode* function.
1617
1614
1618
1615
Returns
@@ -1625,7 +1622,8 @@ def shade(self, data, cmap, norm=None, blend_mode='hsv',
1625
1622
1626
1623
rgb0 = cmap (norm (data ))
1627
1624
rgb1 = self .shade_rgb (rgb0 , elevation = data , blend_mode = blend_mode ,
1628
- vert_exag = vert_exag , dx = dx , dy = dy , ** kwargs )
1625
+ vert_exag = vert_exag , dx = dx , dy = dy ,
1626
+ fraction = fraction , ** kwargs )
1629
1627
# Don't overwrite the alpha channel, if present.
1630
1628
rgb0 [..., :3 ] = rgb1 [..., :3 ]
1631
1629
return rgb0
@@ -1649,11 +1647,8 @@ def shade_rgb(self, rgb, elevation, fraction=1., blend_mode='hsv',
1649
1647
Increases or decreases the contrast of the hillshade. Values
1650
1648
greater than one will cause intermediate values to move closer to
1651
1649
full illumination or shadow (and clipping any values that move
1652
- beyond 0 or 1). Values less than one will cause full shadow or
1653
- full illumination to move closer to a value of 0.5, thereby
1654
- decreasing contrast. Note that this is not mathematically or
1655
- visually the same as increasing/decreasing the vertical
1656
- exaggeration.
1650
+ beyond 0 or 1). Note that this is not visually or mathematically
1651
+ the same as vertical exaggeration.
1657
1652
blend_mode : {'hsv', 'overlay', 'soft'} or callable, optional
1658
1653
The type of blending used to combine the colormapped data values
1659
1654
with the illumination intensity. For backwards compatibility, this
0 commit comments