Machine Learning in Linux

Machine Learning in Linux: BackgroundRemover – remove backgrounds from images and video

In Operation

Let’s go through an example.

Here’s an image of an adorable ferret snoozing on a warm cozy blanket.

Sleeping ferret
Click image for full size

Let’s remove the background from the image. We define the input image with the -i flag and the output image with the -o flag.

$ backgroundremover -i "cute-ferret-is-sleeping.jpg" -o "cute-ferret-is-sleeping.png"

Here’s the generated image.

Sleeping ferret
Click image for full size

While the model’s output is good, there’s room for improvement.

Let’s turn on alpha matting with the flags -a and -ai 15.

$ backgroundremover -i "cute-ferret-is-sleeping.jpg" -a -ai 15 -o "cute-ferret-is-sleeping-alpha-matting.png"

Here’s the generated image with alpha matting.

Sleeping ferret
Click image for full size

The software isn’t limited to images. It can also remove backgrounds from videos with the ability to make a transparent mov file, overlay it over another video or image. There’s also the option to remove the background from a video and make a transparent GIF. There are various advanced options too such as the ability to change the video’s framerate.


BackgroundRemover is a very useful tool for removing backgrounds from images and videos. It can use three U2Net models: u2netp, u2net and u2net_human_seg.

The software uses the same AI model as another background remover, Rembg. We received that software in an earlier article.

When we first tried using alpha matting with BackgroundRemover, the command failed to work. This was because the code was using, a deprecated alias for the builtin int, in NumPy. We raised an issue on the project’s GitHub repository. The project’s developer suggested a minor code change, replacing to np.int64 in This fixed the issue. A pull request was made within a day of raising the issue!

Support: GitHub Code Repository
Developer: Johnathan Nader
License: MIT License

BackgroundRemover is written in Python. Learn Python with our recommended free books and free tutorials.

Artificial intelligence icon For other useful open source apps that use machine learning/deep learning, we’ve compiled this roundup.

Pages in this article:
Page 1 – Introduction and Installation
Page 2 – In Operation and Summary

Notify of

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Inline Feedbacks
View all comments