Transform Sketches into Lifelike Images with qr2ai/outline Cognitive Actions

23 Apr 2025
Transform Sketches into Lifelike Images with qr2ai/outline Cognitive Actions

In today's digital landscape, the ability to convert simple sketches into detailed images opens up a world of creative possibilities. The qr2ai/outline API is designed to help developers integrate such capabilities into their applications seamlessly. With its advanced image generation techniques, the cognitive action "Transform Sketch to Realistic Image" allows users to transform outline sketches into lifelike images. This blog post will guide you through the capabilities of this action, including how to use it and the benefits of leveraging pre-built cognitive actions.

Prerequisites

Before you start integrating the Cognitive Actions, ensure you have:

  • An API key for the Cognitive Actions platform.
  • A basic understanding of how to make HTTP requests and handle JSON payloads.
  • Familiarity with Python will be beneficial for implementing the conceptual usage examples.

Authentication typically involves passing your API key in the request headers for secure access to the cognitive actions.

Cognitive Actions Overview

Transform Sketch to Realistic Image

This action converts outline sketches into detailed, lifelike images, supporting various sketch types and customizable prompts. It's categorized under image-generation.

Input

The input for this action is a JSON payload that can include several parameters to customize the image generation:

  • seed (integer): Random seed for generation (default is 0).
  • image (string): URI of the input image for processing.
  • width (integer): Output image width in pixels (default is 1920).
  • height (integer): Output image height in pixels (default is 1088).
  • prompt (string): Main input prompt guiding the image generation.
  • sampler (string): Sampling method for image generation (default is "Euler a").
  • blurSize (integer): Gaussian blur kernel size (default is 3).
  • useCanny (boolean): Use Canny edge detector for enhanced detail (default is false).
  • loraInput (string): Comma-separated list of LoRA model paths.
  • loraScale (string): Scales for each LoRA model.
  • kernelSize (integer): Kernel size for morphological operations (default is 3).
  • numOutputs (integer): Number of images to output (default is 1, max 4).
  • sketchType (string): Type of sketch detector (default is "HedPidNet").
  • suffixPrompt (string): Additional prompt to enhance the generation.
  • guidanceScale (number): Scale parameter influencing adherence to the prompt (default is 12).
  • weightPrimary (number): Weight for the primary sketch method (default is 0.7).
  • generateSquare (boolean): Specify if the output should be square (default is false).
  • negativePrompt (string): Input prompt to deter undesired elements.
  • weightSecondary (number): Weight for the secondary sketch (default is 0.6).
  • erosionIterations (integer): Number of erosion iterations (default is 2).
  • numInferenceSteps (integer): Number of denoising steps (default is 35).
  • dilationIterations (integer): Number of dilation iterations (default is 5).
  • adapterConditioningScale (number): Scaling factor for the adapter module (default is 0.97).

Here's an example of the JSON payload:

{
  "seed": 0,
  "image": "https://replicate.delivery/pbxt/Lcg9dtkX66pSWfULefLA7UMExDQoonK9lmdA9y1R6kbEF9Q6/outline.png",
  "width": 1024,
  "height": 1024,
  "prompt": "Modern skyscraper, glass facade, urban skyline, clear day.",
  "sampler": "Euler a",
  "blurSize": 3,
  "useCanny": false,
  "loraInput": "",
  "loraScale": "",
  "kernelSize": 3,
  "numOutputs": 1,
  "sketchType": "HedPidNet",
  "suffixPrompt": "Futuristic Concept, Cutting-Edge Technology, Historical Landmark, Timeless Aesthetics, sharp focus, 8k, uhd, file grain, masterpiece",
  "guidanceScale": 7.5,
  "weightPrimary": 0.7,
  "generateSquare": false,
  "negativePrompt": "deformed, animation, anime, cartoon, comic, cropped, out of frame, low res, draft, cgi, low quality render, thumbnail",
  "weightSecondary": 0.6,
  "erosionIterations": 2,
  "numInferenceSteps": 35,
  "dilationIterations": 1,
  "adapterConditioningScale": 0.9
}

Output

Upon successful execution, the action will return a JSON array containing the URLs of the generated images. Here's an example of the output:

[
  "https://assets.cognitiveactions.com/invocations/2ffd9f84-7726-42aa-a5a8-4223a051f8a9/db9a2e0d-70ff-4dd8-a7ab-b1bc9bf44006.png"
]

This output includes the link to the created image, which can be displayed or further processed in your application.

Conceptual Usage Example (Python)

Here’s how you might structure a call to the Cognitive Actions API using Python. This code demonstrates how to send the JSON payload for the "Transform Sketch to Realistic Image" action:

import requests
import json

# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint

action_id = "7ffbbbab-0d03-4e38-a1fc-a01e07708cf2" # Action ID for Transform Sketch to Realistic Image

# Construct the input payload based on the action's requirements
payload = {
    "seed": 0,
    "image": "https://replicate.delivery/pbxt/Lcg9dtkX66pSWfULefLA7UMExDQoonK9lmdA9y1R6kbEF9Q6/outline.png",
    "width": 1024,
    "height": 1024,
    "prompt": "Modern skyscraper, glass facade, urban skyline, clear day.",
    "sampler": "Euler a",
    "blurSize": 3,
    "useCanny": false,
    "loraInput": "",
    "loraScale": "",
    "kernelSize": 3,
    "numOutputs": 1,
    "sketchType": "HedPidNet",
    "suffixPrompt": "Futuristic Concept, Cutting-Edge Technology, Historical Landmark, Timeless Aesthetics, sharp focus, 8k, uhd, file grain, masterpiece",
    "guidanceScale": 7.5,
    "weightPrimary": 0.7,
    "generateSquare": false,
    "negativePrompt": "deformed, animation, anime, cartoon, comic, cropped, out of frame, low res, draft, cgi, low quality render, thumbnail",
    "weightSecondary": 0.6,
    "erosionIterations": 2,
    "numInferenceSteps": 35,
    "dilationIterations": 1,
    "adapterConditioningScale": 0.9
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json"
}

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json={"action_id": action_id, "inputs": payload} # Hypothetical structure
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully:")
    print(json.dumps(result, indent=2))

except requests.exceptions.RequestException as e:
    print(f"Error executing action {action_id}: {e}")
    if e.response is not None:
        print(f"Response status: {e.response.status_code}")
        try:
            print(f"Response body: {e.response.json()}")
        except json.JSONDecodeError:
            print(f"Response body: {e.response.text}")

In this snippet, replace the YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The payload is constructed according to the action's requirements, ensuring all necessary fields are included.

Conclusion

The "Transform Sketch to Realistic Image" action from the qr2ai/outline API provides developers with a powerful tool to enhance their applications with advanced image generation capabilities. By leveraging this cognitive action, you can easily convert sketches into realistic images, opening up a variety of creative possibilities. Explore the potential use cases in your projects, and consider integrating this action to elevate your application's visual output!