> For the complete documentation index, see [llms.txt](https://documentation.deep-image.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.deep-image.ai/image-processing/inpainting-and-outpainting-uncrop.md).

# Inpainting and outpainting (uncrop)

## Inpainting

Inpainting is a technique used in image processing to fill in missing or damaged parts of an image in a way that blends seamlessly with the surrounding areas. This process can reconstruct removed elements or extend the background of an image while preserving the visual coherence of textures, colors, and patterns.

Inpainting is a part of background generation parameters

| Parameter     | Description       |
| ------------- | ----------------- |
| adapter\_type | inpainting        |
| ip\_image2    | url to mask image |

Let's check the example. There is a generated image with some hand issues:

<figure><img src="/files/QHrseatyhRmQvNMfJ27E" alt=""><figcaption></figcaption></figure>

Quickly created mask:

<figure><img src="/files/563EVW0qMIpdw3wtVE5R" alt=""><figcaption></figcaption></figure>

```json
{
    "url": "https://s3.eu-central-1.amazonaws.com/deep-image.ai/api-examples/inpainting-example.png",
    "background": {
        "generate": {
            "description": "hands touching surfing board",
            "adapter_type": "inpainting",
            "ip_image2": "https://s3.eu-central-1.amazonaws.com/deep-image.ai/api-examples/inpainting-example-mask4.png",
            "controlnet_conditioning_scale": 0.5
        }
    }
}
```

And the result:

<figure><img src="/files/EJky7nApeo0vuYKQsEvq" alt=""><figcaption></figcaption></figure>

## Outpainting (uncrop)

Outpainting, or "uncropping," is a technique used to expand an image beyond its original borders by generating new visual content that seamlessly extends the existing scene. Unlike inpainting, which fills in missing areas within an image, outpainting creatively imagines what might lie beyond the current frame, effectively "uncropping" it to add context or detail.

Let's make a horizontal image of the vertical one.

<figure><img src="/files/MlIHPDR2tRRjuvnvpL7b" alt=""><figcaption></figcaption></figure>

```json
{
    "url": "https://deep-image.ai/api-example2.jpg",
    "width": 2000,
    "height": 1000,
    "fit": {
        "canvas": "outpainting"
    }
}
```

And the result:

<figure><img src="/files/CNqYgs9GgH5DYxjoJEHz" alt=""><figcaption></figcaption></figure>

Prompt or image description is generated by default so for this particular example is: "there is a boat that is sitting on the sand near a building".

Additional outpainting parameters:

| Parameter                        | Description                                                                                                                                                                                                          |
| -------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `background.generate.model_type` | Controls the outpainting model. Supported values are `qwen` and `qwen-no-blending`. The default is `qwen`. `qwen-no-blending` works like `qwen`, but it does not blend the original image over the generated result. |
| `placement`                      | Controls where the source image is placed on the destination canvas before outpainting starts.                                                                                                                       |
| `placement.coordinates`          | X and Y coordinates of the placed source image on the destination canvas.                                                                                                                                            |
| `placement.width`                | Width of the placed source image area.                                                                                                                                                                               |
| `placement.height`               | Height of the placed source image area.                                                                                                                                                                              |
| `placement.rotation`             | Rotation of the placed source image.                                                                                                                                                                                 |
| `placement.fit`                  | Controls whether the source image is fitted to the placement box.                                                                                                                                                    |

We can use our prompt as well:

```json
{
    "url": "https://deep-image.ai/api-example2.jpg",
    "width": 2000,
    "height": 1000,
    "fit": {
        "canvas": "outpainting"
    },
    "background": {
        "generate": {
            "adapter_type": "upscale",
            "description": "Boat on Mars with spaceships around."
        }
    }
}
```

And the result:

<figure><img src="/files/WoHrGA5J1CWbJly5O2LQ" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
`generative_upscale` applies diffusion-based upscaling to the final image. It can improve detail, but it can also slightly change the original source image. Keep it `false` when you want to preserve the source area more closely.
{% endhint %}

We can also place the source image manually and select the outpainting model:

```json
{
    "width": 3434,
    "height": 2074,
    "background": {
        "generate": {
            "description": "high quality",
            "model_type": "qwen-no-blending",
            "adapter_type": "upscale"
        }
    },
    "generative_upscale": false,
    "placement": {
        "coordinates": [
            1717,
            1037
        ],
        "width": 880,
        "height": 1244,
        "rotation": 0,
        "fit": false
    },
    "image_app": "tool_uncrop",
    "fit": {
        "canvas": "outpainting"
    },
    "url": "https://deep-image.ai/api-example2.jpg"
}
```

Let's see an example. It's generative upscaled with blending of original image:

<figure><img src="/files/WtUP61GxGBoD7zUWi7IG" alt=""><figcaption></figcaption></figure>

And the result:

<figure><img src="/files/NF5dm1RqMfNJiFVqcEDi" alt=""><figcaption></figcaption></figure>
