API Documentation
  • Welcome!
  • Quick Start
  • API methods
  • Easy integration
  • Easily Copy Pre-Formatted API Requests for Integration
  • Handling Large File Sets
  • Supported formats
  • Webhooks
  • Common usecases
    • Auto enhance image quality
    • Create business photo or avatar from face image
    • Face swap
    • Create beautiful product photo
    • Genarate image in high resolution
    • Remove background
    • AI Drawing to Image - Doodle
    • Real estate
    • Enhancing documents
    • Car dealer photo
  • Image processing
    • Resize and padding
    • Denoise and sharpen
    • Enhance lighting and colors
    • Enhance face details
    • Background removal and generation
    • Image generation
    • Inpainting and outpainting (uncrop)
    • Frame identification
    • Print
    • Captions
    • Additional parameters
    • Presets
  • Account & settings
    • Account information
  • storages
    • Overview
    • Usage
    • Setup
      • AWS S3
      • OneDrive
      • Dropbox
      • Google Drive
  • Presets
    • E-commerce
    • Real-estate
    • Print/Photo
    • Digital Art
  • Technology
    • Algorithms
    • Upscale
    • Background removal
      • Remove BG recommendation
    • Sharpen & Noise reduction
    • Enhance Lighting
  • FAQ
Powered by GitBook
On this page
  • Background removal
  • Item cropping
  • Background generation
  1. Image processing

Background removal and generation

PreviousEnhance face detailsNextImage generation

Last updated 2 months ago

Background of the image can be removed with "remove" parameter of background options.

Also removed background can be replaced with generated one.

Background removal

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

Description of "type" parameter of remove background function.

Parameter
Description

remove

Parameter that controls background removal algorithm.

  • "auto" - (default) automatically picks remove background type based on image

  • "v2" - new remove background algorithm

  • "human" - background removal optimized for photos of people

  • "item" - background removal optimized for photos of items

color

Parameter that controls image background.

If given, image alpha channel will be composited with it.

  • auto - API first tries to identify frame around the object (like in typical ecommerce product photos) and uses that color. The fallback is white color.

  • "#FFFFFF" - RGB color in hexadecimal format.

  • "transparent" - background will be empty for image formats that allows that, f.e. PNG or WEBP.

replace

URL for the simple background image replacement - no shadows or reflections.

Let's check some examples.

Click on the result image to see the difference.

"remove_background": {
    "type": "auto",
    "background": "transparent"
}
"remove_background": {
    "type": "item",
    "background": "#FFFFFF"
}
{
    "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"
    }
}

Item cropping

Let's combine background removal, padding and cropping. With those combinations we are able to put object with any proportions in a desired canvas frame at the center with distance specified as padding option.

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

Background generation

Generating background is fantastic way of improving product photo look. It can be even solution for creating product pack shots without need of manually taking expensive commercial photo shoots.

Let's check what we can do.

Parameter
Description

description

Text prompt describing the scene

item_area_percentage

Parameter between 0 and 1 that controls size of the object which is placed in the middle of final image. So, 0.85 is 85%

sample_num

Seed for random generator. Basically is "id" of generated image. When not specified, image will randomly different every time.

color

When color is specified, generated background is converted to b&w and then to specified color. It works best for prompts such as: "item standing on plain white background". Color has to be RGB array - f.e. [255,255,255]

background_url

Url to image which will be blended together with generated background - it is useful for creating product images that require the same background every time.

{
    "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
        }
    }
}

Without sample_num:

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

We can specify also image resolution:

{
    "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
        }
    }
}

When specifying a color:

{
    "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]
        }
    }
}

Result
Page cover image