Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Open
@anntzer

Description

@anntzer

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

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp