8000 respect array alpha with interpolation_stage='rgba' · matplotlib/matplotlib@c6caa3d · GitHub
[go: up one dir, main page]

Skip to content

Commit c6caa3d

Browse files
chaoyihutacaswell
authored andcommitted
respect array alpha with interpolation_stage='rgba'
1 parent 7ede092 commit c6caa3d

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

lib/matplotlib/image.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -501,17 +501,25 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
501501
if A.ndim == 2: # interpolation_stage = 'rgba'
502502
self.norm.autoscale_None(A)
503503
A = self.to_rgba(A)
504-
alpha = self._get_scalar_alpha()
505-
if A.shape[2] == 3:
506-
# No need to resample alpha or make a full array; NumPy will expand
507-
# this out and cast to uint8 if necessary when it's assigned to the
508-
# alpha channel below.
509-
output_alpha = (255 * alpha) if A.dtype == np.uint8 else alpha
504+
505+
alpha = self.get_alpha()
506+
if alpha is not None and np.ndim(alpha) > 0:
507+
output_alpha = _resample(self, alpha, out_shape, t, resample=True)
508+
output = _resample( # resample rgb channels
509+
# alpha: float, should only be specified when alpha is a scalar
510+
self, _rgb_to_rgba(A[..., :3]), out_shape, t)
510511
else:
511-
output_alpha = _resample( # resample alpha channel
512-
self, A[..., 3], out_shape, t, alpha=alpha)
513-
output = _resample( # resample rgb channels
514-
self, _rgb_to_rgba(A[..., :3]), out_shape, t, alpha=alpha)
512+
alpha = self._get_scalar_alpha()
513+
if A.shape[2] == 3:
514+
# No need to resample alpha or make a full array; NumPy will
515+
# expand this out and cast to uint8 if necessary when it's
516+
# assigned to the alpha channel below.
517+
output_alpha = (255 * alpha) if A.dtype == np.uint8 else alpha
518+
else:
519+
output_alpha = _resample( # resample alpha channel
520+
self, A[..., 3], out_shape, t, alpha=alpha)
521+
output = _resample( # resample rgb channels
522+
self, _rgb_to_rgba(A[..., :3]), out_shape, t, alpha=alpha)
515523
output[..., 3] = output_alpha # recombine rgb and alpha
516524

517525
# output is now either a 2D array of normed (int or float) data

0 commit comments

Comments
 (0)
0