|
| 1 | +# Image Editing |
| 2 | + |
| 3 | +Image editing in `stable-diffusion.cpp` allows you to use reference images to guide the generation process, enabling tasks like identity preservation, style transfer, or layout modification. |
| 4 | + |
| 5 | + |
| 6 | +## Supported Models |
| 7 | + |
| 8 | +Depending on the architecture, different models handle reference images differently. |
| 9 | + |
| 10 | +| Model | Default Preset | |
| 11 | +| :--- | :--- | |
| 12 | +| [**FLUX.1-Kontext-dev**](./kontext.md) | `flux_kontext` | |
| 13 | +| [**LongCat Image Edit**](./longcat_image.md) | `longcat` | |
| 14 | +| [**Qwen Image Edit**](./qwen_image_edit.md) | `qwen` | |
| 15 | +| **Qwen Image LAYERED** | `qwen_layered` | |
| 16 | +| [**Flux.2 [Dev] / Flux.2 [Klein]**](./flux2.md) | `flux2` | |
| 17 | +| [**Boogu Image Edit**](./boogu_image.md) | `z_image_omni` | |
| 18 | +| **Krea2 (Community Edit LoRAs)** | `krea2_ostris_edit` | |
| 19 | +| **Anima (Community Edit LoRAs)** | `cosmos_reference` | |
| 20 | + |
| 21 | +Stable-diffusion.spp also supports basic Unet-based editing models like instruct-pix2pix or CosXL-Edit. This document is not about those. |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +## Configuring Reference Modes (`--ref-image-args`) |
| 26 | + |
| 27 | +Different DiT-based editing models require different configurations to process reference images correctly (e.g., whether to use a Vision Language Model (VLM) encoder or pass VAE-encoded images directly to the DiT). |
| 28 | + |
| 29 | +To simplify this, we provide **Presets**. By default, the system automatically selects the best preset based on the model architecture. However, you can override this using the `--ref-image-args` argument. |
| 30 | + |
| 31 | +### Usage |
| 32 | +The `--ref-image-args` argument accepts a comma-separated list of key-value pairs: |
| 33 | + |
| 34 | +**Using a preset:** |
| 35 | +`--ref-image-args "preset=qwen_layered"` |
| 36 | + |
| 37 | +**Using a preset with a specific override:** |
| 38 | +`--ref-image-args "preset=krea2_edit,force_ref_timestep_zero=true"` |
| 39 | + |
| 40 | +### Available Presets |
| 41 | + |
| 42 | +| Preset | Primary Use Case | |
| 43 | +| :--- | :--- | |
| 44 | +| `flux_kontext` | FLUX.1 Kontext | |
| 45 | +| `longcat` | LongCat Image Edit | |
| 46 | +| `flux2` | FLUX.2 models | |
| 47 | +| `qwen` | Qwen Image Edit | |
| 48 | +| `qwen_layered` | Qwen Image Layered | |
| 49 | +| `z_image_omni` | Boogu, Z-Image Omni | |
| 50 | +| `krea2_ostris_edit` | Most Krea2 Community edit LoRAs (trained with Ostris script) | |
| 51 | +| `krea2_edit` | Specifically for [lbouaraba/krea2edit](https://huggingface.co/conradlocke/krea2-identity-edit). (or similar) | |
| 52 | +| `cosmos_reference` | For Anima | |
| 53 | +| `default` | Uses the automatic detection based on model architecture. | |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +## Advanced Parameter Reference |
| 58 | + |
| 59 | +If presets are insufficient, you can manually configure the following parameters via `--ref-image-args`: |
| 60 | + |
| 61 | +| Key | Type | Description | Allowed Values | |
| 62 | +| :--- | :--- | :--- | :--- | |
| 63 | +| `preset` | string | Overrides the automatic preset. | (See the Presets table above) | |
| 64 | +| `pass_to_vlm` | bool | Whether reference images are passed to the VLM encoder. | `true`, `false` | |
| 65 | +| `pass_to_dit` | bool | Whether VAE-encoded references are passed directly to the DiT. | `true`, `false` | |
| 66 | +| `ref_index_mode` | string | Behavior of the RoPE index. | `fixed`, `increase`, `decrease` | |
| 67 | +| `force_ref_timestep_zero` | bool | Forces timestep=0 for reference tokens. | `true`, `false` (Krea2 only) | |
| 68 | +| `resize_before_vae` | bool | Whether reference images are resized before VAE encoding. | `true`, `false` | |
| 69 | +| `vae_input_max_pixels` | int | Maximum pixel area for VAE reference inputs. | Integer | |
| 70 | +| `vlm_resize_mode` | string | How to resize VLM reference inputs. | `longest_side`, `area`, `none` | |
| 71 | +| `vlm_max_size` | int | Maximum VLM input size; interpreted according to `vlm_resize_mode`. | Integer | |
| 72 | +| `vlm_min_size` | int | Minimum VLM input size; interpreted according to `vlm_resize_mode`. | Integer | |
| 73 | +| `vlm_size` | int | Shortcut to set both VLM min and max size to the same value. | Integer | |
| 74 | + |
| 75 | +### Preset Default Values |
| 76 | + |
| 77 | +For a technical overview of how each preset is configured, see the table below. |
| 78 | + |
| 79 | +| Preset | VLM | RoPE Index | Cond Resize | Special Notes | |
| 80 | +| :--- | :---: | :---: | :---: | :--- | |
| 81 | +| `flux_kontext` | No | `fixed` | `none` | | |
| 82 | +| `longcat` | Yes | `fixed` | `area` | | |
| 83 | +| `flux2` | No | `increase` | `none` | | |
| 84 | +| `qwen` | Yes | `increase` | `area` | | |
| 85 | +| `qwen_layered` | Yes | `decrease` | `area` | | |
| 86 | +| `z_image_omni` | Yes | `fixed` | `area` | | |
| 87 | +| `krea2_ostris_edit`| Yes | `increase` | `area` | `force_ref_timestep_zero = true` | |
| 88 | +| `krea2_edit` | Yes | `increase` | `longest` | `vlm_size = 768` | |
| 89 | +| `cosmos_reference` | No | `fixed` | `none` | `resize_before_vae = false` | |
| 90 | + |
| 91 | +**Additional Default Notes:** |
| 92 | +- **VLM Input Sizes:** For most presets, `vlm_max_size` and `vlm_min_size` are set to `-1`, meaning the values are model-dependent and handled automatically. In `area` mode they represent pixel area; in `longest_side` mode they represent a side length in pixels. |
| 93 | +- **VAE Input Size:** `vae_input_max_pixels` defaults to $1024 \times 1024$ pixels (`1048576`). |
0 commit comments