It is currently Thu Apr 25, 2024 9:05 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 50 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: AI Remove image background(use rembg)
PostPosted: Mon Jul 25, 2022 7:49 am  (#1) 
Offline
GimpChat Member

Joined: Apr 25, 2011
Posts: 78
Location: Taiwan
First you need to successful install rembg

Download the RemoveBG.py, open with text editor, find
aiExe = "C:\\Users\\USER\\AppData\\Local\\Programs\\Python\\Python39\\Scripts\\rembg.exe"
Replace with your own rembg path

Image

Python-fu->AI移除影像背景(AI Remove background) ...
Image

Image

for linux flatpak gimp
RemoveBG-Flatpak.zip
find
aiExe = "/home/jamesh/.local/bin/rembg"
Replace with your own rembg path

then run gimp like below
flatpak run --socket=session-bus org.gimp.GIMP

Test successful on ubuntu

for linux AppImage gimp
RemoveBG-AppImage.zip
find
aiExe = "/home/jamesh/.local/bin/rembg"
Replace with your own rembg path

Test successful on ubuntu 22.04


Attachments:
RemoveBG.zip [1.45 KiB]
Downloaded 1316 times


Last edited by JamesH on Tue Jan 17, 2023 3:45 am, edited 3 times in total.
Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Mon Jul 25, 2022 10:33 am  (#2) 
Offline
GimpChat Member
User avatar

Joined: Oct 31, 2020
Posts: 1393
I am on Linux and cannot get this working. The path to REMBG I linked was
/home/contrast/.local/bin/rembg


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Mon Jul 25, 2022 10:50 am  (#3) 
Offline
GimpChat Member
User avatar

Joined: Oct 31, 2020
Posts: 1393
If anyone gets this working on Linux I would like to know what they did and what version of REMBG they are using.


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Mon Jul 25, 2022 12:31 pm  (#4) 
Offline
GimpChat Member
User avatar

Joined: Sep 27, 2016
Posts: 345
Location: Germany, BW
I have my rembg installed using Anaconda. So I have to figure out how to start that env from within the python script first.
I use rembg standalone .. without GIMP.

_________________
Regards
nelo

(Gimp 2.10 on Linux Mint MATE 20.1)


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Mon Jul 25, 2022 7:25 pm  (#5) 
Offline
GimpChat Member
User avatar

Joined: Nov 04, 2015
Posts: 1333
I used it on video clips converted to PNGs using ffmpeg. It is by no means perfect. It leaves cloudy areas on anything but clear, distinct images.

The drive I had it on died. I found it works with both anaconda python and the installed python 3.9. Ubuntu 22.04 has updated to python3.10.
Here are my notes for the installed python. (I think it does work on python 3.10)

sudo apt install python3-pip
pip install rembg
python --version =3.10.4
sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt update
sudo apt install python3.9 -y
python3.9 --version =3.9.12

add REMBG to path.
You also need to download 'models' that the AI uses to remove backgrounds.
one of them is here.
Copy the custom-model.pth file to ~/.u2net (thats in your home directory)


I made simple scripts to process folders of PNGs.

#!/bin/bash
mkdir ./done
rembg -m u2net_human_seg -p ./ ./done/


https://github.com/danielgatis/rembg
Nelo's instructions for anaconda are here:
https://www.gimp-forum.net/Thread-Remov ... G#pid22354


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Mon Jul 25, 2022 8:25 pm  (#6) 
Offline
GimpChat Member
User avatar

Joined: Oct 31, 2020
Posts: 1393
What do I put here to get it working on Linux?

aiExe = "C:\\Users\\USER\\AppData\\Local\\Programs\\Python\\Python39\\Scripts\\rembg.exe"


I tried REMBG, /home/contrast/.local/bin/rembg and /home/contrast/.local/bin/rembg i and none of them working.


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Mon Jul 25, 2022 8:55 pm  (#7) 
Offline
GimpChat Member

Joined: Apr 25, 2011
Posts: 78
Location: Taiwan
i tested on my android phone(termux linux) with backgroundremover
it does not need full path, maybe you can try it with
aiExe = "rembg"


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Mon Jul 25, 2022 9:22 pm  (#8) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
This is for Windows but you may try it in other OS. This plugin really work.
I found this plugin a few months ago at a website call "romove.bg" and sent me to download a GIMP plugin from;
https://github.com/manu12121999/RemoveBG-GIMP
I downloaded it and installed it, then I signed (you have to sign up) and you get a key code, to make the plugin work. Once you get the "key code", save it in your desktop with notepad. As long as you have this key, you can use the plugin and you can erase the background within the GIMP program.



The photo is from https://www.krugerpark.co.za/africa_lion.html

ImageImage

_________________
https://www.deviantart.com/pocholo17
Image


Last edited by Pocholo on Mon Aug 01, 2022 12:12 am, edited 2 times in total.

Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Tue Jul 26, 2022 12:41 am  (#9) 
Offline
GimpChat Member
User avatar

Joined: Mar 01, 2014
Posts: 12658
Location: Spain, Aragón
:clap :clap :clap


Attachments:
It works fantastic.jpg
It works fantastic.jpg [ 115.55 KiB | Viewed 15083 times ]

_________________
Image

Gimp 2.10.30(samj) portable _ OS Windows 10 Home_ 64bits
Don’t be afraid to start over. It’s a new chance to rebuild what you want.
Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Tue Jul 26, 2022 12:51 am  (#10) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
Thx for sharing. :)

And,,,,, thank you manu12121999!

Attachment:
Star-for-manu12121999-2022-07-26_014500.jpg
Star-for-manu12121999-2022-07-26_014500.jpg [ 227.04 KiB | Viewed 15079 times ]


:hi5

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Tue Jul 26, 2022 1:11 am  (#11) 
Offline
GimpChat Member
User avatar

Joined: Jan 06, 2020
Posts: 338
Location: The Netherlands
I've been waiting a long time for that. Great, thank you!


Attachments:
gimp easy.png
gimp easy.png [ 24.64 KiB | Viewed 7373 times ]


Last edited by Jappaloe63 on Tue Jul 26, 2022 4:20 am, edited 1 time in total.
Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Tue Jul 26, 2022 1:13 am  (#12) 
Offline
GimpChat Member
User avatar

Joined: May 16, 2010
Posts: 14709
Location: USA
You can call me impressed. Any time you need to remove white bg from very white hair it's darn near impossible.

Before rembg

Attachment:
before-rembg-2022-07-26_020452.jpg
before-rembg-2022-07-26_020452.jpg [ 66.13 KiB | Viewed 7390 times ]


After rembg

Attachment:
After-rembg-2022-07-26_020552.jpg
After-rembg-2022-07-26_020552.jpg [ 75.61 KiB | Viewed 7390 times ]


How the heck does it know what's bg or fg? It just runs and works like magic :)
And i love the fact that it's non destructive utilizing a mask. :tyspin :gimp

_________________
Image
Edmund Burke nailed it when he said, "The only thing necessary for the triumph of evil is for good men to do nothing."


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Tue Jul 26, 2022 1:57 am  (#13) 
Offline
Global Moderator
User avatar

Joined: Oct 06, 2010
Posts: 4045
Peter Falkingham said it best.

https://peterfalkingham.com/2021/07/19/ ... d-remover/

I need to buy a new laptop and convert this current one to Linux so I can get some serious playtime in.

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Tue Jul 26, 2022 7:40 am  (#14) 
Offline
GimpChat Member
User avatar

Joined: Oct 31, 2020
Posts: 1393
My main problem has to do with the fact that I use a Flatpak Gimp. Does anyone know how to edit the script and change it to support flatpak gimp's directory?


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Tue Jul 26, 2022 11:29 am  (#15) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2246
Location: Poland
JamesH he wrote shortly: First you need to successful install rembg.
For Windows, this is not too complicated, but with a few surprises.

I will share my experience of installing rembg.exe in Windows 10_64bit.
I tried to compile in msys64 - unfortunately without success (lots of bugs to analyze - although the use of msys64 seems not to be considered eg.: AttributeError: 'MSVCCompiler').

So I installed python-3.9.7-amd64.exe and then:
C: \ Python39> python.exe -m pip install rembg
Successfully installed:
PySocks-1.7.1 PyWavelets-1.3.0 aiohttp-3.8.1 aiosignal-1.2.0 anyio-3.6.1 asgiref-3.5.2 async-timeout-4.0.2 asyncer-0.0.1 attrs-21.4.0 beautifulsoup4-4.11.1 certifi-2022.6.15 charset-normalizer-2.1.0 click-8.0.3 colorama-0.4.5 fastapi-0.72.0 filelock-3.7.1 filetype-1.0.9 flatbuffers-2.0 frozenlist-1.3.0 gdown-4.4.0 h11-0.13.0 idna-3.3 imageio-2.20.0 llvmlite-0.38.1 multidict-6.0.2 networkx-2.8.5 numba-0.55.2 numpy-1.22.3 onnxruntime-1.10.0 packaging-21.3 pillow-9.0.1 protobuf-4.21.3 pydantic-1.9.1 pymatting-1.1.5 pyparsing-3.0.9 python-multipart-0.0.5 rembg-2.0.21 requests-2.28.1 scikit-image-0.19.1 scipy-1.8.0 six-1.16.0 sniffio-1.2.0 soupsieve-2.3.2.post1 starlette-0.17.1 tifffile-2022.5.4 tqdm-4.62.3 typing-extensions-4.3.0 urllib3-1.26.11 uvicorn-0.17.0 watchdog-2.1.7 yarl-1.7.2

After correcting the path in RemoveBG.py, I ran the plugin.
Another surprise:

Image

So I installed:

Image

I restarted it and surprise again:

Image

It only uses the model u2net.onnx (A pre-trained model for general use cases) - I don't know how to change it, for example: u2net_human_seg.onnx (A pre-trained model for human segmentation).
The result leaves little illusion, so I agree with Tas_mania opinion: It is by no means perfect.
However, there is a mask for corrections - so thanks to JamesH for thinking about it.
Also, the installation method is probably not encouraging for the majority of users.


Attachments:
RemBG.gif
RemBG.gif [ 312.77 KiB | Viewed 7343 times ]

_________________
Image

Slava
Ukraini!
Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Tue Jul 26, 2022 1:30 pm  (#16) 
Offline
GimpChat Member
User avatar

Joined: Sep 27, 2016
Posts: 345
Location: Germany, BW
MareroQ wrote:
It only uses the model u2net.onnx (A pre-trained model for general use cases) - I don't know how to change it, for example: u2net_human_seg.onnx (A pre-trained model for human segmentation).


I guess it could be something like this (found somewhere on that site)

Add a custom model
Copy the custom-model.pth file to ~/.u2net and run:
rembg -m custom-model > output.png


Probably replace by the name of the model.
So:
rembg -m u2net_human_seg > output.png

Maybe you have to download the model in question first and place it in that u2net folder.

_________________
Regards
nelo

(Gimp 2.10 on Linux Mint MATE 20.1)


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Wed Jul 27, 2022 6:35 am  (#17) 
Offline
GimpChat Member

Joined: Oct 29, 2012
Posts: 33
Location: Brisbane, Australia
Thanks Pocholo for the Windows version. It is amazing.


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Sat Jul 30, 2022 2:15 am  (#18) 
Offline
GimpChat Member
User avatar

Joined: Nov 04, 2015
Posts: 1333
Image


I came across DIS (Dichotomous Image Segmentation). It could be a developed version of REMBG. I may try it because this team also developed the U2-Net models used by REMBG.

Training neural networks appears to be a rapidly developing industry ATM. The gif above is a Gimp-reduced one from their project page.


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Sat Jul 30, 2022 5:53 am  (#19) 
Offline
GimpChat Member

Joined: May 12, 2015
Posts: 4694
You did all of that with Gimp? Really nice!


Top
 Post subject: Re: AI Remove image background(use rembg)
PostPosted: Sat Jul 30, 2022 9:45 pm  (#20) 
Offline
GimpChat Member

Joined: Jul 28, 2018
Posts: 1196
wirra wrote:
Thanks Pocholo for the Windows version. It is amazing.

You're welcome, wirra! It's so much simpler the one I posted for simple Windows users.

_________________
https://www.deviantart.com/pocholo17
Image


Top
Post new topic Reply to topic  [ 50 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) REMBG - an open source offline usable background removal AI

12

No new posts Attachment(s) Use of Fuzzy Select tool to remove white background from black text

2

No new posts Attachment(s) Remove Stain from Image

5

No new posts Attachment(s) Remove white background but keep white inner

6

No new posts How is the background removed from this image?

2



* Login  



Powered by phpBB3 © phpBB Group