Generate Images Using Image to Image Guidance

Fine tune your generations with Image to Image Guidance. This feature allows for uploaded or generated Images as reference and can help make finer adjustments to your final image appearance.

Image to Image Guidance with Uploaded Images

Follow this recipe to generate images using Image to Image Guidance via Uploaded Images

The guide will recreate the following functionality in the Web UI via API.

Uploading and Image to use for Image Guidance

Uploading and Image to use for Image Guidance

Applying Uploaded Image as Image to Image Guidance

Applying Uploaded Image as Image to Image Guidance

πŸ“˜

Note

  • The Generate Image API can only accept one input image for Image Guidance at a time.
  • To use ControlNet-based Image Guidance features such as Depth to Image, Edge to Image (CANNY) or Pose to Image, add "controlNet": True and specify the type of ControlNet, i.e "controlNetType": "CANNY"to the body of your API call.

🚧

Limitations

Image Guidance features on API does not yet have full parity with the Web UI.

Sample Request

This request adds Pose to Image ControlNet using an init_image from your uploaded file.

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 '
{
  "height": 512,
  "modelId": "1e60896f-3c26-4296-8ecc-53e2afecc132",
  "prompt": "An oil painting of an orange cat",
  "width": 512,
  "init_image_id": <YOUR_INIT_IMAGE_ID> ,
  "init_strength": 0.5,
  "controlNet": True,
  "controlNetType": "POSE"  
}

Image to Image Guidance with Generated Images

Follow this recipe to generate images using Image Guidance via Generated Images

The guide can use previous Generations as your input image

Using a recently generated image as input image

Using a recently generated image as input image

Applying previously generated image as Image to Image Guidance

Applying previously generated image as Image to Image Guidance

πŸ“˜

Note

  • The Generate Image API can only accept one input image for Image Guidance at a time.
  • To use ControlNet-based Image Guidance features such as Depth to Image, Edge to Image (CANNY) or Pose to Image, add "controlNet": True and specify the type of ControlNet, i.e "controlNetType": "CANNY"to the body of your API call.

🚧

Limitations

Image Guidance features on API does not yet have full parity with the Web UI.

Sample Request

This request adds Edge to Image ControlNet using your previously generated image.

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 '
{
  "height": 512,
  "modelId": "1e60896f-3c26-4296-8ecc-53e2afecc132",
  "prompt": "An oil painting of an orange cat",
  "width": 512
  "init_generation_image_id": "<YOUR_GENERATED_IMAGE_ID>",
  "init_strength": 0.5,
  "controlNet": True,
  "controlNetType": "CANNY"  
}


What’s Next

View our other API References below