Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita23a397

Browse files
committed
API: tweak how masking from agg alpha channel is handeled
Only mask out as 'bad' pixels which have alpha == 0 and reapply thealpha provided back by Agg at the end.
1 parent68ad0c4 commita23a397

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

‎lib/matplotlib/image.py

Lines changed: 6 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
raiseValueError("Invalid dimensions, got %s"% (A.shape,))
414414

415415
alpha=self.get_alpha()
416-
ifalphaisNone:
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(),alphaifalphaisnotNoneelse1,
424422
self.get_filternorm()or0.0,self.get_filterrad()or0.0)
425423

426424
ifcreated_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,12 @@ 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
ifA.ndim==2orcreated_rgba_mask:
464+
alpha_channel=output[:, :,3]
465+
alpha_channel[:]=np.asarray(
466+
np.asarray(alpha_channel,np.float32)*hid_output[...,3],
467+
np.uint8)
466468
alpha=self.get_alpha()
467469
ifalphaisnotNoneandalpha!=1.0:
468-
alpha_channel=output[:, :,3]
469470
alpha_channel[:]=np.asarray(
470471
np.asarray(alpha_channel,np.float32)*alpha,
471472
np.uint8)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp