Enhance Image Quality with neurowelt/keros-diffusion Cognitive Actions

22 Apr 2025
Enhance Image Quality with neurowelt/keros-diffusion Cognitive Actions

In the world of image generation and manipulation, the neurowelt/keros-diffusion API opens the door to a plethora of creative possibilities. With its powerful Cognitive Actions, developers can enhance and manipulate images using advanced techniques such as Stable Diffusion XL. This article will guide you through the capabilities of these actions, providing a clear understanding of how to integrate them into your applications for improved image quality, detail, and artistic effects.

Prerequisites

Before you dive into using the Cognitive Actions, there are a few prerequisites to keep in mind:

  • API Key: You will need an API key to access the neurowelt/keros-diffusion Cognitive Actions platform. Ensure to register and obtain your key.
  • Setup: Familiarize yourself with how to authenticate your requests by passing the API key in the headers.

Authentication typically involves including the API key in the request headers. This allows you to securely access the Cognitive Actions services.

Cognitive Actions Overview

Control Stable Diffusion XL Inference

The Control Stable Diffusion XL Inference action allows developers to enhance and manipulate images by adjusting various parameters. This action is particularly useful for creating high-quality artistic images or improving existing ones by modifying aspects such as richness, contrast, texture, and more.

Input

The input schema for this action includes a variety of fields:

  • mask: (string) Input mask for inpaint mode (URI format).
  • seed: (integer) Random seed (optional).
  • focus: (number) Adjusts image sharpness (range: 0 to 0.5).
  • image: (string) Input image for manipulation (URI format).
  • width: (integer) Width of the output image (default: 1024).
  • height: (integer) Height of the output image (default: 1024).
  • prompt: (string) Descriptive text guiding the image generation (default: "An astronaut riding a rainbow unicorn").
  • refine: (string) Specifies the refine strategy (default: "no_refiner").
  • texture: (number) Controls the texture of the image (default: 1).
  • contrast: (number) Adjusts the image contrast (default: 1).
  • richness: (number) Controls the detail and complexity (default: 1.3).
  • variance: (number) Affects how other parameters operate (default: 0.1).
  • background: (number) Affects background visibility (default: 0.25).
  • guidanceScale: (number) Scale for classifier-free guidance (default: 9).
  • applyWatermark: (boolean) Applies a watermark to the generated image (default: true).
  • negativePrompt: (string) Input for negative prompting (optional).
  • promptStrength: (number) Strength of the prompt (default: 0.8).
  • numberOfOutputs: (integer) Number of images to output (default: 1).
  • numberOfInferenceSteps: (integer) Number of denoising steps (default: 50).

Here is an example input payload:

{
  "focus": 0,
  "width": 1024,
  "height": 1024,
  "prompt": "psychedelic Obama wizard in Chernobyl, nuclear fallout, Hasserblad",
  "refine": "no_refiner",
  "texture": 1,
  "contrast": 1,
  "richness": 1.3,
  "variance": 0.1,
  "background": 0.25,
  "guidanceScale": 9,
  "applyWatermark": true,
  "negativePrompt": "",
  "promptStrength": 0.8,
  "numberOfOutputs": 1,
  "numberOfInferenceSteps": 50
}

Output

Upon successful execution, the action returns a URL pointing to the generated image. For example:

[
  "https://assets.cognitiveactions.com/invocations/a2a8c88e-313b-4576-8894-ce59a163920d/db32622e-7970-49ae-aa1b-d6a766c46402.png"
]

Conceptual Usage Example (Python)

Here's a conceptual example of how you might call the Control Stable Diffusion XL Inference action using Python:

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 = "06e6c818-a074-4977-83d0-d84077ef3029"  # Action ID for Control Stable Diffusion XL Inference

# Construct the input payload based on the action's requirements
payload = {
    "focus": 0,
    "width": 1024,
    "height": 1024,
    "prompt": "psychedelic Obama wizard in Chernobyl, nuclear fallout, Hasserblad",
    "refine": "no_refiner",
    "texture": 1,
    "contrast": 1,
    "richness": 1.3,
    "variance": 0.1,
    "background": 0.25,
    "guidanceScale": 9,
    "applyWatermark": True,
    "negativePrompt": "",
    "promptStrength": 0.8,
    "numberOfOutputs": 1,
    "numberOfInferenceSteps": 50
}

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 example, replace "YOUR_COGNITIVE_ACTIONS_API_KEY" with your actual API key. The action ID and input payload are structured according to the specifications for the Control Stable Diffusion XL Inference action.

Conclusion

The neurowelt/keros-diffusion Cognitive Actions provide powerful tools for developers looking to enhance images through advanced manipulation techniques. By leveraging these actions, you can create stunning visuals tailored to your application's needs. Explore further by experimenting with different parameters to discover the potential of image generation in your projects!