-
Notifications
You must be signed in to change notification settings - Fork 785
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
Add function to apply mask to RawImage. #1020
Conversation
Add function to get a pixel and set a pixel.
Useful PR! 🔥 Could you reference the similar function / usage / inspiration? e.g., how PIL does mask application? |
@xenova, I am not completely familiar with the Python Imaging Library, however it looks like a similar thing is achieved with the following snippet - assuming I understand the docs correctly 😅 from PIL import Image
background = Image.open('background.png')
foreground = Image.open('foreground.png')
mask = Image.open('mask.png').convert('L')
result = Image.composite(background, foreground, mask)
result.save('masked_image.png') The mask is The foreground image would map to what This was a great resource for learning how that library and function works: |
Thanks! I followed that resource you provided and found https://note.nkmk.me/en/python-pillow-putalpha/ - perhaps it's more applicable? If so, I say we rename |
Yes - that's a much more apt name! |
Remove unused functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated it to support 3-channel and 4-channel images. Will merge now, and will add unit tests in follow-up PR. (Couldn't do now since I can't merge main into the PR; permission error)
I'm working on an app to remove the background from an image.
This PR adds the ability to very easily apply the result of the model as a mask to a RawImage.
The image alpha channel will be replaced with the values of the mask.
Here is an example of the sort of thing I am doing.