Enhance Your Images with InvSR Cognitive Actions: A Developer's Guide

22 Apr 2025
Enhance Your Images with InvSR Cognitive Actions: A Developer's Guide

In the world of image processing, high-quality visuals can make a significant difference in user engagement and experience. The InvSR Cognitive Actions provide a powerful way to elevate your low-quality images to high-resolution masterpieces using advanced algorithms. By leveraging the capabilities of the InvSR model, developers can integrate image super-resolution via diffusion inversion into their applications, enhancing image quality while considering performance trade-offs.

In this blog post, we'll explore how to utilize the Perform Image Super-resolution via Diffusion Inversion action, including how to set it up, the input and output requirements, and a conceptual usage example in Python.

Prerequisites

To get started with Cognitive Actions, you'll need:

  • An API key for the Cognitive Actions platform, which allows you to authenticate your requests.
  • Familiarity with making HTTP requests and handling JSON data.

Authentication typically involves passing your API key in the request headers. Ensure you keep your API key secure and do not expose it in front-end code or public repositories.

Cognitive Actions Overview

Perform Image Super-resolution via Diffusion Inversion

This action generates high-quality, high-resolution images from low-quality inputs using the InvSR model. It applies arbitrary-steps image super-resolution through diffusion inversion, improving image quality, although it may increase inference time and may not preserve perfect detail in complex scenarios. This action falls under the category of image-enhancement.

Input

The input for this action requires a JSON object conforming to the following schema:

  • inputPath (string, required): The URI of the low-quality input image.
  • seed (integer, optional): Specifies the random seed value. Default is 12345.
  • numberOfSteps (integer, optional): Specifies the number of sampling steps to be taken. The default value is 1, with a maximum of 5.
  • choppingResolution (integer, optional): Determines the resolution for chopping. Possible values are 128, 256, or 512, with a default of 128.

Example Input:

{
  "seed": 12345,
  "inputPath": "https://replicate.delivery/pbxt/M8qhJrY5aD7tG40HumHd3gIIR3LXjMKThkOCNB1oSfGrimcu/32.jpg",
  "numberOfSteps": 1,
  "choppingResolution": 128
}

Output

Upon successful execution, the action returns a URL pointing to the high-resolution image generated from the low-quality input. The output typically looks like this:

Example Output:

https://assets.cognitiveactions.com/invocations/96c7cf32-59c4-4f8d-bfd4-9767493de0a3/6cb398a6-d7ac-4ad1-9a34-10a90b99bb58.png

Conceptual Usage Example (Python)

Here's how you can call the Perform Image Super-resolution via Diffusion Inversion action using Python. This example illustrates how to structure the input payload and make a POST request to the Cognitive Actions API.

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 = "9729ff4e-2c57-4f99-b852-2cbaadf69bcf" # Action ID for Perform Image Super-resolution via Diffusion Inversion

# Construct the input payload based on the action's requirements
payload = {
    "seed": 12345,
    "inputPath": "https://replicate.delivery/pbxt/M8qhJrY5aD7tG40HumHd3gIIR3LXjMKThkOCNB1oSfGrimcu/32.jpg",
    "numberOfSteps": 1,
    "choppingResolution": 128
}

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:

  • Replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key.
  • The action_id variable contains the ID for the super-resolution action.
  • We construct the input payload using the schema provided and send it to the API endpoint.

Conclusion

The InvSR Cognitive Actions provide a robust solution for enhancing image quality through super-resolution techniques. By integrating the Perform Image Super-resolution via Diffusion Inversion action into your applications, you can effortlessly transform low-quality images into stunning visuals.

Consider exploring other use cases for image enhancement in your projects. Whether it's for improving product images, enhancing user-uploaded photos, or creating visually appealing content, the possibilities are endless. Happy coding!