Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3c9cacf

Browse files
committed
Make clipping work properly for effectively planar surfaces
1 parent f374383 commit 3c9cacf

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/matplotlib/colors.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,20 +1556,21 @@ def hillshade(self, elevation, vert_exag=1, dx=1, dy=1, fraction=1.):
15561556
+ np.cos(alt) * np.cos(slope)
15571557
* np.cos(az - aspect))
15581558

1559-
# Apply contrast stretch
1559+
#-- Apply contrast stretch
15601560
imin, imax = intensity.min(), intensity.max()
15611561
intensity *= fraction
1562-
if np.abs(fraction) > 1:
1563-
np.clip(intensity, imin, imax, intensity)
15641562

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.
15671571
intensity -= imin
15681572
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)
15731574

15741575
return intensity
15751576

0 commit comments

Comments
 (0)