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

Skip to content

Commit 44b4097

Browse files
committed
API: tweak how masking from agg alpha channel is handeled
Only mask out as 'bad' pixels which have alpha == 0
1 parent 68ad0c4 commit 44b4097

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

lib/matplotlib/image.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,12 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
413413
raise ValueError("Invalid dimensions, got %s" % (A.shape,))
414414

415415
alpha = self.get_alpha()
416-
if alpha is None:
417-
alpha = 1.0
418416

419417
output = np.zeros((out_height, out_width, 4), dtype=A.dtype)
420418

421419
_image.resample(
422420
A, output, t, _interpd_[self.get_interpolation()],
423-
self.get_resample(), alpha,
421+
self.get_resample(), alpha if alpha is not None else 1,
424422
self.get_filternorm() or 0.0, self.get_filterrad() or 0.0)
425423

426424
if created_rgba_mask:
@@ -445,7 +443,7 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
445443
# and the pixels that Agg is telling us to ignore (relavent
446444
# to non-affine transforms)
447445
# Use half alpha as the threshold for pixels to mask.
448-
out_mask = out_mask | (hid_output[..., 3] < .5)
446+
out_mask = out_mask | (hid_output[..., 3] == 0)
449447
output = np.ma.masked_array(
450448
hid_output[..., 0],
451449
out_mask)
@@ -463,9 +461,9 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
463461

464462
# Apply alpha *after* if the input was greyscale without a mask
465463
if A.ndim == 2 or created_rgba_mask:
464+
alpha_channel = output[:, :, 3]
466465
alpha = self.get_alpha()
467466
if alpha is not None and alpha != 1.0:
468-
alpha_channel = output[:, :, 3]
469467
alpha_channel[:] = np.asarray(
470468
np.asarray(alpha_channel, np.float32) * alpha,
471469
np.uint8)

0 commit comments

Comments
 (0)