# 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="https://2652559519-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3i5YcUkcXyIsWHIhRO2d%2Fuploads%2FAWFuWVhkwN1KWSArL2ze%2Finpainting-example.png?alt=media&#x26;token=7beb7bf5-4c9e-4fe3-9c0d-456272ed4ab7" alt=""><figcaption></figcaption></figure>

Quickly created mask:

<figure><img src="https://2652559519-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3i5YcUkcXyIsWHIhRO2d%2Fuploads%2FLwHQsDcxi6ZyuECHzsgS%2Finpainting-example-mask4.png?alt=media&#x26;token=1a514e15-fd50-47c1-adaf-601037b4d4fc" 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="https://2652559519-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3i5YcUkcXyIsWHIhRO2d%2Fuploads%2FSiyoI17EaWBcU9dcKf6V%2Finpainting-example-width%3D1024_height%3D1024_generated%20(16).png?alt=media&#x26;token=b4e49390-ecc5-460d-b0c3-5f2185511b76" 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="https://2652559519-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3i5YcUkcXyIsWHIhRO2d%2Fuploads%2FDJ7jXNKONDSsIiCi8TNy%2Fimage%20(20).jpeg?alt=media&#x26;token=a3facbbe-29c5-4f73-ac1f-eed6e277c1f6" 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="https://2652559519-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3i5YcUkcXyIsWHIhRO2d%2Fuploads%2FUnEu6Y8ESWQ1eUTOgBzo%2Fapi-example2-width%3D2000_height%3D1000.jpg?alt=media&#x26;token=b81aa8b6-7389-4a3a-86c9-ccb7d88012c0" 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".

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="https://2652559519-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3i5YcUkcXyIsWHIhRO2d%2Fuploads%2FiMh9YkSfITPFBq37qsdP%2Fapi-example2-width%3D2000_height%3D1000_generated.jpg?alt=media&#x26;token=802ed7f4-cfb7-4ca5-a1ac-5c89dddabd88" alt=""><figcaption></figcaption></figure>
