Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Description
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
frompylabimport*a=tril(arange(1.,26.).reshape(5,5))a[a==0]=np.nanaxs=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
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