Skip to playerSkip to main content
Manually painting layer paths over hundreds of individual video frames or batch outputs is a massive bottleneck. In this tutorial, I show you how to automatically isolate and mask a character or dominant subject right inside ComfyUI, whether you are using a loaded photo or an image straight from a generation node!

While right-clicking an image to use the standard manual Mask Editor works for single setups, it breaks down entirely when dealing with complex batch sequences. I walk you through an advanced automated approach utilizing the OneFormer COCO Segmentor. You'll learn how to break down the resulting multi-color segment map by converting individual color data into dedicated Red, Green, and Blue mask channels. From there, we use Mask Composite mathematical subtraction nodes (Subtracting Red and Green, then filtering out Blue) combined with a ToBinaryMask node to output a razor-sharp, flawless black-and-white alpha transparency mask instantly.

Original YouTube Tutorial: https://youtu.be/DsoV3xaEnas

Connected Videos in this Series:
* Convert Real Videos to OpenPose Tracking Skeletons: https://youtu.be/T9YNARKEkq8
* Fix Broken Node Dependencies with ComfyUI Manager: https://youtu.be/dyrhPVRsy9w

Source/Model Resources:
* ComfyUI Official Framework: https://github.com/comfyanonymous/ComfyUI
* ComfyUI Custom Nodes / Segmentors (COCO Node Base): Search "Coco Segmentation" or "OneFormer" via ComfyUI Manager.
* Workflow Project Files: Check out your saved node tree links over on https://comfyworkflow.com/

Video Details:
* Original Publish Date: July 2024
* Focus: Automated Subject Masking / OneFormer COCO Segmentation / Alpha Channel Extraction
* Hardware Setup: Local PC utilizing an NVIDIA RTX GPU setup (e.g., RTX 4060 Ti)

Follow lordcaocao2025 on Dailymotion for more deep dives into complex procedural masking, automated composition pipelines, and zero-fluff ComfyUI guides!

---
Connect with me:
📺 YouTube: https://www.youtube.com/@CaoCao2025
📱 TikTok: https://www.tiktok.com/@caocao20250
💎 Patreon: https://www.patreon.com/cw/Caocao2025

#ComfyUI #COCOSegmentation #AutoMasking #BackgroundRemoval #StableDiffusion #AIVideo #TechTutorial #lordcaocao2025
Transcript
00:00Hello guys, welcome back with me, Chow Chow 2025.
00:04Today we going learn how to mask a dominant part of the picture automatically in Comfy UI.
00:12Masking in Comfy.
00:14If only one image is pretty simple, just right click the image, then click open in Mask Editor.
00:20In Mask Editor, you could do masking like in Forge or Automatic 11.11.
00:26Just click, save to node then.
00:30But it will be difficult if you have a lot of image to mask.
00:36The problem also arise if the image is a result of generation.
00:40If the image is the result of generation, it will be impossible for you to mask it manually without disturbing
00:47the flow.
00:58There are actually a way to be able to mask dominant picture like character or prime object that located in
01:06the center from an image automatically.
01:08Whether it is original image or image, result of generation.
01:14It works most of the time.
01:17You can later edit the result image or join it with other image or background.
01:24First, you need to have Comfy UI, Comfy Manager and Cocoa Segmentation.
01:30I put the link of the workflow on the description so you can install all missing node using Manager.
01:42Now I will explain how it works.
01:45First, we need some image.
01:48We will segment this with one former Cocoa Segmental.
01:51The result will be a bunch of segment not focusing only on character.
02:20The next thing to do is convert the Thee, the segment based on its color to red segment.
02:26Green segment and blue segment.
02:29We do this by using convert image to mask and set up the channel according to red, green, blue.
02:36We are going to show how the mask shown by convert mask to image and put a preview image.
02:52We are going to subtract red and green mask using mask composite.
03:04Here are the results.
03:06Now we also subtract the red, green result with blue to get the next combination.
03:11is getting there.
03:19Now we combine the mask with solid color with value 0.5.
03:38Here are the results.
03:40Lastly, we are going to create only two color on the mask by using top binary mask.
03:46Light color will be white while dark color will be black.
03:51Adjust the threshold if you want.
03:53In this setting, I use one.
04:11Now you could use the mask of dominant image.
04:13Now you could get what you want.
04:14Whether the mask of dominant image.
04:17Or not the dominant one.
04:20You could use invert mask for this.
04:24Now we have both mask.
04:26We can use this mask for in painting.
04:29Or we could use the undominate mask to crop it with black or solid color to get only the dominant
04:35image.
04:36We could also use this to merge dominant image to a new background image.
04:56It's just like .
05:25You can use the magic of your color for the mask.
05:26It's like you can use it to have a new color.
05:54You
06:15You
06:16You might want to focus on your character only and not on the background.
06:21There's still a way to do this.
06:22We could use a second mask process.
06:27This time we use one former AD a 20K segmentor.
06:31And this time we only split between red and green and then solid color.
06:36The rest of the process is the same.
06:39And here are the results.
07:03It also work for our original picture.
07:31Of course, if you just want to remove a background.
07:34You could use image, rembg or remove background.
07:39Like this.
07:44There are many things that you could do with this.
07:47Just be creative.
07:50Anyway guys, that's it for today video.
07:55Don't forget to like, share and comment.
07:58See you on the next episode.
08:01And have a nice day.
08:03Please, subscribe.
Comments
lordcaocao2025
Creator
Procedural segmentation shifts the entire workflow away from slow, manual roto brush painting. Isolating the character directly out of the initial image generation path means you can seamlessly swap backgrounds or drop in stylized overlays dynamically without touching a third-party editor. Did the channel subtraction separate your character cleanly from the background elements? Let me know below!

Recommended