You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, not much of an issue, but it seems that imshow is not interpolating RGBA images in the proper way. There was some discussion about a similar issue in #9906 which ended up on a documentation note:
imshow expects RGB images adopting the straight (unassociated) alpha representation.
If that's the case imshow should still switch to associated colors (premultiply alpha) before interpolation to avoid artefacts like the one below, shouldn't it?
import matplotlib.pyplot as plt
import numpy as np
fig, (axl, axr) = plt.subplots(1, 2)
# full green image
img = np.zeros((5, 5, 4))
img[...,1] = np.ones((5, 5))
# transparent above main diagonal
img[...,3] = np.tril(np.ones((5, 5), dtype=np.uint8))
axl.imshow(img, interpolation="none")
axr.imshow(img, interpolation="bilinear")
plt.show()
@tacaswell maybe my description can be a bit misleading. Black fringing is a common artifact when some part of a graphic pipeline uses premultiplied alpha while others don't, but I'm not entirely sure that's what's happening here.
A, output, t, _interpd_[self.get_interpolation()],
self.get_resample(), alpha,
self.get_filternorm(), self.get_filterrad())
That is where we re-sample RBGA images for rendering. From looking at that I suspect that this is an Agg bug, but we should be hitting this code path in cairo as well...
I suspect the fix here is to change to output starting as (1, 1, 1, 0), which will make it look right more often (as the default patch color is white), but should dig into it a bit more. We may want to re-sample the RGB and A seperatly like we do with the color-mapped data.
While building a test for this issue, I came across a problem with the interpolation keyword when savefig() is used with the SVG format. See issue #12065.
Activity
fargiolas commentedon May 26, 2018
it seems something
Aggspecific, it doesn't happen e.g. with thecairobackendtacaswell commentedon May 29, 2018
It looks like it is compositing it into black (0, 0, 0) rather than white (1, 1, 1)....
fargiolas commentedon May 29, 2018
@tacaswell maybe my description can be a bit misleading. Black fringing is a common artifact when some part of a graphic pipeline uses premultiplied alpha while others don't, but I'm not entirely sure that's what's happening here.
tacaswell commentedon May 29, 2018
matplotlib/lib/matplotlib/image.py
Lines 480 to 496 in 0334c04
That is where we re-sample RBGA images for rendering. From looking at that I suspect that this is an Agg bug, but we should be hitting this code path in cairo as well...
I suspect the fix here is to change to output starting as (1, 1, 1, 0), which will make it look right more often (as the default patch color is white), but should dig into it a bit more. We may want to re-sample the RGB and A seperatly like we do with the color-mapped data.
Crude fix for issue matplotlib#11316
dabana commentedon Sep 7, 2018
@tacaswell was right about doing the alpha and rgb interpolation separatly.
dabana commentedon Sep 7, 2018
While building a test for this issue, I came across a problem with the interpolation keyword when savefig() is used with the SVG format. See issue #12065.
fix for issue matplotlib#11316
tacaswell commentedon May 17, 2019
This was fixed by #12062 / #13559. Thanks @dabana !