Software to automatically remove background from images?

18,112

Solution 1

The imagemagick package includes a convert command.

Example commands:

convert image1.jpg -fuzz 20%% -transparent White image2.png
convert image1.png -threshold 10%% image2.png

Both are simple versions of removing a background and might make all other none-background white in the image transparent (the fuzzy/threshold options can adjust that).

But Imagemagick has examples on removing backgrounds using masks.

What works best depends on the original. JPG tend to be fuzzy (what looks like the same color often are slightly different colors) so they will have mixed results.

Solution 2

pip install --upgrade pip
pip install backgroundremover

Then simply

backgroundremover -i "/path/to/file.jpg" -o "out.png"

and if you want for video

backgroundremover -i "/path/to/video.mp4" -tg -o "output.gif"

source: https://github.com/nadermx/backgroundremover

Example before and after:

Example photo

Share:
18,112

Related videos on Youtube

Ben Andersen
Author by

Ben Andersen

Updated on September 18, 2022

Comments

  • Ben Andersen
    Ben Andersen over 1 year

    Are there any Ubuntu alternatives to photoscissors, which makes it easy to remove the background of an image?

    I'm currently using GIMP in different ways to do the same but for some images it takes a long time.

  • kyriakosSt
    kyriakosSt over 2 years
    Comment to people: This is a machine-learning-based tool that seems very cool for real photographs, but I think it leaves small artifacts in artificial images like some with the logo-white-background combination I tried.
  • Admin
    Admin almost 2 years
    This only works if the background is white, right?
  • Admin
    Admin almost 2 years
    apparently only works for flat backgrounds
  • Admin
    Admin almost 2 years
    This is a non answer