Skip to content

[Bug]: interpolation_stage="data" removes too many pixels in the vicinity of nans in upsampled, interpolated images #29778

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

Open
anntzer opened this issue Mar 19, 2025 · 1 comment

Comments

@anntzer
Copy link
Contributor

anntzer commented Mar 19, 2025

Bug summary

Currently, when upsampling images with interpolation_stage="data", upsampled pixels are set to nan ifany of the underlying data points is nan. This leads to much wider "nan-propagation" than interpolation_stage="rgba".

Code for reproduction

from pylab import *

a = tril(arange(1., 26.).reshape(5, 5))
a[a == 0] = np.nan
axs = figure(layout="constrained").subplots(2, 2)
axs[0, 0].imshow(a, interpolation_stage="data", interpolation="none")
axs[0, 0].set_title("stage=data, interp=none")
axs[0, 1].imshow(a, interpolation_stage="data", interpolation="bilinear")
axs[0, 1].set_title("stage=data, interp=bilinear")
axs[1, 0].imshow(a, interpolation_stage="rgba", interpolation="none")
axs[1, 0].set_title("stage=rgba, interp=none")
axs[1, 1].imshow(a, interpolation_stage="rgba", interpolation="bilinear")
axs[1, 1].set_title("stage=rgba, interp=bilinear")

show()

Actual outcome

Image

Note how the blank area is much wider in the bilinear, data-stage interpolation case.

Expected outcome

Although I'm not sure the choice is objective, I think a blurred boundary (similarly to the bottom right case) would make sense.

Implementation-wise, I suspect this arises from a similar issue as #29711 (comment): it should indeed be possible to interpolate in data space even with nans if we interpret the data array as a single-channel image with an additional alpha channel (0-1, depending on whether the data is nan) and correctly weighting the data by the alpha channel (similarly to the premultiplied alpha filtering suggested in the comment). Without setting a zero weight on the nans, it becomes of course impossible to upsample pixels for which any underlying data points are nan (so setting the upsampled pixel to nan is the only reasonable choice).

Additional information

No response

Operating system

No response

Matplotlib Version

3.11.0.dev525+g9f7b3dd205

Matplotlib Backend

No response

Python version

3.13

Jupyter version

No response

Installation

git checkout

@timhoffm
Copy link
Member

To be checked: Under which circumstances does this happen when the user does not or little customization through kwargs? It's critical if this happens without the user being aware, because we're misrepresenting the data - looks like there's no information in these pixels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants