Purpose
txt2mask is a plugin that automatically creates masks for Stable Diffusion inpainting. As an add-on to the AUTOMATIC1111 Stable Diffusion Web UI, it allows users to enter a text string in img2img mode and automatically generate the corresponding image mask, thereby replacing manual mask drawing with the brush tool. This tool is powered by clipseg.
Main Capabilities
- In img2img mode, enter the text to search for in the Mask Prompt field to automatically generate a mask in the image.
- Provides a Mask Precision field to adjust the confidence of the mask; a value that is too low may cause areas beyond the intended target to be selected.
- Supports using | as a separator to search for multiple objects, for example entering face|a tree|a flower; clipseg will process these items independently and overlay the sub-masks into the final mask.
- Provides a Mask Padding option to expand the selection boundary, useful when the mask does not fully cover the target (such as a red shirt).
- Supports a Negative mask prompt to subtract specified content from the area selected by the Mask prompt; for example, if the Mask prompt is face and the Negative prompt is eyes, the mask will select the face but exclude the eyes.
- Supports a Brush mask mode setting, allowing the text mask to be used in combination with the brush tool or an uploaded image mask.
How to Use
- Clone or download the repository and place the files in the base directory of the AUTOMATIC1111 Web UI.
- In the img2img interface, select txt2mask as the active script.
- Enter the text to search for in the image in the Mask Prompt field.
- Adjust the Mask Precision field to increase or decrease the confidence of the mask.
- Click Generate to generate the mask.
Use Cases
Suitable for users who need to quickly and automatically generate masks in Stable Diffusion inpainting, especially in scenarios where they want to avoid manually using the brush tool and want to describe the target area in natural language.
Limitations and Notes
- This script has been replaced by the author's new extension Unprompted, which has the same masking functionality and more features. The author does not plan to update the original script and cannot guarantee that it will continue to work in new versions of the A1111 WebUI.
- This script is still under active development (based on the original source description).
- When masking, usually "less is more": rather than trying to mask "a one-armed man doing a backflip off a barn", writing "a man" may work better.
- A Mask Precision value that is too low may cause areas beyond the intended target to be selected.