Enhance Your Images with Cognitive Actions from Ending Scene

23 Apr 2025
Enhance Your Images with Cognitive Actions from Ending Scene

In the realm of image processing, the integration of advanced functionalities can significantly enhance the creative possibilities of your applications. The Ending Scene Cognitive Actions provide a robust API for generating refined images through enhanced features, including img2img transformations and inpainting capabilities. This post will guide you through the capabilities of the Generate Enhanced Image action, demonstrating how you can leverage this powerful tool in your projects.

Prerequisites

Before diving into the integration of Cognitive Actions, ensure you have the following:

  • An API key for accessing the Cognitive Actions platform.
  • Basic knowledge of JSON for structuring your requests.

Authentication typically involves passing your API key in the headers of your HTTP requests.

Cognitive Actions Overview

Generate Enhanced Image

The Generate Enhanced Image action allows you to create visually compelling images by utilizing specified prompts for either img2img or inpainting operations. This action provides refined guidance and scheduler options that help you achieve controlled transformations with adjustable parameters to improve image generation quality.

Input

The input for this action consists of several parameters that allow for fine-tuning the image generation process. Here’s a breakdown of the required and optional fields:

  • inputPrompt (string): A description of the desired image content.
    Example: "a hand-drawn TOK fantasy game wallpaper, a green sunrise"
  • negativeInputPrompt (string): Specifies undesired attributes in the output.
    Example: "realistic, highly detailed, single color, messy, centered, frame, border line, deformed, mutated, disfigured"
  • outputWidth (integer): Width of the output image in pixels (default: 1024).
    Example: 1344
  • outputHeight (integer): Height of the output image in pixels (default: 1024).
    Example: 768
  • loraIntensity (number): Scale for the LoRA effect intensity (range: 0 to 1).
    Example: 0.6
  • promptIntensity (number): Strength of the prompt (range: 0 to 1).
    Example: 0.8
  • watermarkStatus (boolean): Indicates whether a watermark should be applied (default: true).
    Example: true
  • outputImageCount (integer): Number of output images to generate (range: 1 to 4).
    Example: 1
  • schedulingMethod (string): Method for scheduling the image generation process (default: "K_EULER").
    Example: "K_EULER"

Example Input

Here is a practical example of the JSON payload required to invoke the action:

{
  "refineMode": "no_refiner",
  "inputPrompt": "a hand-drawn TOK fantasy game wallpaper, a green sunrise",
  "outputWidth": 1344,
  "outputHeight": 768,
  "loraIntensity": 0.6,
  "noiseFraction": 0.8,
  "promptIntensity": 0.8,
  "watermarkStatus": true,
  "outputImageCount": 1,
  "schedulingMethod": "K_EULER",
  "guidanceIntensity": 7.5,
  "inferenceStepCount": 50,
  "negativeInputPrompt": "realistic, highly detailed, single color, messy, centered, frame, border line, deformed, mutated, disfigured"
}

Output

The action typically returns a URL to the generated image. Here’s an example output:

[
  "https://assets.cognitiveactions.com/invocations/56f40076-7ade-4ce0-a475-1eda6efa3e51/80a0d1e3-6c8f-442c-a1b3-81f8747b5e3b.png"
]

Conceptual Usage Example (Python)

Here’s a conceptual Python code snippet illustrating how you can call the Generate Enhanced 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 = "b1381252-03bf-49b9-8754-2bd4b12bae06"  # Action ID for Generate Enhanced Image

# Construct the input payload based on the action's requirements
payload = {
    "refineMode": "no_refiner",
    "inputPrompt": "a hand-drawn TOK fantasy game wallpaper, a green sunrise",
    "outputWidth": 1344,
    "outputHeight": 768,
    "loraIntensity": 0.6,
    "noiseFraction": 0.8,
    "promptIntensity": 0.8,
    "watermarkStatus": true,
    "outputImageCount": 1,
    "schedulingMethod": "K_EULER",
    "guidanceIntensity": 7.5,
    "inferenceStepCount": 50,
    "negativeInputPrompt": "realistic, highly detailed, single color, messy, centered, frame, border line, deformed, mutated, disfigured"
}

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 code snippet, you'll notice how the action ID and the structured input payload are integrated. The endpoint URL and request structure provided are illustrative, focusing on the concept of invoking the Cognitive Actions API.

Conclusion

Integrating the Generate Enhanced Image action from the Ending Scene Cognitive Actions can dramatically enhance the image processing capabilities of your applications. By utilizing its various parameters, you can create tailored image outputs that align with specific creative visions. Explore the possibilities and consider how this action can fit into your next project!