You are not logged in.
rembg
https://github.com/danielgatis/rembg
From time to time, I need to ‘cut out’ images for private use.
Every Linux user knows this and thinks of GIMP. But working with it isn't everyone's cup of tea.
Although I've been using Linux for many years, I'm just not skilled at using GIMP.
The simple Python tool rembg, based on CLI (command line), offers a cool workaround.
Under Debian, we first need to install the pipx package:
sudo apt update && sudo apt install pipxHere, under carbon-trixi, a small number of python3 dependencies are also installed.
Next, we execute the command
pipx ensurepath and reboot the system so that the PATH is recognized.
After rebooting, rembg CLI support is required
pipx install “rembg[cpu,cli]” # for CPU
pipx install “rembg[gpu,cli]” # for NVIDIA/CUDA GPUSince I don't have NVIDIA, for me it's
pipx install “rembg[cpu,cli]”This completes the installation.
####################################
rembg has the following commands
rembg --help
Usage: rembg [OPTIONS] COMMAND [ARGS]...
Options:
--version Show the version and exit.
--help Show this message and exit.
Commands:
b for a byte stream as input
d download models
i for a file as input
p for a folder as input
s for a http serverWe navigate to the directory containing the image we want to cut out from the background and open the terminal:
unklar@carbon2:~/Pictures$ rembg i 20.jpg 20free.jpg
Downloading data from 'https://github.com/danielgatis/rembg/releases/download/v0.0.0/u2net.onnx' to file '/home/unklar/.u2net/u2net.onnx'.
100%|████████████████████████████████████████| 176M/176M [00:00<00:00, 500GB/s]After reloading this library (once), we see that the image without background
20free.jpg has been added to our original image 20.jpg.
Last edited by unklar (2026-01-05 12:18:31)
Offline
Very impressive! ![]()
The first thing I thought was - if you're not going to wrangle with Gimp, then this is a job for AI.
Then, first impression was OK, rembg seems a very cool CLI tool...
...but reading a bit more, after all it is using AI. But a locally installed AI, it looks like.
And your instructions look very easy to follow. Thank you!
...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )
Offline
@unklar, Thanks for sharing this. p.s. I'm assuming the output needs to be png or some other format that supports transparency (and not jpg)?
Offline
^@johnraff,
thank you for the kind words.
@bronto,
that's correct, although .jpg also works here. ![]()
Offline
A few more tips on Python software packages.
Let's say we were too quick and just installed rembg like this:
pipx install rembgThen the --force function will help us fix that:
pipx install --force “rembg[cpu,cli]”----
pipx listor
pipx list --short tells us which Python packages we have installed.
On Debian, it is recommended to install python3-pip to simplify package management.
sudo apt install python3-pipand then make the entry below in our ~/.bashrc
PATH=“/home/unklar/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games”takes care of the rest. unklar = USERNAME
After rebooting, all commands are available to us. We can upgrade, pin, reinstall, uninstall, etc.
Please refer to the pipx manual pages
man pipxOffline
^so pipx is a user-level version of pip, that doesn't need sudo?
...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )
Offline
^so pipx is a user-level version of pip, that doesn't need sudo?
YES. ![]()
pipx allows you to...
* Run the latest version of a CLI application from a package
in a temporary virtual environment,
leaving your system untouched after it finishes.
* Install packages to isolated virtual environments,
while globally exposing their CLI applications
so you can run them from anywhere.
* Easily list, upgrade, and uninstall packages
that were installed with pipx.pipx runs with regular user permissions, never calling "sudo pip install".
https://packages.debian.org/trixie/pipx
Last edited by unklar (Yesterday 10:36:30)
Offline
Excellent! I've never liked Gimp and stay away from it as much as possible.
I wish there was a Linux version of Paint Shop Pro. Someone once gave me a copy, but it was in floppy disk format (for Windows 3.x) and I can't install it under Wine.
Mtpaint is quite useful for basic photoediting tasks.
Last edited by Colonel Panic (Yesterday 17:59:23)
Offline
I verified my pipx install is working but trying to install rembg according to instructions fails:
Unable to parse package spec: “rembg[cpu,cli]”What's missing?
Real Men Use Linux
Offline
Not related to DeepDayze's question, but this is interesting:
Comparison to Other Tools
...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )
Offline
I verified my pipx install is working but trying to install rembg according to instructions fails:
Unable to parse package spec: “rembg[cpu,cli]”What's missing?
You forgot PATH.
You didn't reboot the system.
What was the command before?
Offline
Not related to DeepDayze's question, but this is interesting:
Comparison to Other Tools
Thanks for this find, great thing! ![]()
On carbon/debian:
LANG=C apt policy pip poetry pipenv venv pyenv pipsi brew npx pip-run fades pae pactivate
pip:
Installed: (none)
Candidate: (none)
Version table:
pipenv:
Installed: (none)
Candidate: 2024.0.1+ds-3
Version table:
2024.0.1+ds-3 500
500 https://deb.debian.org/debian trixie/main amd64 Packages
pyenv:
Installed: (none)
Candidate: 2.5.4-1
Version table:
2.5.4-1 500
500 https://deb.debian.org/debian trixie/main amd64 Packages
pipsi:
Installed: (none)
Candidate: 0.9-1.1
Version table:
0.9-1.1 500
500 https://deb.debian.org/debian trixie/main amd64 Packages
fades:
Installed: (none)
Candidate: 9.0.2-2
Version table:
9.0.2-2 500
500 https://deb.debian.org/debian trixie/main amd64 Packages
Notice: Unable to locate package poetry
Notice: Unable to locate package venv
Notice: Unable to locate package brew
Notice: Unable to locate package npx
Notice: Unable to locate package pip-run
Notice: Unable to locate package pae
Notice: Unable to locate package pactivateOffline
Actually as a person that spend some (not a lot) of time removing the backgrounds with photoshop mostly, it would be interesting to compare this auto-magical removers via some test images, like
https://unsplash.com/photos/black-and-w … KXKBY-C-Dk
(both rembg and 'photoshop ai bg removal' does pretty crappy job on it)
Offline
DeepDayze wrote:I verified my pipx install is working but trying to install rembg according to instructions fails:
Unable to parse package spec: “rembg[cpu,cli]”What's missing?
You forgot PATH.
You didn't reboot the system.What was the command before?
I already ran the commands for setting the PATH and rebooted. Seems the pipx path was added to the end so should it be moved to beginning?
EDIT: Aha, it was the quotation marks in the command Unklar posted. I typed the double quotes instead around the program name and it now worked. Got rembg installed now.
Last edited by DeepDayze (Today 18:35:46)
Real Men Use Linux
Offline
^^@DD, good that you found that. ![]()
Offline
Actually as a person that spend some (not a lot) of time removing the backgrounds with photoshop mostly, it would be interesting to compare this auto-magical removers via some test images, like
https://unsplash.com/photos/black-and-w … KXKBY-C-Dk
(both rembg and 'photoshop ai bg removal' does pretty crappy job on it)
^I don't think you can compare rembg with Gimp or others. It is for home use only. ![]()
Offline
^^@DD, good that you found that.
Took me a bit to figure that out ![]()
Real Men Use Linux
Offline