Enhance and Upscale Your Images with Real Esrgan

25 Apr 2025
Enhance and Upscale Your Images with Real Esrgan

In the digital age, the demand for high-quality images continues to grow, whether for marketing materials, personal projects, or enhancing visual content on websites. The Real Esrgan service offers powerful Cognitive Actions designed to enhance and upscale images effortlessly. Utilizing advanced algorithms, Real Esrgan not only improves image resolution but also provides optional face correction and customizable scaling options. This makes it an ideal solution for developers looking to integrate image enhancement capabilities into their applications.

Prerequisites

To get started with Real Esrgan, you'll need an API key for the Cognitive Actions service and a basic understanding of making API calls.

Enhance and Upscale Image with Real-ESRGAN

The "Enhance and Upscale Image with Real-ESRGAN" action is engineered to elevate the quality of images by increasing their resolution while preserving and even enhancing details. This action solves the common problem of low-resolution images that appear pixelated or blurry when enlarged, making it particularly useful for photographers, graphic designers, and marketers.

Input Requirements

To use this action, you will need to provide the following input parameters:

  • Image: A URI pointing to the input image (this parameter is mandatory).
  • Scale: A numeric value that indicates the factor by which to upscale the image (default is 4, with a range from 0 to 10).
  • Face Enhance: A boolean flag that determines whether to enhance faces within the image (default is true).

Example Input:

{
  "image": "https://replicate.delivery/pbxt/JBn4y1EkUjdlMlqNT14CJ8O9YYlogntF70PAjMYSmuK5wEmu/output.png",
  "scale": 2,
  "faceEnhance": false
}

Expected Output

The action will return a URI that links to the enhanced and upscaled image, allowing for easy integration into your projects.

Example Output:

https://assets.cognitiveactions.com/invocations/b34f3d44-c1ae-46f4-a26b-8a21bc9360e2/7dafa2f7-27e2-4a2d-b586-62aac30738f0.png

Use Cases for this Action

  • Photography Enhancements: Photographers can upscale their images for prints or online portfolios without sacrificing quality.
  • Marketing Materials: Marketers can ensure that images used in promotional content are sharp and visually appealing.
  • Web Development: Developers can enhance images for websites, improving load quality and user experience.
  • Face-Centric Applications: Applications that focus on portraits or facial recognition can benefit from the face enhancement feature, ensuring that facial details are clear and prominent.
import requests
import json

# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"

action_id = "81ee519e-cf80-44d6-9f48-8a2c802f5e42" # Action ID for: Enhance and Upscale Image with Real-ESRGAN

# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
  "image": "https://replicate.delivery/pbxt/JBn4y1EkUjdlMlqNT14CJ8O9YYlogntF70PAjMYSmuK5wEmu/output.png",
  "scale": 2,
  "faceEnhance": false
}

headers = {
    "Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
    "Content-Type": "application/json",
    # Add any other required headers for the Cognitive Actions API
}

# Prepare the request body for the hypothetical execution endpoint
request_body = {
    "action_id": action_id,
    "inputs": payload
}

print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")

try:
    response = requests.post(
        COGNITIVE_ACTIONS_EXECUTE_URL,
        headers=headers,
        json=request_body
    )
    response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)

    result = response.json()
    print("Action executed successfully. Result:")
    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 (non-JSON): {e.response.text}")
    print("------------------------------------------------")

Conclusion

The Real Esrgan service provides developers with an invaluable tool for enhancing and upscaling images, making it easier to deliver high-quality visual content. With its customizable options and powerful processing capabilities, this action is perfect for a wide range of applications, from photography to web development. Start integrating Real Esrgan into your projects today and elevate your image quality to new heights!