> 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/background-removal-and-generation.md).

# Background removal and generation

Use `background.remove` to cut out the main subject.

You can keep transparency, apply a flat color, replace the background, or generate a new one.

### Background removal

```json
{
    "background": {
        "remove": "auto",
        "color": "#FFFFFF"
    }
}
```

#### Parameters

| Parameter | Description                                                                                                 |
| --------- | ----------------------------------------------------------------------------------------------------------- |
| `remove`  | Controls the background removal mode. Supported values are `auto`, `v2`, `human`, `item`, and `generative`. |
| `prompt`  | Text instruction used with `remove: "generative"`. Describe what should stay in the foreground.             |
| `color`   | Controls the output background color. Use `auto`, a hex color like `#FFFFFF`, or `transparent`.             |
| `replace` | URL of a background image for simple replacement. This does not generate new shadows or reflections.        |

`auto` is the default mode.

Use `human` for portraits.

Use `item` for products and objects.

Use `generative` when the image has multiple relevant foreground elements and you want the prompt to guide what stays.

Let's check some examples.

<figure><img src="/files/4d4lcIVAUK2RoE4M3JtT" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Click the result image to compare it with the source.
{% endhint %}

{% tabs %}
{% tab title="transparent" %}

```json
{
    "url": "https://deep-image.ai/api-example.png",
    "background": {
        "remove": "auto",
        "color": "transparent"
    }
}
```

{% endtab %}

{% tab title="white" %}

```json
{
    "url": "https://deep-image.ai/api-example.png",
    "background": {
        "remove": "item",
        "color": "#FFFFFF"
    }
}
```

<figure><img src="/files/h4lRJPRBOeV32EHegOMu" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="replace" %}

```json
{
    "url": "https://deep-image.ai/api-example.png",
    "background": {
        "remove": "auto",
        "replace": "https://images.pexels.com/photos/628281/pexels-photo-628281.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"
    }
}
```

<figure><img src="/files/G5t062WeBPZLbP0h19wB" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

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

### Prompt-based background removal

Use prompt-based removal when `auto` keeps too much, removes too much, or misses related foreground objects.

Keep the prompt short and focused on what should remain.

```json
{
    "background": {
        "remove": "generative",
        "prompt": "keep relevant foreground, keep relevant objects"
    }
}
```

You can combine this with `color` or `replace` when you do not want a transparent result.

For image preparation tips, see [Remove BG recommendation](/image-processing/background-removal-and-generation/remove-bg-recommendation.md).

### Item cropping

You can combine background removal, padding, and item crop to center a subject inside a fixed canvas.

```json
{
    "url": "https://deep-image.ai/api-example2.jpg",
    "width": 1000,
    "height": 1000,
    "fit": {
         "crop": "item"
    },
    "background": {
        "remove": "auto",
        "color": "#FFFFFF"
    },
    "padding": 100
}
```

<figure><img src="/files/rwHzQg3xVg5IuwBt3DGN" alt=""><figcaption><p>Result</p></figcaption></figure>

### Background generation

Background generation improves product photos without a manual photo shoot.

It removes the original background, places the subject on the canvas, and generates a new scene around it.

#### Parameters

| Parameter              | Description                                                                                                             |
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `description`          | Text prompt describing the scene.                                                                                       |
| `item_area_percentage` | Float from `0` to `1` that controls how much of the final image the item occupies. `0.85` means 85%.                    |
| `sample_num`           | Random seed for the generated image. If you omit it, results vary between runs.                                         |
| `color`                | Converts the generated background to black and white, then tints it with the given RGB array. Example: `[255,255,255]`. |
| `background_url`       | URL of an image blended with the generated background for more consistent outputs.                                      |

```json
{
    "url": "https://deep-image.ai/api-example.png",
    "background": {
        "generate": {
            "description": "item standing on sand with beach in background",
            "item_area_percentage": 0.65,
            "sample_num": 12663
        }
    }
}
```

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

Without `sample_num`:

```json
{
    "url": "https://deep-image.ai/api-example.png",
    "background": {
        "generate": {
            "description": "item standing on sand with beach in background",
            "item_area_percentage": 0.65
        }
    }
}
```

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

You can also set the output size:

```json
{
    "url": "https://deep-image.ai/api-example.png",
    "width": 1000,
    "height": 1000,
    "background": {
        "generate": {
            "description": "item standing on sand with beach in background",
            "item_area_percentage": 0.65
        }
    }
}
```

<figure><img src="/files/8EBrGXS2ezXviOWpbkN9" alt=""><figcaption></figcaption></figure>

When specifying a color:

```json
{
    "url": "https://deep-image.ai/api-example.png",
    "width": 1000,
    "height": 1000,
    "background": {
        "generate": {
            "description": "item positioned on plain white background",
            "item_area_percentage": 0.65,
            "color": [217,179,190]
        }
    }
}
```

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