Skip to content

Separate alpha and rbg interpolation then recombine to fix issue11316 #12062

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,16 +486,31 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
raise ValueError("Invalid dimensions, got %s" % (A.shape,))

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

alpha = self.get_alpha()
if alpha is None:
alpha = 1.0
alpha = 1

#resample alpha channel
alpha_channel = A[..., 3]
_image.resample(
alpha_channel, output_a, t,
_interpd_[self.get_interpolation()],
self.get_resample(), alpha,
self.get_filternorm(), self.get_filterrad())

#resample rgb channels
A = _rgb_to_rgba(A[..., :3])
_image.resample(
A, output, t, _interpd_[self.get_interpolation()],
A, output, t,
_interpd_[self.get_interpolation()],
self.get_resample(), alpha,
self.get_filternorm(), self.get_filterrad())

#recombine rgb and alpha channels
output[..., 3] = output_a

# at this point output is either a 2D array of normed data
# (of int or float)
# or an RGBA array of re-sampled input
Expand Down
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/matplotlib/tests/baseline_images/test_png/pngsuite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,20 @@ def test_image_interps():
ax3.set_ylabel('bicubic')


@image_comparison(baseline_images=['interp_alpha'],
extensions=['png'], remove_text=True)
def test_alpha_interp():
'Test the interpolation of the alpha channel on RGBA images'
fig, (axl, axr) = plt.subplots(1, 2)
# full green image
img = np.zeros((5, 5, 4))
img[..., 1] = np.ones((5, 5))
# transparent under main diagonal
img[..., 3] = np.tril(np.ones((5, 5), dtype=np.uint8))
axl.imshow(img, interpolation="none")
axr.imshow(img, interpolation="bilinear")


@image_comparison(baseline_images=['interp_nearest_vs_none'],
extensions=['pdf', 'svg'], remove_text=True)
def test_interp_nearest_vs_none():
Expand Down