mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Let the text-to-mask .mask.png
file be used as a mask
Ironically, the black and white mask file generated by the `invoke> !mask` command could not be passed as the mask to `img2img`. This is now fixed and the documentation updated.
This commit is contained in:
parent
d8c1b78d83
commit
2e14ba8716
@ -81,15 +81,18 @@ text2mask feature. The syntax is `!mask /path/to/image.png -tm <text>
|
|||||||
It will generate three files:
|
It will generate three files:
|
||||||
|
|
||||||
- The image with the selected area highlighted.
|
- The image with the selected area highlighted.
|
||||||
|
- it will be named XXXXX.<imagename>.<prompt>.selected.png
|
||||||
- The image with the un-selected area highlighted.
|
- The image with the un-selected area highlighted.
|
||||||
|
- it will be named XXXXX.<imagename>.<prompt>.deselected.png
|
||||||
- The image with the selected area converted into a black and white
|
- The image with the selected area converted into a black and white
|
||||||
image according to the threshold level.
|
image according to the threshold level
|
||||||
|
- it will be named XXXXX.<imagename>.<prompt>.masked.png
|
||||||
|
|
||||||
Note that none of these images are intended to be used as the mask
|
The `.masked.png` file can then be directly passed to the `invoke>`
|
||||||
passed to invoke via `-M` and may give unexpected results if you try
|
prompt in the CLI via the `-M` argument. Do not attempt this with
|
||||||
to use them this way. Instead, use `!mask` for testing that you are
|
the `selected.png` or `deselected.png` files, as they contain some
|
||||||
selecting the right mask area, and then do inpainting using the
|
transparency throughout the image and will not produce the desired
|
||||||
best selection term and threshold.
|
results.
|
||||||
|
|
||||||
Here is an example of how `!mask` works:
|
Here is an example of how `!mask` works:
|
||||||
|
|
||||||
@ -120,7 +123,7 @@ It looks like we selected the hair pretty well at the 0.5 threshold
|
|||||||
let's have some fun:
|
let's have some fun:
|
||||||
|
|
||||||
```
|
```
|
||||||
invoke> medusa with cobras -I ./test-pictures/curly.png -tm hair 0.5 -C20
|
invoke> medusa with cobras -I ./test-pictures/curly.png -M 000019.curly.hair.masked.png -C20
|
||||||
>> loaded input image of size 512x512 from ./test-pictures/curly.png
|
>> loaded input image of size 512x512 from ./test-pictures/curly.png
|
||||||
...
|
...
|
||||||
Outputs:
|
Outputs:
|
||||||
@ -129,6 +132,13 @@ Outputs:
|
|||||||
|
|
||||||
<img src="../assets/inpainting/000024.801380492.png">
|
<img src="../assets/inpainting/000024.801380492.png">
|
||||||
|
|
||||||
|
You can also skip the `!mask` creation step and just select the masked
|
||||||
|
|
||||||
|
region directly:
|
||||||
|
```
|
||||||
|
invoke> medusa with cobras -I ./test-pictures/curly.png -tm hair -C20
|
||||||
|
```
|
||||||
|
|
||||||
### Inpainting is not changing the masked region enough!
|
### Inpainting is not changing the masked region enough!
|
||||||
|
|
||||||
One of the things to understand about how inpainting works is that it
|
One of the things to understand about how inpainting works is that it
|
||||||
|
@ -911,9 +911,12 @@ class Generate:
|
|||||||
# with alpha transparency. It converts it into a black/white
|
# with alpha transparency. It converts it into a black/white
|
||||||
# image with the transparent part black.
|
# image with the transparent part black.
|
||||||
def _image_to_mask(self, mask_image, invert=False) -> Image:
|
def _image_to_mask(self, mask_image, invert=False) -> Image:
|
||||||
# Obtain the mask from the transparency channel
|
if mask_image.mode in ('L','RGB'):
|
||||||
mask = Image.new(mode="L", size=mask_image.size, color=255)
|
mask = mask_image
|
||||||
mask.putdata(mask_image.getdata(band=3))
|
else:
|
||||||
|
# Obtain the mask from the transparency channel
|
||||||
|
mask = Image.new(mode="L", size=mask_image.size, color=255)
|
||||||
|
mask.putdata(mask_image.getdata(band=3))
|
||||||
if invert:
|
if invert:
|
||||||
mask = ImageOps.invert(mask)
|
mask = ImageOps.invert(mask)
|
||||||
return mask
|
return mask
|
||||||
|
Loading…
x
Reference in New Issue
Block a user