How to create mask with prompt in ComfyUI

Published Categorized as Workflow Tagged , No Comments on How to create mask with prompt in ComfyUI


Creating a mask for an image has numerous visual and computational applications, ranging from graphic design to advanced computer vision tasks. Creators can use the masks to maintain contextual integrity and unlock innovative possibilities in downstream workflows.

In this workflow, you can create masks automatically using a prompt. For example, the prompt “bottle” creates a mask and an inverted mask below.

You need to be a member of this site to download the ComfyUI workflow.

Software

We will use ComfyUI, an alternative to AUTOMATIC1111.

Read the ComfyUI installation guide and ComfyUI beginner’s guide if you are new to ComfyUI.

Take the ComfyUI course to learn ComfyUI step-by-step.

Workflow overview

This workflow uses the Grounding DINO and Segment Anything models to create masks from an image using a prompt. The workflow creates a mask and an inverted mask specified by the prompt.

Step-by-step guide

Step 1: Update ComfyUI

Before loading the workflow, make sure your ComfyUI is up-to-date. The easiest way to do this is to use ComfyUI Manager.

Click the Manager button on the top toolbar.

Select Update ComfyUI.

Restart ComfyUI.

Step 2: Load workflow

Download the ComfyUI JSON workflow below.

Become a member of this site to see this content

Already a member? Log in here.

Drag and drop the JSON file to ComfyUI.

Step 3: Install missing nodes

Click Manager > Install Missing Custom Nodes.

Install the nodes that are missing.

Restart ComfyUI.

Step 4: Revise the prompt

Revise the prompt in the GroundingDinoSAMSegment node. Write the object for which you want to create a mask.

Step 5: Upload an image

Upload an image to the Load Image node.

Step 6: Run workflow

Click Queue to run the workflow.

queue button comfyui

You get three images:

  • An image with the subject alone
  • The mask
  • The invert mask
Andrew

By Andrew

Andrew is an experienced software engineer with a specialization in Machine Learning and Artificial Intelligence. He is passionate about programming, art, and education. He has a doctorate degree in engineering.

Leave a comment

Your email address will not be published. Required fields are marked *