@@ -1556,20 +1556,21 @@ def hillshade(self, elevation, vert_exag=1, dx=1, dy=1, fraction=1.):
1556
1556
+ np .cos (alt ) * np .cos (slope )
1557
1557
* np .cos (az - aspect ))
1558
1558
1559
- # Apply contrast stretch
1559
+ #-- Apply contrast stretch
1560
1560
imin , imax = intensity .min (), intensity .max ()
1561
1561
intensity *= fraction
1562
- if np .abs (fraction ) > 1 :
1563
- np .clip (intensity , imin , imax , intensity )
1564
1562
1565
- # Rescale to 0-1, keeping range before contrast stretch
1566
- if imax > imin :
1563
+ #-- Rescale to 0-1, keeping range before contrast stretch
1564
+ # If constant slope, keep relative scaling (i.e. flat should be 0.5,
1565
+ # fully occluded 0, etc.)
1566
+ if (imax - imin ) > 1e-6 :
1567
+ # Strictly speaking, this is incorrect. Negative values should be
1568
+ # clipped to 0 because they're fully occluded. However, rescaling
1569
+ # in this manner is consistent with the previous implementation and
1570
+ # visually appears better than a "hard" clip.
1567
1571
intensity -= imin
1568
1572
intensity /= (imax - imin )
1569
- else :
1570
- # If constant slope, keep relative scaling
1571
- # (i.e. flat should be 0.5, fully occluded 0, etc.)
1572
- intensity = (intensity + 1 ) / 2
1573
+ intensity = np .clip (intensity , 0 , 1 , intensity )
1573
1574
1574
1575
return intensity
1575
1576
0 commit comments