How to automatically mask a character or dominant part of the picture in ComfyUI
Hello Guys welcome back with me ChowChow 20-25
Today we going learn how to mask a dominant part of the picture automatically in Comfy U I
Masking in Comfy U I if only one image is pretty simple, just right click the image then click open in Mask Editor
In Mask Editor you could do masking like in forge or automatic 11 11
Just Click Save to node then
But it will be difficult if you have a lot of image to mask.
The problem also arise if the image is a result of generation
If the image is the result of generation, it will be impossible for you to mask it manually without disturbing the flow
There are actually a way to be able to mask dominant picture like character from an image automatically
Whether it is original image or image result of generation
It work most of the time
You can later edit the result image or join it with other image or background
How to do it?
First you need to have Comfy U I, Comfy Manager and Coco Segmentation.
I put the link of how to install them in the video description
I also put the link of the workflow on the description so you can install all missing node using manager
Now i will explain how it works
first, we need some image
We will segment this with One Former Coco segmentor
The result will be a bunch of segment not focusing only on character
The next thing to do is convert the the segment based on it's color to red segment, green segment and blue segment
We do this by using Convert Image To Mask and set up the channel according to Red Green Blue
We going to show how the mask shown by convert mask to image and put a preview image
Next we going to substract Red and Green mask using mask composite
here are the result
Now we also substract the Red Green result with Blue to get the next Combination
is getting there
Now we combine the mask with solid color with Value 0.5
here are the result
lastly we going to create only two color on the mask by using ToBinaryMask
Light color will be white while dark color will be black
adjust the threshold if you want
in this setting i use 1
Now you could get what you want, whether the mask of dominant image
or the not the dominant one
You could use invert mask for this
Now we have both mask
we can use this mask for inpainting
or we could use the undominat mask to crop it with black or solid color to get only the dominat image
we could also use this to merge dominant image to a new background image
You might to focus on your character only, and not on the background,
there still a way to do this
We could use a second mask process
this time we use One Former ADE20K Segmentor
And this time we only split between red and green and then solid color
the rest of the process is the same
and here are the result
It also work for our original picture
Off course if you just want to remove a background
You could use Image Rem b g or Remove Background
like this
There are many thing that you could do with this
Just be creative
Anyway guys, that's it for today video
thank you for watching
don't forget to like, share and comment
see you on the next episode
and have a nice day
please subscribe