透過素材を作るには
透過素材を作るためには拡張機能「Layer Diffusion」を利用します。
この機能を利用することで透過素材(アルファチャネルを持つPNGファイル)を簡単に作成することができます。
![](https://techhowto.blog/wp-content/uploads/2024/05/012-4.png)
![](https://techhowto.blog/wp-content/uploads/2024/05/013-4.png)
Layer Diffusionのインストール
今回はStable Diffusion Web UI Forgeで使える拡張機能「sd-forge-layerdiffuse」の形でインストールします。
Stable Diffusion Web UI Forgeのインストール方法は以下のページを参照してください。
まずはStable Diffusion Web UI Forgeを起動し「Extensions」タブを選択します。
![](https://techhowto.blog/wp-content/uploads/2024/05/001-2.png)
次に「Install from URL」に進みます。
![](https://techhowto.blog/wp-content/uploads/2024/05/002-3.png)
以下のURLを入力し「Install」を選択します。
https://github.com/layerdiffusion/sd-forge-layerdiffuse
![](https://techhowto.blog/wp-content/uploads/2024/05/003-4.png)
インストールが完了したら以下の表示がされるので「Installed」タブに進みます。
![](https://techhowto.blog/wp-content/uploads/2024/05/004-3.png)
![](https://techhowto.blog/wp-content/uploads/2024/05/005-3.png)
「Apply and restart UI」を選択します。Web UIの再起動がかかるので完了まで待ちましょう。
![](https://techhowto.blog/wp-content/uploads/2024/05/006-3.png)
再起動したらインストールは完了です。
対応したモデルのインストール
背景透過画像を出力するには、背景透過画像を学習させたモデルを使用する必要があります。
推奨されているモデルは以下の二つです。
- Juggernaut XL / リアル系モデル
- anima_pencil-XL / アニメ系モデル
モデルのインストールについては以下の記事を参照してください。
透過素材を生成する
「Generation」タブの「LayerDiffuse」を選択します。
![](https://techhowto.blog/wp-content/uploads/2024/05/007-4.png)
「Enabled」にチェックを入れ、「Method」を「Only Generate Transparent Image(Attention Injection)」を選択します。
![](https://techhowto.blog/wp-content/uploads/2024/05/009-4.png)
インストールした推奨モデルを選択し、プロンプトを記入、画像を生成します。
![](https://techhowto.blog/wp-content/uploads/2024/05/010-4.png)
Layer Diffusionで透過画像を生成すると二種類の画像が生成されます。
![](https://techhowto.blog/wp-content/uploads/2024/05/011-4.png)
左のチェック柄背景は透過のイメージ(チェック柄部分が透過)で、実際の背景透過画像は右の白背景のものとなります。
適当な背景と重ね合わせてみます。
![](https://techhowto.blog/wp-content/uploads/2024/05/014-4.jpg)
![](https://techhowto.blog/wp-content/uploads/2024/05/016-2-1.jpg)
きちんと透過画像として出力されていることがわかります。
背景に合わせた透過素材を生成する
以下の画像のベンチに座った女の子の透過素材を生成してみます。
![](https://techhowto.blog/wp-content/uploads/2024/05/004-4.png)
「Layer Diffuse」の項目の「Method」を「From Background to Blending」に変更します。
![](https://techhowto.blog/wp-content/uploads/2024/05/001-3.png)
画像を登録するエリアが表示されるので背景画像を登録します。
![](https://techhowto.blog/wp-content/uploads/2024/05/003-5.png)
ベンチに座る女の子を生成するようなプロンプトを入力し画像を生成します。
結構難易度高いので根気強くいきましょう。
そして生成された画像がこちらです。
![](https://techhowto.blog/wp-content/uploads/2024/05/006-4.png)
ここから背景画像を削り、透過画像を生成します。
「LayerDiffuse」の「Method」を「From Background and Blending to Foreground」に変更します。
![](https://techhowto.blog/wp-content/uploads/2024/05/007-5.png)
生成した画像を追加で表示された画像登録エリアに登録します。
![](https://techhowto.blog/wp-content/uploads/2024/05/008-3.jpg)
次に「Generate」を選択します。
![](https://techhowto.blog/wp-content/uploads/2024/05/009-5.png)
背景を削った透過画像が生成されました。
![](https://techhowto.blog/wp-content/uploads/2024/05/010-5.png)
こうすることで背景にあったポーズの透過画像を生成できます。
![](https://techhowto.blog/wp-content/uploads/2024/05/011-5.png)
まとめ
今回はStable Diffusionを使って透過画像を生成できる「Layer Diffusion」についての説明と、インストールする方法、背景画像に合わせた画像を生成する方法を説明させていただきました。
以下内容のおさらいです。
どんな画像を出力するか指定するプロンプト(呪文)を以下のページにまとめています。
うまく使ってください。
コメント