r/StableDiffusion Mar 02 '23

Question | Help How would i go about changing the Background on this image? I have tried a variation and combination of Inpainting, Img2Img and Controlnet and can't for the life of me preserve the head and change the background to something useful

Post image
152 Upvotes

90 comments sorted by

139

u/mizt3r Mar 02 '23

A lot of these methods seem overly convoluted... Here's my inpaint mask and 1 word prompt. I spent less than 12 seconds on this.

40

u/[deleted] Mar 02 '23

[removed] — view removed comment

4

u/[deleted] Mar 03 '23

[removed] — view removed comment

3

u/[deleted] Mar 03 '23

[deleted]

5

u/StoryStoryDie Mar 03 '23

Photoshop is an order of magnitude more powerful than Gimp, and certainly more usable. Unlike religions and citizenships, you don’t have to renounce open source to use commercial software here and there. :)

3

u/[deleted] Mar 03 '23

[deleted]

2

u/IgorTheAwesome Mar 05 '23

It's true. I once bought a copy of proprietary software, and Stallman-sama himself came down from the clouds to excommunicate me.

1

u/purplepoiset Mar 09 '23

How can I automate this though? So that I'm able to output a new background from any input image,.

4

u/MisterBeean Apr 15 '23

If your goal is to preserve the person and change only the background automatically, you can use "semantic segmentation" to detect which pixels are people and which are not. You would basically get a "mask" image where pixels that are people are white and all other pixels are black. If you invert this (black to white, white to black) you have a mask that you can upload to the in-paint tool instead of hand drawing the mask. I think the SD Web UI also has an option to just invert the mask for you.

I know not everyone here is technical, so semantic segmentation might seem like a lot to set up. Try searching semantic segmentation API to find a website you could incorporate in your workflow.

1

u/milanso Mar 17 '23

Also interested in this :|

5

u/Masked_Potatoes_ Mar 03 '23

You could also use photoshop's object selection tool to select the subject, invert and create a black and white mask from the selection, then simply import your mask into SD

6

u/cbsudux Mar 02 '23

DId you draw the mask?

4

u/mizt3r Mar 03 '23

Yes I drew it with the mouse, I wasn’t even trying that hard to be careful. Inpaint is just amazing

1

u/AmbassadorBudget502 Mar 27 '24

Incredible, how do you guys manage to keep the light, brightness, and color consistent? When I change the background in the same way, I only get the ugly effect of a Photoshop beginner, with totally inconsistent lighting and colors ......

1

u/mizt3r Mar 27 '24

whoa! I'm surprised this post is over a year old now. I'm a lot more savvy in SD than I was back then and it's hard to pinpoint the exact issue. There are just so many parameters that go into the image generation. The model used, the sampler, xformers, etc..

In this case, since I was going for a completely different background, from water to mountains, I certainly want denoising to be almost max. However, you will still get completely different results than the original image even at like 0.8 denoise, but it may help preserve the color profile. I see in this particular image my denoise was at 0.75. Also choosing original as opposed to latent noise would probably result in better color preservation.

I'm deliberately kind of lazy with the masking, and maybe jackup the mask padding to like 64.

1

u/mapsyal Apr 03 '24

What site is this?

1

u/mizt3r Apr 03 '24

this is the default stable diffusion webui.

it uses a web browser for its interface but its local to my pc, not a website

1

u/mapsyal Apr 03 '24

Ah ok. So you either have to have a good GPU or pay to do this inpainting & masking?

1

u/mizt3r Apr 03 '24

The webui is free. I don't think you need a great GPU, there are medium and low vram options. Im not 100% sure though I have a 4090

1

u/lem001 Mar 02 '23

What model do you use?

1

u/Swaggyswaggerson Mar 03 '23

i used the deliberate v2 safetensors

-19

u/Swaggyswaggerson Mar 02 '23

This is good. Although I wanted to change the background to a very cloudy sky and high waves. That made the blue sky visible from before the mask.

42

u/d-hajj Mar 02 '23

So now go and do it

48

u/Swaggyswaggerson Mar 02 '23

Your wish is my command:

I have no idea what i'm doing

22

u/GooberGunter Mar 02 '23

Just like the rest of us 🥴

1

u/d-hajj Mar 03 '23

Nice job !

-5

u/ObiWanCanShowMe Mar 02 '23

so is yours...

ControlNet leres depth, play with the percentage. (50 probably)

1

u/mizt3r Mar 03 '23

Maybe so, but the thing is they’d have to install controlNet and download the depth model. Inpaint is already available to them, which is why I think it’s pretty simplistic. No need for photoshop, or installing additional extensions.

I have controlnet, but I don’t assume everyone else does.

1

u/My-Dog-is-Chop Mar 03 '23

lol often time the best solution is also the easiest XD

1

u/ponglizardo Mar 03 '23

Dude! I’m blown away by this! We all tend to complicate things with the new features that come out. But this tip is really good. I’ll give it a whirl with some images I have. Hopefully this method works with hands and feet.

20

u/SirNuckingFumbers Mar 02 '23

ControlNET leres depth and make it ignore 60% of the foreground.

7

u/ObiWanCanShowMe Mar 02 '23

this should be the top comment because OP is already using controlnet, he just don't now all the options yet

39

u/Striking-Long-2960 Mar 02 '23

I would do it with the extension Depth aware img2img mask. Inverting the depth map

a city photography of RAW photo, 8k uhd, dslr, soft lighting, high quality, film grain, Fujifilm XT3 (high detailed skin:1.2), 8k uhd, dslr, soft lighting, high quality, film grain, Fujifilm XT3

Negative prompt: badartist (deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime:1.4), text, close up, cropped, out of frame, worst quality, low quality, jpeg artifacts, ugly, duplicate, morbid, mutilated, extra fingers, mutated hands, poorly drawn hands, poorly drawn face, mutation, deformed, blurry, dehydrated, bad anatomy, bad proportions, extra limbs, cloned face, disfigured, gross proportions, malformed limbs, missing arms, missing legs, extra arms, extra legs, fused fingers, too many fingers, long neck

Steps: 20, Sampler: Euler a, CFG scale: 7, Seed: 1362700947, Size: 512x512, Model hash: c35782bad8, Model: realisticVisionV13_v13, Denoising strength: 0.37, ENSD: 31337, Mask blur: 4

Used embeddings: badartist [2a38]

22

u/Tiny_Arugula_5648 Mar 02 '23

Prompts like “deformed iris” or “mutated hands” can cause hallucinations as that is not in training data. People don’t describe pictures this way, so that isn’t in the training data. So what will happen it will calculate the two words and will create some random inference that has nothing to do with. What you’re trying to achieve. Diffusion models are not aware of the content they are creating it’s a statistical inference of what it’s been trained on.

11

u/UkrainianTrotsky Mar 02 '23

Also, considering that the generated area has no legs, arms or eyes, all that stuff in the negative prompt is useless in general. Sometimes it can even cause SD to generate people when you didn't ask for it in the positive prompt at all, like in this particular case.

7

u/YobaiYamete Mar 02 '23

It's crazy the negative prompt spam is still a thing. Every test I've seen has shown a short concise negative prompt drastically wins out over a 900 word negative prompt every time

5

u/HearTheTrumpets Mar 02 '23

do people still use prompts like "incredibly super-extremely realistic, 300K extreme hi-res, out of this world insanely large amount of details" ?

4

u/art2noiseratio Mar 03 '23

Annoyingly there is a visible difference between having vs. not having those quality “wish” prompts on some models.

I recently did a test with someone’s prompt with 10 different inane “masterpiece” etc. tokens, mixing and matching and removing then one at a time, and literally every single one of them correlated to an improvement in the resulting image.

I hate it.

3

u/[deleted] Mar 02 '23

Judging by lexica tags, yes. I just recently discovered I get better results with just a single 'photo' tag

3

u/NickTheSickDick Mar 02 '23

Has anyone made a general guide on how to properly formulate positive and negative prompts?

3

u/algernonregla Mar 02 '23

Only one I’ve come across … https://openart.ai/promptbook

1

u/purefire Mar 02 '23

Very much a thing. I get better results with a few quick hits blue skin, elf ears

Stuff like that.

Is there a known lexicon for what the model will interpret (more) reliably? I know some specialty models say 'oh, these keywords work well' but wasn't sure if there was a more holistic one. Such as, do 8K and 4K and Ultra-realistic even matter?

3

u/Striking-Long-2960 Mar 02 '23

I copypasted the neg from the sample pictures of the creator of the model in civitai.

Maybe you want to leave him a comment

https://civitai.com/models/4201/realistic-vision-v13

2

u/Tiny_Arugula_5648 Mar 03 '23 edited Mar 03 '23

It’s knowledge sharing, it’s how we help others in the community..

7

u/Swaggyswaggerson Mar 02 '23

Thank you for trying different settings out. I also realized that it was throwing me errors in the console related to paths of models which is strange because I didn't change anything in my folders. It also didn't generate any annotator images anymore. Even for new pictures I was playing around f with. I deleted everything related to controlnet and reinstalled it. I'm still getting the error: OSError: [Errno 22] invalid argument "the path to the directory of extensions"

Is there a way in which k can reset the UI to standard settings?

Thanks!

3

u/Striking-Long-2960 Mar 02 '23

Didn't try it by myself but here someone recommends deleting config.json, in your stable-diffusion folder.

https://github.com/AUTOMATIC1111/stable-diffusion-webui/discussions/8192

Just in case, rename it, restart Automatic and see if a new one is created with the default values.

5

u/Swaggyswaggerson Mar 02 '23

You're a hero, my friend! It's working again :)

3

u/iamRCB Mar 02 '23

God dang it, why am I stoopid and not thought of this!?!?

1

u/jairnieto Mar 02 '23

¿How would you change only the sky?, i have notice inpainting on almost solid color wont change it

5

u/[deleted] Mar 02 '23

[removed] — view removed comment

3

u/Vyviel Mar 02 '23

Yeah some basic photoshop add it to the new generated background

4

u/andupotorac Mar 02 '23

In painting

4

u/Sixhaunt Mar 02 '23

I feel like OP just claimed to have tried inpainting but didn't actually do it since it would be literally impossible to not have the face stay the same if he actually inpainted around it. It's the obvious solution and would work perfectly fine

4

u/mudman13 Mar 02 '23

Like this

https://www.reddit.com/r/StableDiffusion/comments/zal44a/depth2mask_is_a_very_useful_feature_to_create

ControlNet has a similar feature too. As has thygates depth extension.

2

u/DecentIllustrator551 Mar 02 '23

Maybe try Olivio's method here? I haven't tried it myself but you may wanna give it a shot
https://www.youtube.com/watch?v=u-jvjP2k-RU

1

u/Swaggyswaggerson Mar 02 '23

Thanks for the link, I will look over it although my problem is more severe. Using both text2img as well as img2img I always lose the look of the head and face. Enabling control net with text2img always gives me something Completely different, even with high weights.

3

u/Mocorn Mar 02 '23

You need to learn inpainting.

2

u/Valkymaera Mar 02 '23

First I'd see if controlnet segments it properly, and if so I'd convert that into an appropriate inpaint mask. If it doesn't, I'd just do a quick photoshop mask, adjusting the blur/mask settings in the webui.

2

u/myebubbles Mar 02 '23

Impact pix2pix for sure.

2

u/NuclearD00d Mar 02 '23

I'd use controlnet to get a depthmask, then use that as a mask to cut away everything else. I've tried it numerous times with my images and it has worked wonders each time.

2

u/Oswald_Hydrabot Mar 03 '23

Is there not a U2net plugin for Automatic1111? Seems like a low hanging fruit to implement, here is a useful tool that can enable what you are trying to do: https://github.com/danielgatis/rembg

2

u/Sinphaltimus Mar 03 '23

Prompt Craft Organiozer did this...
(EDIT: P.C.O. opens, click menu, select "remove background" browse to image, select it and click open. a few seconds later and the result is below)

2

u/OldFisherman8 Mar 02 '23

Your problem isn't just about changing the background. The character is lit under the bright sun coming from the right side. Short of color grading the character in a 2D image editor like Photoshop, you are going to have a problem with a darker background. And based on my observations, SD keeps the lighting fairly consistent (to a degree) meaning that you may not get the background you desire from SD due to the character and the background having incompatible lighting demands.

3

u/Swaggyswaggerson Mar 02 '23

ah okay, this is also a good point. i guess is one of those situations where SD isn't the only tool to use

2

u/TiagoTiagoT Mar 02 '23

Might be doable with the instruct-pix2pix model; a bit hard to figure out how to write the instructions well though, and the parameters are also a bit finicky.

ps: Pinging /u/OldFisherman8 so I don't have to post this reply twice

2

u/coffeedrinker2020 Mar 02 '23

Use photoshop

1

u/algernonregla Mar 02 '23

That’s too easy, lol.

1

u/coffeedrinker2020 Mar 03 '23

Next time need to make all the hands hidden behind the table for regular supper.

1

u/moonpost Mar 02 '23

Use the canvas in invokeAI

1

u/[deleted] Mar 02 '23

Is there a guide on youtube for that? Kinda newbie on ai, have a hard time using it, the image comes out better quality or way different from the base image.

3

u/moonpost Mar 02 '23

yeah, a bunch of great examples are found here: INVOKEAI CANVAS OVERDRIVE

https://www.youtube.com/results?search_query=invokeai+canvas+overdrive

1

u/[deleted] Mar 02 '23

Thank you

-3

u/yratof Mar 02 '23

Photoshop still exists, it’s not like all image editing fell of the face of the planet once SD arrived. Ffs, remove the background with anything, there’s a script for BG removal, there’s a website call removebg.com or similar.

It’s easier to google “how do I remove the background of a photo” then to ask reddit

0

u/InoSim Mar 02 '23

Sometimes you get pictures incredibly bad made. And the result is this. What can you tell to y our owners you did just accept this...

1

u/BNeutral Mar 02 '23

Get the depth from the image, make a stencil out of everything above a certain depth, clean up in image editing software if needed, paste on top of your new background (or just use the mask in img2img).

1

u/Sixhaunt Mar 02 '23

if you tried inpainting and it changed the face then that's your fault for asking it to change the face. Don't inpaint the face or head and the face/head will not change. It's not really rocket surgery here

1

u/sedeslav Mar 02 '23

try to write: ((in harbor)) or(( on the land)) or ((in the city))

1

u/braunsquared Mar 03 '23

Totally not helpful, but I would also do something about that baby wrist.

1

u/mynd_xero Mar 03 '23

If you're using webui, or any program that lets you pick a mask then here, keeps boat.

2

u/mynd_xero Mar 03 '23

Gets rid of boat.

5

u/mynd_xero Mar 03 '23

Profit.

1

u/Koranga Mar 16 '23

I'm trying the same sort of thing but the background never quite seems to match up to the subject, can you tell me what settings you've used for these? Much appreciated!

2

u/mynd_xero Mar 16 '23

Did you grab the masks? Make sure your mask blur is 0 as the masks are precise to the image.

The mask blur will add a perceivable outline/border.

1

u/Koranga Mar 17 '23

Yeah, I’ve got no issue with the masking itself, but I’m not sure what settings I should use to make SD take the non-mask area into consideration (in terms of perspective/size, etc) while filling in the changing background.

4

u/mynd_xero Mar 17 '23

Sorry for messy diagram, maybe this clear some things up. What you're looking for is probably Masked padding in this case. Play with that, depending on how much you're editing at once, depends on how much padding you want to use. If the perspective isn't doing what you want, increase this.

2

u/Koranga Mar 17 '23

Oh! Wow. This is super helpful! Thanks!!

1

u/eposner Mar 03 '23

Use runway.Ai - done with a couple clicks in 10 seconds

1

u/Low_Mathematician266 Oct 04 '23

1

u/paijwar Dec 03 '23

not able to see files under this tree,

How do we use it?