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 のインストール

    注:既にPython(バージョン3.12を推奨)がインストール済みの場合は,この手順は不要である.

    winget(Windowsパッケージマネージャー)を使用してインストールを行う

    1. Windowsで,コマンドプロンプト管理者権限で起動する(例:Windowsキーを押し,「cmd」と入力し,「管理者として実行」を選択)
    2. winget(Windowsパッケージマネージャー)が利用可能か確認する:
      winget --version
      
    3. Pythonのインストール(下のコマンドにより Python 3.12 がインストールされる).
      winget install --scope machine Python.Launcher
      winget install --scope machine Python.Python.3.12
      
  2. 必要な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