So often I encountered the problem that I need the background of an image removed. Be it for a presentation, paper or anything else. The usual options I encountered were:
- Painstakingly tracing the outline by hand in Gimp
- Use an online tool and either deal with bad download resolution or pay a download fee
- Use ChatGPT to do this, then realise that it is actually not the original image, but a weird mixture of the original and AI slop
- Probably you could also pay for Photoshop, but not me, I’m a bargain hunter!
So, how can it be done? – Using AI, of course, we nowadays throw AI at everything.
But in this case, it is not typical LLM AI, but a pretrained network that we then run locally through the Rembg CLI tool!
Follow these steps to use it (I tested it on Ubuntu 24.04, also make sure you have Python installed):
- Open a terminal (any1 not knowing what this is, you are in tech dept…), preferably in your image folder
- (Optional) create a virtual Python environment using “python -m venv .venv” and activate it with “source .venv/bin/activate“
- Install the needed dependencies with “pip install onnxruntime filetype watchdog aiohttp gradio asyncer click “. Alternatively, if you have an NVIDIA GPU available, you can use onnxruntime-gpu instead of onnxruntime for GPU acceleration
- Install Rembg using “pip install rembg“
- Then you can simply convert the images with “rembg i <name_of_input_image> <name_of_output_image>“. E.g. “rembg i img1.jpg img_no_bg1.jpg“
As an example, here is a result I got with the original image in the left, the dreamed-up version of ChatGPT in the middle (just because I find it amusing) and the rmbg result on the right:



So as you can see, the script works quite well. And while the ChatGPT version looks good from afar, if you zoom in you can tell that a diffusion model was at work.
So, that’s it for this short tutorial. Have fun removing backgrounds!
Goodbye and thanks for the fish!