-
Notifications
You must be signed in to change notification settings - Fork 775
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
base: main
Are you sure you want to change the base?
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 |
if (this.channels !== 4) { | ||
throw new Error('Image must have 4 channels'); | ||
} |
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.
Would be useful to support both 3- and 4-channel images as the input image.
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.
Would you consider something like this?
Automatically convert to 4 channels if 3 are provided, however anything else will throw an error.
if (this.channels !== 4) { | |
throw new Error('Image must have 4 channels'); | |
} | |
if (this.channels === 3) { | |
this.convert(4); | |
} else if (![3, 4].includes(this.channels)) { | |
throw new Error('Image must have 3 or 4 channels'); | |
} |
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.
To prevent unnecessary conversions, I think we can set the step size accordingly (3 for RGB, 4 for RGBA) and write the image data accordingly.
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.
Hey, sorry I’ll get to this soon.
I’m currently poorly and bedridden at the minute, but will work on a fix ASAP.
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.
No rush! Feel better soon! 🤗
Yes - that's a much more apt name! |
Remove unused functions.
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.