八個優(yōu)秀的開源圖片背景移除程序
圖像背景移除程序通過自動分割圖像中的主體和背景并刪除背景。這個過程涉及利用機(jī)器學(xué)習(xí)算法技術(shù)來檢測前景和背景。
刪除圖片背景經(jīng)常被用于:
- 增強(qiáng)視覺效果,讓觀眾將注意力集中在主體內(nèi)容上。
- 創(chuàng)建專業(yè)圖形:在平面設(shè)計、產(chǎn)品攝影和電子商務(wù)等場景,可以創(chuàng)建具有透明背景的專業(yè)外觀圖像。這允許將對象無縫集成到不同的背景中。
- 優(yōu)化網(wǎng)頁設(shè)計:網(wǎng)頁設(shè)計師經(jīng)常需要刪除圖片背景來創(chuàng)建具有重疊視覺效果的元素。
- 創(chuàng)建營銷材料:在創(chuàng)建營銷材料(如小冊子、橫幅和廣告)的過程中,常常需要移除圖片背景,以便于將圖片的主體放置在各種背景環(huán)境中,以達(dá)到視覺效果滿足品牌定位。
- 改善產(chǎn)品攝影:電子商務(wù)平臺的產(chǎn)品展示圖片往往需要去除干擾并保持統(tǒng)一的背景,來實(shí)現(xiàn)一致的產(chǎn)品展示效果。
下面是一些開源的圖片背景移除開源程序。
1.Rembg
源碼:https://github.com/danielgatis/rembg
Rembg是一個可以移除圖片背景的Python開源工具。Rembg還可以用作Python庫,也可以支持GPU,運(yùn)行起來更加高效。要安裝它,請確保您的系統(tǒng)中安裝了Python,然后運(yùn)行:
# CPU Support
pip install rembg # for library
pip install rembg[cli] # for library + cli
# GPU Support
pip install rembg[gpu] # for library
pip install rembg[gpu,cli] # for library + cli
使用方式:
# 網(wǎng)絡(luò)圖片去除背景
curl -s http://input.png | rembg i > output.png
# 本地圖片去除背景
rembg i path/to/input.png path/to/output.png
2.BackgroundRemover
源碼:https://github.com/nadermx/backgroundremover
官網(wǎng):https://www.backgroundremoverai.com/
BackgroundRemover是個能夠有效地消除圖像或者視頻背景的命令行工具。這個工具要求安裝python >= 3.6、torch和torchvision穩(wěn)定版本,以及ffmpeg 4.4+。
安裝backgroundremover:
pip install backgroundremover
移除圖片背景:
backgroundremover -i "/path/to/image.jpeg" -o "output.png"
移除視頻背景:
backgroundremover -i "/path/to/video.mp4" -tv -o "output.mov"
移除視頻背景并轉(zhuǎn)GIF:
backgroundremover -i "/path/to/video.mp4" -tg -o "output.gif"
還有許多帶參數(shù)的用法,有需要不防參考它的開源網(wǎng)站。
3.Imgly
源碼:https://github.com/imgly/background-removal-js
這是一個JavaScript腳本,可以直接在瀏覽器中輕松地從圖像中刪除背景,而不會產(chǎn)生任何額外的成本或隱私問題。
4.Image-Editor
源碼:https://github.com/darshitjain87/Image-Editor
Image-Editor是一個基于AI的照片編輯網(wǎng)站,提供了強(qiáng)大的圖片編輯功能,如:背景更改、顏色調(diào)整、裁剪、圖像銳化等。
它基于Python的cv2庫的機(jī)器視覺算法實(shí)現(xiàn)圖像處理,并利用Mediapipe的selfie_segmentation模型實(shí)現(xiàn)在視頻流中的實(shí)時去除背景。
5.CarveKit
源碼:https://github.com/OPHoperHPO/image-background-remove-tool
CarveKit是一個使用神經(jīng)網(wǎng)絡(luò)去除高質(zhì)量圖像中背景的自動化框架。
功能特征:
- 高質(zhì)量
- 批處理
- 支持NVIDIA CUDA和CPU處理
- FP16推理:快速推理,內(nèi)存使用率低
- 100%兼容remove.bg的API
- 支持移除頭發(fā)中的背景
- 可以輕松與其他代碼集成
安裝CPU版本:
pip install carvekit --extra-index-url https://download.pytorch.org/whl/cpu
安裝GPU版本:
pip install carvekit --extra-index-url https://download.pytorch.org/whl/cu113
6.django_bgRemoverML
源碼:https://github.com/FarjaalAhmad/django_bgRemoverML
這是一個集成Django的機(jī)器學(xué)習(xí)項目,用于從圖像中移除背景。Linux安裝過程如下:
git clone https://github.com/FarjaalAhmad/django_bgRemoverML
cd django_bgRemoverML
python3 -m pip install -r requirements.txt
bash setup.sh
python3 manage.py migrate
python3 manage.py runserver
通過向http://localhost:8000/upload發(fā)送POST請求,參數(shù)為:image=[BASE64]。
7.Transparent Background
源碼:https://github.com/plemeri/transparent-background
這是一個由InSPyReNet(ACCV 2022)提供并支持的圖片背景刪除工具??梢暂p松地從圖像、視頻和其他視覺內(nèi)容中刪除背景。
8.BG Remover
源碼:https://github.com/developersharif/bgremover-app
下載地址:https://sourceforge.net/projects/bgremover/
官網(wǎng):https://bgremover.realbrain.cc/
這是一個離線的圖像背景刪除桌面應(yīng)用程序。它利用最新的機(jī)器學(xué)習(xí)算法在幾秒鐘內(nèi)提供準(zhǔn)確的結(jié)果。只需拖放圖像即可輕松編輯圖像,一鍵去除背景。此外,應(yīng)用程序還包括基本的編輯功能,例如更改圖像背景和顏色。