# Image to Image

2D画像情報をインプットに画像生成を行います。

Unityのカメラの範囲の映像、別で準備した画像データを利用します。

Image to Imageを使用することで新しい要素を追加してなじませたり微調整を行ったりが可能です

<div><figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2F7jUiaxvIltUPGvRXgdWc%2F00000-3917042126.png?alt=media&#x26;token=f3984de2-7318-44f7-90ed-3ad5da15fe93" alt=""><figcaption></figcaption></figure> <figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FYuIidsyodumQF8G06snD%2F00026-4237068665.png?alt=media&#x26;token=06ea7754-c6ec-4675-a426-c91a1e4f9002" alt=""><figcaption></figcaption></figure></div>

現在(2023年4月)Image to ImageはWebUIを使用することで部分的に修正が可能なInpaint機能などを使うことが出来るためWebUIを使うこともお勧めです。

stable-diffusion-for-unityではStableDiffusionWebUIを動かしているため、UnityからStartServerで起動したコマンドプロンプトに記載のローカルサーバーのURLよりWebUIの機能を使用することが可能です。

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FGPKsFvrgawqcsrhZLZxn%2Fwebui.png?alt=media&#x26;token=0a414b01-2af9-4965-863d-5bbe479bae1b" alt=""><figcaption><p>ローカルサーバーURL</p></figcaption></figure>

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FvOoFu9g8GFewxjw53hFP%2Fimage.png?alt=media&#x26;token=5ea14afb-7556-479c-9974-7f5c48acf981" alt=""><figcaption><p>WebUIインペイント</p></figcaption></figure>

Unity上で行う場合<br>

<figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2F2dzVwpXBdjf3zMdvalrq%2Fimage.png?alt=media&#x26;token=0ba210c7-3859-4f5d-a558-344212fd318c" alt=""><figcaption></figcaption></figure>

Img2Img.csコンポーネントをオブジェクトにアタッチして使用します。

以下ローカルサーバーが立ち上がっている前提です。下記を参考にStartServerしてからご使用ください

[rkarusbnitsuite](https://docs.witchpot.com/production/rkarusbnitsuite "mention")

パラメータ概要を下記に示します。特によく調整を行うパラメータを太字にしています

<table><thead><tr><th width="198">パラメータ</th><th>内容</th></tr></thead><tbody><tr><td><strong>ImageSource</strong></td><td>インプットとする要素を準備した画像にするかUnity内のカメラ映像とするか</td></tr><tr><td>Image</td><td>ImageSourceでTextureを選んだ場合、インプットとする画像を選択<br>詳細は表下に記載</td></tr><tr><td><strong>Prompt</strong></td><td>生成したい画像を自然言語で入力</td></tr><tr><td><strong>NegativePrompt</strong></td><td>生成画像に含みたくない要素を自然言語で入力</td></tr><tr><td><strong>Width</strong></td><td>生成画像の横幅をpixelで入力</td></tr><tr><td><strong>Height</strong></td><td>生成画像の高さをpixelで入力</td></tr><tr><td>Steps</td><td><p>生成画像の精細さが変わる</p><p>生成画像がぼやけた感じになる場合に大きくしてください</p></td></tr><tr><td><strong>Cfg Scale</strong></td><td>プロンプトに従う強さ<br>プロンプトの要素の反映が弱い場合に多きな値に調整してください。</td></tr><tr><td><strong>DenoisingStrength</strong></td><td>インプット画像にどれだけ忠実に画像生成されるか<br>インプット画像を少しだけ変更したい場合、値を小さく<br>画像を大幅に変更したい場合値を大きくしてください</td></tr><tr><td>Seed</td><td>シード値を固定すると同じような画像が生成かの可能<br>-1の場合ランダムとなる</td></tr><tr><td>Batch Count</td><td>画像生成を行う枚数を指定します<br>1~100枚で選択することが出来ます。<br>生成画像はStreamingAssets/StableDiffusion内に保存されます。エクスプローラーで日時順などにして確認してください</td></tr><tr><td>ExportType</td><td>出力タイプとしてPNG, JPG, TGAを選択可能<br>Image, RawImage, Materialなどに適用</td></tr><tr><td>Sampler</td><td>生成画像のニュアンスを変える</td></tr><tr><td><strong>Model</strong></td><td>ベースとなるモデル<br>変え方はも<a href="../production/moderuloranoshie">モデル/LoRAの差し替え</a>ご覧ください</td></tr><tr><td><strong>Lora</strong></td><td>追加学習により特定の要素を出しやすくする要素<br>変え方は<a href="../production/moderuloranoshie">モデル/LoRAの差し替え</a>をご覧ください<br>Loraを選択するとPromptに&#x3C;lora:ファイル名:1>が追加されて使用可能になります</td></tr></tbody></table>

インプットとしてTextureを選択した場合の設定

画像のImportSettingsで>Read/Writeにチェックを入れてください。

<div align="left"><figure><img src="https://501701507-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fxpygm4kgEjp47Cbyg5EY%2Fuploads%2FOXvLsEnU3UfOjB4sOcnn%2Fimage.png?alt=media&#x26;token=766e2751-b05c-48a3-92dd-12b36ff008f1" alt=""><figcaption></figcaption></figure></div>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.witchpot.com/component/image-to-image.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
