Remove or replace the background instantly

There are two tutorials on this page – background removal and background replacement.

Remove Background Tutorial

Both use the /bg command. If you reply to any image in Telegram with /bg, the background will be removed and a mask will be created.


The tool is designed for realistic photographs by default, but you can also use it for illustrated works with these parameters:


  • /format:png – Download a true transparent PNG.  It otherwise defaults to a high-res nearly uncompressed JPG with a black background.
  • /color – you can recolor the background to any color, by supplying a HEX value with or without the pound sign. It is not case sensitive, either. Example: /color:FFFFFF will give you a white background. And here’s a handy color picker.
  • /anime – improves masks and edges quality for any kind of illustrated works, by better detection of illustrated subjects in the foreground
  • /masks – this returns only the masks, and not the image. The average user probably doesn’t need this, but the power user will surely ask, so here you go!

Try it out

  1. First render a photo, or upload the example above to follow along.
  2. Next, reply to that photo with /bg as shown below
  3. Then type: /bg /anime /color:FF4433 

Let’s say I wanted yellow instead, so I just change the color to FFFF00



Replace Background Tutorial

You’ll need two images for this tutorial, a foreground object and a background.

Step 1. Upload a background, or render one

The background resolution should be the same as the foreground photo, or larger. You can use the /facelift command to resize them.

Steal this background idea:

/render #sdxlreal HDR realistic photograph, low camera angle, a mystical surreal tropical paradise, glistening water, (((bokeh))) /size:1280x960 /images:2 <realvis3-xl>

Step 2: Save your background as a controlnet preset


If you’re uploading an image as the background, saving it as a ControlNet preset turns it into an addressable image with a name, as shown below:

Optional: If you’re using a rendered image as a background and don’t want to bother with ControlNet presets, copy the photo ID as shown below. That photo ID works the same as the ControlNet saved name.

Step 3. Create or upload the foreground image

You don’t need to remove the background, we can do both in one step. Just upload foreground subject, or render one.

We’ve rendered a silly men’s cologne for my foreground object. Let’s replace the skyline with the tropical paradise.

/render #sdxlreal HDR realistic close-up macro photograph of a men's cologne ((crystal flask)) that has the words "MUSKY FELLLOW" written on the flask /size:1280x960 /images:2 <realvis3-xl> /vass <bettertext-xl>

Step 4. Reply to the foreground image with the replace command

I named my background “tropical-paradise” in step 2, so I’ll repeat it here:

/bg /replace:tropical-paradise

Or using the Photo ID method from Step 2:

/bg /replace:Izg4D5d

Tweaking the results

You can control the feathering effect by adding the /blur parameter.

/bg /replace:tropical-paradise /blur:10
  • Blur has a default value of 10
  • The max blur value is 255
  • Use whole numbers, no decimals.
  • Blur 0 is the lowest value

Background Replace works best when the whole subject is in view, meaning that parts of the body or object aren’t obstructed by another object.  This will prevent the image from floating or creating an unrealistic background wrap.

If the object isn’t exactly where you’d like it placed in the image, correct it with the outpaint command.

Fix Mismatched Lighting

Unless you’re very careful with controlling the light sources of both images, the super imposed image’s lights and reflections will make no sense. This is especially true for objects like bottles of fake cologne, like our example, where the reflections of the sky lounge bottle and jungle don’t match at all.

You can fix this by reprompting the image with the /remix command, so it all gels together better.


Try /more or /remix on results

A second round of post-processing can correct shadows, lights, and even typos! (bottom right).  Watch this video to learn how

Multiple character background removal

It seems to choose the characters that are most well lit and whose faces are most clear. In Telegram, you can use the built-in mobile pen tool, or the inpaint tool to prep the image first before using /bg

Some lighting conditions and cluttered backgrounds may also result in a partial background removal. Prompting for “bokeh background” before rendering is the easiest way to get around this, as it will intelligently remove anything blurred in one shot.

Worst case, you can always inpaint the background or tiny details away.



How to fix wrong scale

Remember to prep the resolution for each image using the /facelift command or using /outpaint for panning and relative position of the object. In this bad outcome, my Temple Background was much smaller than my red high heel shoes


Alternative Mask Uploading Technique

Reply to the mask with /showprompt to get the image code used in inpainting (or pick it from the inpainting recent masks list) – use /maskinvert to paint the background instead of foreground

What can I do with the mask?

To prompt only the background! It can’t be done in one step though. First reply to the mask with /showprompt to get the image code us for inpainting, or pick it from the inpainting recent masks. Add /maskinvert to the background instead of the foreground when making a render.

The mask is downloaded automatically when removing the background. You can upload this to Inpaint to prompt your own background into the picture.


Galaxy Smartphone users: If your uploaded photo wasn’t recognized, try another way. Some Android smartphones provide shortcut tray apps for quick image uploading, and that seems to confuse Telegram into thinking that your photo is an attachment. Instead, use your File Manager and go all the way to the photo directory to upload the file instead. Turn on “use compression”.

Back to Tutorials