Enhance Your Images with the Real-ESRGAN Cognitive Action

21 Apr 2025
Enhance Your Images with the Real-ESRGAN Cognitive Action

In the world of image processing, enhancing and upscaling images can significantly improve visual quality and user experience. The Real-ESRGAN Cognitive Action allows developers to easily integrate advanced image enhancement capabilities into their applications. This action uses state-of-the-art algorithms to upscale images while preserving and improving details, particularly useful for facial features. With options to scale images and enhance faces, integrating this functionality can elevate your app's visual performance.

Prerequisites

Before you start using the Real-ESRGAN Cognitive Action, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Basic knowledge of making API calls and handling JSON payloads.
  • A valid URL pointing to an image file that you want to enhance and upscale.

Authentication typically involves passing your API key in the request headers to identify and authorize your access to the Cognitive Actions API.

Cognitive Actions Overview

Enhance and Upscale Image

The Enhance and Upscale Image action is designed to improve the quality of images by scaling them up and enhancing details, particularly for faces. This action can scale images by a factor between 0 and 10, with an optional face enhancement feature using the GFPGAN model.

Input

The input schema for this action requires an object with the following properties:

  • image (required): A string containing the URI of the input image to be processed. This must be a valid URL pointing to an image file.
  • scale (optional): A number that specifies the factor by which to scale the image. The value must be between 0 and 10, with a default of 4.
  • faceEnhance (optional): A boolean that enables GFPGAN face enhancement during the upscaling process. The default value is false.

Here is an example of a valid input JSON payload:

{
  "image": "https://replicate.delivery/pbxt/JM6ZAcEVtcieXxez7qCZG8E4pnq7wGH1YX7YgJH9F5sTpsFc/keanu.jpeg",
  "scale": 4,
  "faceEnhance": true
}

Output

The action typically returns a URL pointing to the enhanced and upscaled image. Here’s an example of the output you might receive:

https://assets.cognitiveactions.com/invocations/3e10a8a0-2d28-4443-9080-39f147d787e9/7426e46a-0d50-4e68-a06c-d7c352982f09.png

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet that demonstrates how you might call the Enhance and Upscale 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 = "f1854b1a-055a-4926-a9ea-50ca2f579a62"  # Action ID for Enhance and Upscale Image

# Construct the input payload based on the action's requirements
payload = {
    "image": "https://replicate.delivery/pbxt/JM6ZAcEVtcieXxez7qCZG8E4pnq7wGH1YX7YgJH9F5sTpsFc/keanu.jpeg",
    "scale": 4,
    "faceEnhance": true
}

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 specifies the Enhance and Upscale Image action.
  • The payload is structured according to the action's input requirements.
  • The endpoint URL and request structure are illustrative; you may need to adjust them based on the actual API specification.

Conclusion

The Real-ESRGAN Cognitive Action provides powerful capabilities for enhancing and upscaling images, making it an excellent tool for developers looking to improve the visual quality of their applications. With features like adjustable scaling and facial enhancement, you can create stunning visuals that enhance user engagement.

Consider experimenting with this action in your projects to see how it can transform your images and elevate your application's performance. Happy coding!