ComfyUI Fundamentals - Adv Masking and Compositing

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay welcome to another Camp VI fundamentals tutorial uh we're going to be covering uh Advanced masking techniques and compositing in this tutorial um I'm gonna raise one thing before we start which is a lot of this stuff can be done using Photoshop or or any number of other editing um programs and in some cases it would be much quicker for you to use those than to use this process but this process can be automated you can actually batch the processes that I'm going to teach here using um you know automated masking nodes like clipse egg and that kind of stuff so bear that in mind I'm going to show you just the manual processes but um if you want to use automated things you can do that stuff basically so you'll see this uh this works was a little bit different it's a little bit more advanced than the other ones because we're using multiple text encoders and we're producing multiple different images and the reason we're doing that is we are going to be combining these three images into one image actually and in order to do that where we need these these image previews are our um they're our resources basically and this section is going to be unlinked from what we're going to be doing with image masking and stuff this is specifically just for one thing and that's to generate images so um if you have your own version of this where you have a whole bunch of um a bunch of nodes and a bunch of clip texts and stuff or messing around with things I I've got a really complicated one that I'm not going to put up but um I use that to generate Concepts and brainstorm ideas with my prompting and stuff like that it's a good idea to have something like this where you've got the ability to just slam down tons of prompts and tons of samples and just generate like crazy answer I've got these three images and I'll explain them so this one is a location this is a place where we are going to composite these other things into we're putting um it into a haunting liminal Canyon made of gray complete concrete blocks and then we're going to put a dude in a biohazard suit in here as well and then we're going to put this weird creature in it too hopefully I can find a way of making it fit somewhere in there but it's part of the journey is making things work so first off we're going to need some image loaders I am going to include this with the prompt I'm going to include it without all of this stuff and you'll have to kind of follow along and build these more complicated stuff this whole stuff up here that I'm going to show you with all the image manipulation um it's kind of a bespoke process it's not something that um it would necessarily lend itself to your processes if you're trying to make art because this is more of an artistic one-off art type thing rather than a um Mass producing type system so anyway in order to use these we're going to get three of them and we're going to copy the stuff from one to the other now you could save them out from here and then load them the other way but I just do this because it's quicker and it it keeps me from having all this stuff on my hard drive basically so the reason we have these three nodes is because you can see they've got a mask and image and that's important we need the masking and we need the image and so for both of these things we want just the um the subject out of these two images and this one we're keeping the entire image so we're going to mask these out so we right click open in mask editor and you'll have seen this kind of stuff in um my masking tutorial if you've used that if not um you could go watch that for some more background on this whole process if you want all right so unfortunately for us comfy wise masking tool is uh a little bit wanting when it comes to features which means that um it's very difficult to tell when you've masked an actual a dark shape and it also means that um it's really hard to focus on what you're you can change the size of this and that's the only thing you can do you can't even zoom in on the on the image which is it travesty when it comes to actually doing masking but we're going to mask this save to node so this area is now saved as a selectable mask in this node and because we're going to need this to be coming out as an image I'm just gonna do this a lot of custom nodes require you to convert your green mask into an actual image mask and an image mask is pretty I didn't show this earlier in the other masking thing but I'll show you now it's simply a black and white image of this now there are things you can do to this in order to refine it because this is just an editable image which means that you can go into things like white suit you can open up all your image editing stuff in here you can do all kinds of stuff like changing the region stuff you can tweak stuff you can run Feathering you can smooth the edges of things there's all kinds of crazy stuff you can do to try and refine these mask edges but we're not going to really bother with it because um well maybe you will why not let's just use the simplest one we can we'll do a post-processing image blur may as well that way we can um preview image now if we read this to 22. it'd be much too high so we're going to lower it to 10. so yeah that'll stop us from having a super sharp edge on this stuff and we'll make this small and go over here and then we're going to copy this Ctrl C TRL V and plug this into here and we're going to pick one of these two people which one would fit best in here I'm thinking the left hand one yeah we'll grab the left hand one now if we're using clipseat we could grab these people using clipsec you just type in the word humanoid and it'll select all the humanoids but clipsec is bad if there's more than one person so just be full one you don't want this uh having multiple Mast objects in one image is um it's it's hard to work harder to work with so I'd advise against it all right grab this I should do that whole this is what I prepared earlier but I feel like if I show you more of the process you'll have a bit more confidence to just try it yourself all right this is mask this is coming out I'm gonna remove this preview and this one they're both doing the same thing so just blurring a little bit and now in order to make use of these we actually have to perform a masking thing on it so we are going to use the Masquerade notes which are basically your One-Stop shop for masking stuff just be aware that um there are masking Tools in last suit under images but they're not particularly compatible with masquerade nerds because they use this weird I'll show you masking oh oops I just happened to pick one that didn't have what I wanted on it um image let's do crop all right I just did that one um how about mask paste okay yeah here we go so West nodes will use the master region but they must have a thing called crop data which um basically restricts them to connecting during the other last node masking things which is really really frustrating um because there's no um there's no crop data into something else thing in it yeah it's it's very frustrating so um anyway that's me complaining again let's use masquerade nodes to perform an action and we're going I'm going to cut the image out so we're cutting this person that we've masked over out of the image and in order to get the information of where it is we're going to grab the mask and then we're going to grab actually sorry the image we need is from here and The Mask we're going for you so the mask is the selection area and the image is the pixels which are hidden by that mask currently sir if we pull out a preview of this you'll see that it has selected this area basically and because we're using the wrong mask I'm just going to fix the mask and you'll actually see what the effects of the blur does see how it has smoothed all the edges around this so you can use that to kind of uh make this whole process a little bit uh less messy when it comes to putting images on top of each other so we're going to copy this process over here now we're going to attach the image to here oh wait okay this is the mask I keep messing that up mask and this one's the image and preview all right and so we've got to do it here so now that we have this this stuff here this is our resources we're going to be using we're basically building a stack of resources that we can put in another image and this is that image so in order to put these into another image we have to create another node and we're going to use the paste by mask now there's all kinds of stuff in there you could experiment with any number of these and see what they do um this one we're going to use because it we have the image to paste which is going to be our cut by mask output we have the mask as well and we can grab the uh this is how you choose where the image is going to be by the way the mask is not necessarily like these are the pixels that need to be covered so much as where is the image and we can just use that one and the image base is going to be this so if we output an image now you'll notice we're not generating stuff here these are all in fixed mode so they're not regenerating new ones and this is all it practically instant because uh it's not generating stuff yet we'll do this afterwards but at the moment these don't need to do anything particularly fancy now because I've used this mask you'll notice that the creature is in the same spot it was on the other image and we paste it in and that's not that may not be what you want what if you wanted to be somewhere else so interestingly we can do a number of different things we could draw on here and create a new mask um because this will accept mask data from anything I can plug this one into this mask so this is in a different location and if we queue the prompt it's tried to put our creature over against the wall where this guy actually comes from so if we we can change these settings that'll change how it tries to place it in the image as well so this one tries to keep it um the right size and the right ratio and fit within the Mast area so that's a good way of making an image smaller or possibly bigger if you fill up the whole size of the screen this tries to keep it the same size as in the original and this keeps the same size and doesn't use the mask to hide stuff so this one's good for putting stuff on top of things this is good for putting stuff in a window for example this one's good for um keeping it within the Mast area and this one is good for um hang on I'll just regenerate this yeah this one tries to put as much cover as much of the original um mask as possible and this one resizes all sizes to fit it doesn't care about keeping it square basically and we're just going to use our mask for the moment so I'm going to show you the other way of doing this so I've used this mask to do that but um I could use any mask I can um let's do a yeah let's let's just copy this image alone yep so now we have this and we're going to now draw in here elsewhere we're going to go mask editor and I want that creature to be here specifically so I wanted to fill this region now whether or not this works we'll say we'll see so just masked this small area and we're going to use this as a mask instead and we're going to send it here and it should move down let's move down but it's obviously not placed properly so we can mess with this stuff try and get it to fit in our image so as you can see keep ratio fills doing it I could do this one this one should work except that it's way too big and you can you can change that by resizing this this cut by mask will actually change the size of this image so if I make this can't resize it smaller can I I probably can we'll see yeah if it is smaller real very small good I was unclear on that mechanic a little bit so you see how we're going smaller and we're decreasing the size of this so if we that see how it's kind of in in this hole but we don't have a lot of good control over this and um unfortunately that is a bit of a problem with this there's no good good way of accurately controlling these you can put them in generally where they should go but um generally it's a very imprecise thing like this no it's dead what we'll do is we will make sure that we use this particular one I think because at least that's the right size and in the right location although it does seem like it's probably too small so maybe we should tweak this if we go in here and edit this mask um how about yeah this is what we'll do we'll clear it we'll put it here so hopefully if we now put this here keep dropped it'll put it here but we want it coming out around the corner so let's look for a flip node image flip well well well we can do some image manipulation here so we're going to flip this one here because this is where our resource sits it's best to change it in this area here so if we're going to modify this image it has to be between this node and this node all right so now we have turned it around but as you can see this image doesn't really fit our needs does it so maybe we should just generate another one I mean this one seems more like what we might need so if we instead do the same thing as before we go right click copy clip space paste clip space into here and then we go mask editor and we relatively quickly cut this thing out now I could use of course clipsec to very quickly do all this and uh some of you might do that all right here we go now we have this different thing and when we go Q it saves it in the other position and we can remove this because we don't need it to face that way instead it's going to face this way and now it's coming out from around the corner so what do we do with these legs wow we can grab this thing and we can go we can clone it again so as you can see this is building up a big network of things but they're they're all kind of going towards building this one image here so maybe this stuff uh needs are moving around or whatever better this is more of a messy process Than You'll generally find over here but uh so what we're going to do is we're going to open the marketer and we're going to grab this section here now can we do we can remove good I wish I could just hold a key and make it move straight so as I said earlier um this is not an Optimum way of doing things but it is a way that you can do things so we're going to mask this stuff and we're going to we'll do the Clone again we'll grab the image we'll grab the mask oh yeah mask to image sorry and these tutorial is probably going to go a bit longer than the other ones so because we still have more to do with this all right so what we are actually doing is we are going to paste again so we're going to clone this pasting this keeping the original and we're going to use this mask to do it now we want a sharp edged mask so we don't care about the blur for this one and because we now have two things you'll see how that we build a little tree and it comes to here and then to here and then it's like okay again we have to combine these two so clone this the image to paste is going to be the top one and the image base is going to be the one with this on it so the idea is to whoops mask mask I need this mask yeah yeah in theory if I'm correct damn all right here we go uh gotta juggle these until you find one that works okay that's definitely not it okay all right cut by mask I'm pasting it twice I might be pasting it twice yeah I think I might be doing it twice hang on I need to see what this is doing first okay that is the correct image so the image base needs to be this one sorry figure it out that's what I was doing wrong okay here we go sorry I I added one of these when I didn't need it all right so you can see we've partially masked this we just need to do a little bit more work and this will be masked out and its feet will be hidden so go back here edit again add some more of the original back here now if we are lucky it's now gone well there's still a little bit but we don't really care about that so now the creature looks like it's coming out from around the corner and we'll put that there and let's add Mr Hazard suiti guy as well so now we need to use another paste mask obviously and we're going to use U and we're going because it's going to be in here we'll paste this one and the mask is going to be the one from here and we need the kind of blurry one so should be this yeah this one will do I hate that do the mask as I have told you to do them not whatever you were doing at the moment okay yeah okay preview okay so he needs adjusting as well so what we can do is we can um clone this yet again you can use empty images first I'm just using this so I know where things are and we're going to do it over here and we're going to put him over here somewhere so edit it and we're going to go over here this way we can try and make him be on the actual floor instead of standing on top of this awkwardly okay and we're going to just feed the mask in like so and now it's moved him down onto the ground so now we have put a composite image together and yes you could have generated attempted to generate this using prompts and you may have succeeded but especially when a color is involved and you have directly said I want this to be a certain color this can be very problematic for prompting but if we use this method we can ensure that the right people are in the right places and the right creatures are in the right places we're basically taking back control from the sampler here with this so now that we've constructed this whole thing here is just to composite this whole thing into one image so in order to make use of it we're actually going to move the whole thing I'm going to move it up so that it's a little bit more out of the way and we're going to make a new sand plan the new sample is going to have its own prompt again because well I could try combining each of these into a prompt and then saying yes this will be what's in it this yellow is going to be badly messed with it so we're going to have to be a little bit more careful without prompting and because this is going to be the end component of the workflow right you can add a bunch of stuff after this there's nothing stopping you um we're just going to end it here with this one and then we're going to pull out a clip and we're going to grab the clipped thing as well and so you'll notice that the negative is shared across all of them by the way this saves me the time of rewriting this every single time and on top of that having separate prompts for each of them is is a great way of controlling what you're going to be doing in multiple images so we're going to say yes and test wearing a who has it suit [Music] exploring uh dark thriving monster coming around the corner okay so whether or not that helps us much who knows we're just trying to describe this image as much as possible and we're going to use a um physics we're not going to use a latent we're going to use another load image and it's going to be this now you could use our image saves anywhere in this process and I suggest you do because if you use previews and load images the way I'm using them if you close this workflow and start again all this will get wiped so um if you care about what you're making make sure it's got It's on Save nodes basically clearly I don't care what I'm making right now I have no reason to save this really so uh for me it's it's not really a problem but for you you might want to save these and we'll do a very encode and we will do way back here I was being messy with the cables because This is the End spot okay grabs that and we are going to bring this way down to work three this is kind of a tuning process where we're going to we're doing an image to image essentially and the idea is to change this image as little as possible but use the denoising that we do here to fix up the editing mistakes caused by the compositing and if we do it right it should maintain most of its details so it's added a shadow for him which is pretty cool even though the shadow is kind of unrealistic so yeah there you go as you can see it has messed up some stuff you could regenerate this a number of times so we can go again and uh you know do it repeatedly in different seeds different fingers you can tweak it as much as you want and then you can move this on to the next step and the next step you're upscaling and so on but this is how you do compositing um there you go much better image now this is how you can do compositing stuff now you can probably stop there if you want but I'm going to keep going because there's more we can do to this using similar techniques because we can use image manipulation over here to cause some cool effects so I'm going to put this on fixed I'm just going to regenerate it with fixed I can ensure that the image stays the way I want it to be um for my future work so that um I can make sure that uh if I if I'm doing the very specific thing it's a good idea to have all the back stuff just kind of holding still all right that seems good enough my main concerns the back of this guy's head uh let's do a image I'll show you a cool thing you can do where we now I'll do this one um gradient see there's this annoying thing that comfy UI does not have it has a thing called an empty um it has a whoops wrong one so talking and trying to do complicated things at the same time gradient gradient yeah that okay so Kung Fu I does not have a lot of basic nodes that would be kind of a good idea to have and one of those it has an empty node right it has the uh the latent empty Latin image but it doesn't have one where you can just set a color there's no empty solid color which is kind of crap right but if you have westerners you can cheat it with an image generate gradient I mean you could use an image loader if you have one like an image handy but if you are super lazy you can just do this now I'm going to add a little bit of red to this um let's do 50 60 yeah that'll do and so this is RGB by the way and this is this is the um this is the percentage of this gradient thing so this is where on the image the um this value will be used and it spreads out between them so if I do 0 60 whatever it'll go red and then if I go um like 10 uh uh zero Dash uh 60-0 I'll just show you preview I might as well show you how this thing works while we're at it so you can see it's making gradients and if I keep prompt so just did 10 but if I put this at 70. see how it stretches out so this is a really good way of tuning your images by the way you just have to know the RGB values of things I'm trying to remember an RGB value at the moment but it's probably going to be wrong that was wrong that was pretty wrong uh 10 why not and then uh we'll go 30 green and then no no blue no wait RGB yeah so this is blue zero ah why not we use this one and I'll show you what this does to it uh right so this shows me what this is doing and it can go here and we're going to be combining some stuff so we're going to pull out a image post process blend the blend node is amazing and you will find yourself using a lot if you do this kind of stuff that I'm about to show you so if we blend this gradient with this image at 50 percent we are going to get this image as you can see the color is a bit meh and so on so I'm going to raise this a bit more give it a bit more Bingo all right now if we do multiply we can subtly change the way it's handling things we can do screen so we can we can see how it's changed the top color of this image and a little bit of green on here so we're in effectively we're able to tweak how our colors are in certain places on this image this way so if we use something like this we can I'm just trying to tweak it for a very specific look to the background so this is a good way of if you are um actually an artist and what actually make images that you want to make using this stuff to tweak your images as you go so now that we have tweaked this in a way that I wish to do we will pass it through another VA encode and as you can see it's getting very massive over here so we're going to shift things and this here and this here yeah I feel like I need this stuff Ctrl C shift V that's that's hooked up wrong damn I thought they had fixed this but it looks like they're still not quite uh how I'd like it but good enough all right um I'm just complaining about nothing again model yep and we don't need that we need this and it needs here sir um let's pull another one of these and we'll use the same prompt so we may as well put it in the bus that uh doesn't yet exist all right housekeeping is important if you want to be able to control control do it properly it's not going to do it in there oh see control V I wish I could control shift V with these and then it would drag from the current node that I had selected instead of the previous one that's what I wish okay that plugs in we can plug in the negative and the positive all right we need we're nearly done we're nearly done nearly done all right now oh dear I've done something weird okay the tolerances yeah I think I think that's what I did whoops I messed up the image um yeah my gradient go messed up when I tried to drag this box and I drag this slider thing out so um using this method we can get better images if we run it after we've done colors on them as you can see it's lost some detail in here but this is probably because um it's using the same seed as the previous one so I'm just gonna do this and then it should should have less of that burn in effect if you stack two samples and have the same seed it can cause this kind of weird uh weird kind of distortions on it looks like it's been burnt in using um certain filters there we go see it smoothed it all out again yeah so as you can see it's changed the colors slightly it's made it darker more um you know just it's very minor changes you can cause a huge amount of change on things and we'll just run it again using a lot darker this time um stable diffusion loves to go bright so if you make a very dark image and you run it through a sample the stuff in the sample likes to get brighter if it can it won't be as dark as this image basically usually it'll it'll have some lighter spots if you if you look at the both you'll see that there's um the lighter spots have been highlighted anyway um so that's that's some ways of doing image manipulation with um yes and I've also shown you how to you composite images using some more advanced masking techniques and hopefully you find this useful in getting some really cool images done and I would love to see them um if you actually do make some stuff with this because um I think it's a really powerful tool that people are unaware of because they're they're trapped in this idea that um stairway diffusion is just you type in words and then an image comes out and you can do more than that if you want so anyway thanks for watching me rant for 42 minutes the next tutorial is going to be covering prompts specifically I'm going to go into the depth of prompting um and yeah I might do some more stuff if you have suggestions for future tutorials let me know as well thank you for watching
Info
Channel: Ferniclestix
Views: 17,166
Rating: undefined out of 5
Keywords:
Id: Yc13jDr9VRk
Channel Id: undefined
Length: 42min 24sec (2544 seconds)
Published: Mon Aug 07 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.