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

Fix: support alpha array for RGB images in imshow (closes #26092)#30111

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Vaishnavi-Raghupathi wants to merge2 commits intomatplotlib:main
base:main
Choose a base branch
Loading
fromVaishnavi-Raghupathi:fix-rgb-alpha

Conversation

Vaishnavi-Raghupathi

-->Summary

This PR fixes issue#26092 by enabling the use of a 2D alpha array with RGB images inimshow. Previously, passing an alpha array worked for grayscale images but was ignored for RGB images. With this change, the alpha array is correctly combined with the RGB data, allowing for per-pixel transparency in color images.

--> What was changed

  • Modified the image handling logic to stack the user-provided alpha array with the RGB image, producing an RGBA image as expected.
  • Shape validation was added to ensure the alpha array matches the image dimensions.

--> How it was tested

  • Manually tested by displaying an RGB image with a 2D alpha array and confirming that transparency is applied correctly (top half transparent, bottom half opaque).

--> Additional notes

  • No new automated test was added, as this was a manual verification. Please let me know if a formal test is required.

Closes#26092

Copy link
Member

@rcomerrcomer left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Hi@Vaishnavi-Raghupathi we do usually require new tests for code changes. Also, some of the existing tests are broken by this change, which needs to be addressed.

The issue has moved on a fair bit since it was opened. I believe the most important comment to read is#26092 (comment). You should check what the code in there produces with and without your change. I believe the remaining work is to make the bottom right subplot look like the centre right subplot, i.e. when we have an RGBA array and an alpha array passed in, the alpha of these two arrays should be blended.

# user-specified array alpha overrides the existing alpha channel
A=np.dstack([A[..., :3],alpha])
else:# Scalar alpha
ifA.shape[2]==3:# broadcast scalar alpha
A=np.dstack([A,np.full(A.shape[:2],alpha,np.float32)])
else:# or apply scalar alpha to existing alpha channel
post_apply_alpha=True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why is this removed?

post_apply_alpha=True
#to handle RGBA inputs
ifA.shape[2]==4andalphaisnotNone:
A[...,3]=alpha# override existing alpha channel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I think this is just repeating what already happened on line 518.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

These changes do not belong in this PR.

@rcomerrcomer moved this fromNeeds review toWaiting for author inFirst Time ContributorsMay 28, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@rcomerrcomerrcomer left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
Projects
Status: Waiting for author
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

[Bug]: alpha array-type not working with RGB image in imshow()
2 participants
@Vaishnavi-Raghupathi@rcomer

[8]ページ先頭

©2009-2025 Movatter.jp