Inpainting Tutorial - Stable Diffusion

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Inpainting the secret sauce to stable diffusion and how the pros get the best looking images. You can turn a generation from this into this. And people keep asking me, do you need the inpainting model? No you don't, but it will help you with the larger fixes. But to be completely honest with you, I usually use the regular models for inpainting as well. So we had a painter over, when he was finished he wouldn't accept my money. So I asked him why and he replied, don't worry, the paint is on the house. All right, so when you're inside stable diffusion, you're going to enter image to image here, and then this tab inpainting. Now I've prepared an image here, and if we zoom in on this a little bit, you can see that the image is fairly good, but the face here isn't great. The nose is all messed up, the ear is not great. So you might have an image that looks like this. You're fairly happy with the composition, but you need to fix most of the time the face. But it could be other parts, it doesn't really matter. So this is what we're going to do today. And also this feature here, the scroll, this is not default. So if you want this, you're going to go into extensions, and you're going to find this, the canvas zoom. And you can either copy paste this URL and install from URL, or you can check available, load from and find it in the list and install it. When you're in here, we are gonna inpaint first the face here. Now you have a lot of options to choose from. And first of all, the mask mode is going to be inpaint mask, because we have painted what we're supposed to be changing. If you did it the other way around, you're going to choose inpaint not masked that would change the rest of the image. Now this is where most people get it wrong, the masked content. If you want like this image, you want to keep what's under here, which is her face, then you're going to choose original, because then it will remember what's below here, and use that to create our next iteration of the image. If you have nothing under here, you need to switch to latent noise. These two are the ones that you're going to use for 99% of users. Then we have the in paint area here. And if you take whole picture, then all of this frame, this image will be rendered. So this part that we've painted will keep the same resolution as the rest of the image. However, for this image, we don't want that. We want more detail, better resolution here. So if we change this in paint area to only masked, it will take this area here, and render this in full resolution, and then splice it together with the big image. And that can be changed here. So this image fully is 768 by 768. So this is what we'll use here as well. But this doesn't have to coincide with the full image if you're in painting just a masked area. Euler A is a great sampling method. I usually do that at 25 steps. I also like DPM 2M caris and SDE caris. I usually run that at 30, 35 steps, but it's a little slower. Now, if you just want to upscale the image, let's say you want to keep the details, then I run this at 0.4. However, we want to change the details because the details weren't good. We want better details, better quality. So then I usually go with 0.6. Let me show you an example here. So we're going to do one image here. I'm going to type in woman face. Now I have a negative prompt that I use, which is the nfixer. And that can be downloaded from the Armada merge model or Illuminati model, but that is not required. So now you can see that we're only getting this part of the image. If you go back here, you can see that it's a major change compared to the left one. Now we actually have a proper face. Now let's say you didn't get this result. Then you have probably either changed the mask content here. You have a different resolution or your denoising strength is off. Let me show you what happens if I set this to, for example, one. The denoising is how much the image will be changed. So one will change it completely and zero would change it. Nothing at all. So let's paint back in here and generate. And now it will change completely. It will still be a woman, but it doesn't retain much of the original. As you can see, it's a completely different woman and the hair doesn't match at all. This woman has a different hairstyle and it's kind of blended into the other one. So this is not a great results. And if we would have the denoising at zero, you can see here that we won't get any change to the image at all. So this is just the same image. That's why I recommend, especially for an image like this, where you have the original, I set this at 0.6. And then you can keep going. Now if you drag this image to the left here, you can keep working with what you have here. Now, if you were to want to add something to the image, let's say you want to add a coffee cup here. And we're changing this to coffee cup or coffee mug or whatever. Now, if I would keep this at original and 0.6, it would try to make the coffee cup from what's below here, which is basically nothing. So as you can see here, we're not getting any coffee cup. We have the same image and nothing because it couldn't find anything to work with that looks like a coffee cup. So in this instance, there are two ways to solve this. And if you change this to latent noise, it will give the image. As you can see here, you can see the noise coming in here, but it didn't work. Then you might say, well, that didn't work Seb, you're a terrible teacher. Well, let me show you. When you're using latent noise, you need to raise the denoising string. Because now you need to change more of this noise that gets added. Let me show you. And there we go. Now we got a little coffee cup here. Now it's not perfect to scale or anything. And that's one of the issues with working with the latent noise, because it doesn't understand really how this is supposed to interact with the rest of the image. What I would do is I would go inside in paint sketch here, we're going to drag our image in. And here, we can draw. So you can pick a color or for example, let's take this brown here. And then let's try to sort of create the cup here. Let's give it some the light is hitting from the left here. So maybe just add some doesn't have to be perfect. Well, we're going to iterate on this. And now, when we render, first of all, we can change the mass content to original. And then we can lower the denoising a little bit. Now, not as low as point six, because this needs to be changed a lot, but maybe point eight point nine. And we don't have a perfect value here. This needs to be tested and fine tuned. Let's do two images. And now we have something that's more in line with the scene. They're not perfect still. But we can work with that we can take what we have, we can take this and drag this into here. And then we can either paint more, or we can use the in painting. This one and just mask this out and change this into well another cup a cup. But now we have most of it there. So now we can lower the denoising even more. I'm changing to four images. And we are rendering because now we want some more examples we want AI to give us something to choose from. And here we have some more coffee cups. Now, it doesn't look like the one we have to the left here. It's another coffee cup, but I think it's a fairly cool addition to the scene. Now, if you want this better, since this is a, you can see clear that this is a blurred cup, then you're going to need to work with this even more. You can add blurred into the scene. We can actually try that. Now I added blurred coffee cup out of focus. And while it may not be perfect, it's better than what we had before. Now it's a similar blur to the left here. Now, and this can be adapted to something I do is add a blue color. I actually take this, go into Photoshop or photopea and paint a little rough sketch, which can be more detailed down in paint sketch. But let's pretend we're happy with this. You can drag this into here and you can actually keep working with the face because we have this part. We can actually go, let's say we want the eyes here. I'm setting the denoising to 0.6 again. Now let's do two images. Now we will render even closer. That will give us more details specifically in the in painted area here. And you can keep going as long as you want with this. Look at this one, for example. You can see we've got some more detail in the eyes here. And again, if you want to keep iterating, just drag that to the left. Now let's say we want to change the earring here. Beautiful golden earring. You can see we're getting much more intricate details compared to the first one. You can see in some of the image, there's a little line here, like a blurred line. And that can be changed with, you have the mask blur here and only masked padding pixels. So the padding, that changes how far from the object this blur is. And the mask blur here changes how much the blur is. Think of it as a Gaussian blur. So let's say we set this to 20 instead. We're gonna set this a little closer. You can see the line is not as distinct anymore, especially in this one. So there you have it, in painting in stable fusion. Once you get to know the values and settings, it's fairly easy. And you can keep iterating with very advanced scenes with multiple people, faces and characters and whatever. It doesn't matter. If you learned something today, feel free to like and subscribe. If you don't, that's fine too. I'm not your boss. I'll see you in the next video. As always, have a good one. See ya.
Info
Channel: Sebastian Kamph
Views: 197,871
Rating: undefined out of 5
Keywords:
Id: No1_sq-i_5U
Channel Id: undefined
Length: 12min 31sec (751 seconds)
Published: Thu Apr 06 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.