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上)

  1. Python 3.12 のインストール

    インストール済みの場合は実行不要。

    管理者権限でコマンドプロンプトを起動(手順:Windowsキーまたはスタートメニュー > cmd と入力 > 右クリック > 「管理者として実行」)し、以下を実行する。管理者権限は、wingetの--scope machineオプションでシステム全体にソフトウェアをインストールするために必要である。

    REM Python をシステム領域にインストール
    winget install --scope machine --id Python.Python.3.12 -e --silent
    REM Python のパス設定
    set "PYTHON_PATH=C:\Program Files\Python312"
    set "PYTHON_SCRIPTS_PATH=C:\Program Files\Python312\Scripts"
    echo "%PATH%" | find /i "%PYTHON_PATH%" >nul
    if errorlevel 1 setx PATH "%PATH%;%PYTHON_PATH%" /M >nul
    echo "%PATH%" | find /i "%PYTHON_SCRIPTS_PATH%" >nul
    if errorlevel 1 setx PATH "%PATH%;%PYTHON_SCRIPTS_PATH%" /M >nul

    関連する外部ページ

    Python の公式ページ: https://www.python.org/

  2. AI エディタ Windsurf のインストール

    Pythonプログラムの編集・実行には、AI エディタの利用を推奨する。ここでは,Windsurfのインストールを説明する。

    管理者権限でコマンドプロンプトを起動(手順:Windowsキーまたはスタートメニュー > cmd と入力 > 右クリック > 「管理者として実行」)し、以下を実行して、Windsurfをシステム全体にインストールする。管理者権限は、wingetの--scope machineオプションでシステム全体にソフトウェアをインストールするために必要となる。

    winget install --scope machine Codeium.Windsurf -e --silent

    関連する外部ページ

    Windsurf の公式ページ: https://windsurf.com/

  3. 必要なPythonライブラリのインストール
    1. Windowsで,管理者権限コマンドプロンプトを起動(手順:Windowsキーまたはスタートメニュー > cmd と入力 > 右クリック > 「管理者として実行」)。
    2. 以下のコマンドを実行し,必要なライブラリをインストールする.
      pip install -U rembg
      

【関連する外部ページ】

【サイト内の関連ページ】

動作確認

  1. Windows で,コマンドプロンプトを実行
  2. rembg のソースコード等のダウンロード
    cd /d c:%HOMEPATH%
    rmdir /s /q rembg
    git clone https://github.com/danielgatis/rembg
    
  3. 動作確認
    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