Generate Images Using Canvas Inpainting
This feature allows for uploaded or generated Images as reference, apply ControlNet and add finer adjustments to your image appearance.
Follow this recipes with code snippets to generate images using Canvas Inpainting
ποΈ
Generate Images with Canvas Inpainting
Open Recipe
Inpainting
This guide will recreate the following Canvas Inpainting functionality in the Web UI via API.
Canvas Parameter Breakdown
- Image dimensions for images uploaded to
canvasInitId
andcanvasMaskId
must be divisible by 8. - Ensure
canvasRequest
is set toTrue
when using Canvas Editor features. - Models can be specified using
modelId
. All models except for Leonardo Lightning XL, Leonardo Anime XL and Phoenix can be used with Canvas Inpainting. A list of model Ids can be found here - Inpaint Strength is
init_strength
, which must be subtracted from 1 to match the equivalent value. E.g. In the example above, the Inpaint strength is 0.85, which equates toinit_strength:0.15
. - Max Inpaint strength is
init_strenght:0.8
. - Default values for
num_images
is 4,init_strength
is 0,guidance_scale
is 7. - Accepted file formats are jpg, png, jpeg, webp.
Uploading Mask
Note
- Masks must be uploaded as a white element against a black background. Inpainting will be applied on the white area.
- Additional colour can be applied on the init image.
- Mask and Init Image dimensions must match, otherwise image generation will fail.
Image Dimension Generation Limit
Max height
and width
dimensions for both canvasInitId
and canvasMaskId
is 1536x1536. This table shows the allowed number of images based on the image dimension of the init and mask image.
Dimensions | num_images |
---|---|
512x512 | 8 |
768x768 | 8 |
512x1024 | 4 |
768x1024 | 4 |
> 1024x1024 | 2 |
Sample Request
Parameter compatibility
Parameters other than those listed below are not compatible with Canvas Inpainting, i.e.
alchemy
,photoReal
.
curl --request POST \
--url https://cloud.leonardo.ai/api/rest/v1/generations \
--header 'accept: application/json' \
--header 'authorization: Bearer <YOUR_API_KEY>' \
--header 'content-type: application/json' \
--data '
{
"prompt": "a bright sun",
"canvasRequest": True,
"num_images": 4,
"init_strength": 0.15, // Inpaint strength 0.85
"canvasRequestType": "INPAINT",
"guidance_scale": 7,
"modelId": "1e60896f-3c26-4296-8ecc-53e2afecc132", // Leonardo Diffusion XL
"canvasInitId": init_image_id,
"canvasMaskId": masks_image_id
}
Updated 4 months ago