10000 Fix imshow edges by tacaswell · Pull Request #8300 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fix imshow edges #8300

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
API: tweak how masking from agg alpha channel is handeled
Only mask out as 'bad' pixels which have alpha == 0
  • Loading branch information
tacaswell committed Mar 20, 2017
commit 44b409751eb0c70cc87831d3c786e9b7882f9d62
8 changes: 3 additions & 5 deletions lib/matplotlib/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,14 +413,12 @@ def _make_image(self, A, in_bbox, out_bbox, clip_bbox, magnification=1.0,
raise ValueError("Invalid dimensions, got %s" % (A.shape,))

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

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

_image.resample(
A, output, t, _interpd_[self.get_interpolation()],
self.get_resample(), alpha,
self.get_resample(), alpha if alpha is not None else 1,
self.get_filternorm() or 0.0, self.get_filterrad() or 0.0)

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

# Apply alpha *after* if the input was greyscale without a mask
if A.ndim == 2 or created_rgba_mask:
alpha_channel = output[:, :, 3]
alpha = self.get_alpha()
if alpha is not None and alpha != 1.0:
alpha_channel = output[:, :, 3]
alpha_channel[:] = np.asarray(
np.asarray(alpha_channel, np.float32) * alpha,
np.uint8)
Expand Down
Binary file modified lib/matplotlib/tests/baseline_images/test_image/rotate_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
0