rembg のインストールと動作確認(画像の背景除去)(Python を使用)(Windows 上)
画像の背景除去.U2-Net を使用.
【関連する外部ページ】
GitHub のページ: https://github.com/danielgatis/rembg
U2-Net
【文献】
Xuebin Qin, Zichen Zhang, Chenyang Huang, Masood Dehghan, Osmar R. Zaiane and Martin Jagersand, U2-Net: Going Deeper with Nested U-Structure for Salient Object Detection, arXiv:2108.10257, 2021.
前準備
Python のインストールと必要なPythonライブラリのインストール(Windows上)
- Python のインストール
注:既にPython(バージョン3.12を推奨)がインストール済みの場合は,この手順は不要である.
winget(Windowsパッケージマネージャー)を使用してインストールを行う
- Windowsで,コマンドプロンプトを管理者権限で起動する(手順:Windowsキーまたはスタートメニュー,「cmd」と入力,右クリックメニューなどで「管理者として実行」を選択)
- winget(Windowsパッケージマネージャー)が利用可能か確認する:
winget --version
- Pythonのインストール(下のコマンドにより Python 3.12 がインストールされる).
reg add "HKLM\SYSTEM\CurrentControlSet\Control\FileSystem" /v LongPathsEnabled /t REG_DWORD /d 1 /f REM Python をシステム領域にインストール winget install --scope machine --id Python.Python.3.12 --id Python.Launcher -e --silent REM Python のパス set "INSTALL_PATH=C:\Program Files\Python312" echo %PATH% | find /i "%INSTALL_PATH%" >nul if errorlevel 1 setx PATH "%PATH%;%INSTALL_PATH%" /M >nul echo %PATH% | find /i "%INSTALL_PATH%\Scripts" >nul if errorlevel 1 setx PATH "%PATH%;%INSTALL_PATH%\Scripts" /M >nul
- 必要なPythonライブラリのインストール
【関連する外部ページ】
【サイト内の関連ページ】
動作確認
- Windows で,コマンドプロンプトを実行
- rembg のソースコード等のダウンロード
cd /d c:%HOMEPATH% rmdir /s /q rembg git clone https://github.com/danielgatis/rembg
- 動作確認
cd /d c:%HOMEPATH% cd rembg cd examples rembg i animal-1.jpg animal-1.result.jpg animal-1.result.jpg rembg i animal-2.jpg animal-2.result.jpg animal-2.result.jpg rembg i animal-3.jpg animal-3.result.jpg animal-3.result.jpg rembg i girl-1.jpg girl-1.result.jpg girl-1.result.jpg rembg i girl-2.jpg girl-2.result.jpg girl-2.result.jpg rembg i girl-3.jpg girl-3.result.jpg girl-3.result.jpg