ComfyUI: Generate and refine head masks with Florence 2 and SAM 2

Demo summary
The workflow shows using Florence 2 for object detection to target the head and SAM 2 for precise segmentation, including adjusting the 'grow mask expand' value to improve blending.
Step-by-step
- Use Florence 2 to identify and target the head region
- Pass the generated bounding box into SAM 2 for segmentation
- Adjust the grow mask expand value to refine the mask boundaries
Watch out for
- If the mask is too close to the existing outline, the model has less freedom to reinterpret shape and integrate the new face naturally
Tips
- Ensure the grow mask expand value is large enough so the mask does not hug the silhouette too tightly
- Adjust the grow mask expand setting first depending on the specific shot to allow the model room to be creative
All demos from “Learn How To: Face Swap”
0:290:24Load source footage and models in ComfyUIThe user demonstrates importing source video footage and loading the necessary model nodes including WAN Video, VAE, and Clip Vision within the ComfyUI interface.ComfyUI· AI Animation Generator
0:530:48Generate and refine head masks with Florence 2 and SAM 2CurrentThe workflow shows using Florence 2 for object detection to target the head and SAM 2 for precise segmentation, including adjusting the 'grow mask expand' value to improve blending.ComfyUI· AI Inpainting
1:410:46Prepare driving data and auto-prompts with Qwen2-VLThe demo shows running pose detection on source footage and using Qwen2-VL (referred to as Gwen VL) to generate a semantic text description from a reference image for the face swap.ComfyUI· AI Face Swap Generator
3:280:27Simplified face swap using ComfyUI App ModeA demonstration of the simplified 'App Mode' interface where users can upload footage and a reference image to perform a face swap without interacting with the node graph.ComfyUI· AI Face Swap Generator- Watch “Learn How To: Face Swap” →
AI Inpainting
1:02:141:23Landscape composition control with Canny ControlNetShows how to use the Canny edge pre-processor to maintain the shape of mountains while changing the lighting to a sunset.AI Search
6:360:29Adjust mask expansion settingsThe user demonstrates adjusting the 'Grow Mask with Blur' node's expand value to accommodate larger replacement characters.MDMZ
3:120:44Anime character replacement with MochaA demonstration of replacing one anime character with another using a reference image, highlighting the tool's performance on complex outfits and hair.AI Search
7:201:48Edit image details with Flux KontextThe user shows how to load a reference image and use a text prompt to change specific features, such as changing a cartoon bunny's eye color to red.pixaroma
19:191:08Modify hairstyles and facial featuresThe creator shows how to change a subject's hair color and style (e.g., to a blunt bob with bangs) while attempting to maintain facial consistency using Flux Kontext.pixaroma
21:030:26Edit text within an imageA demonstration of Flux Kontext's ability to change text on a 3D render from 'Welcome' to 'Pixaroma' while maintaining the original font style and perspective.pixaroma
23:191:55Remove objects using Mask Editor and InpaintingThe user demonstrates precisely removing a necklace from a portrait by painting a mask in the ComfyUI Mask Editor and using an inpainting prompt.pixaroma
16:571:43Generate composite image with Flux 2The creator demonstrates image-to-image generation by uploading two reference photos and using a text prompt to replace a logo on a coffee can with his own headshot using the Flux model.WINBUSH
20:010:28Text-to-image manipulation in ComfyUIThe video shows how to use a text prompt to attempt to rotate an object in an image within a specific node-based workflow.WINBUSH
15:063:12Transform 3D scenes with Qwen2-VL (Qwen-Edit)The creator uses the Qwen-Edit workflow to perform complex scene modifications, such as changing weather to rain or snow, while preserving the original 3D geometry and text.Matt Hallett Visual
20:221:07Fix text and faces using Crop and StitchA demonstration of a custom 'crop image' node to isolate specific areas like signs or faces, regenerate them at native resolution, and stitch them back into the high-res image.Matt Hallett Visual
8:230:24Change hairstyles with AIA demonstration of using an outfit change system to apply a new haircut to a character by using a hairstyle image as a reference.Yaroflasher
ComfyUI