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