Enhance Your Images with the prakharsaxena24/masked-upscaler Cognitive Action

25 Apr 2025
Enhance Your Images with the prakharsaxena24/masked-upscaler Cognitive Action

In the ever-evolving world of digital images, enhancing and upscaling visuals is a crucial task for developers aiming to provide users with high-quality content. The prakharsaxena24/masked-upscaler offers a powerful Cognitive Action that allows developers to upscale specific areas of an image using customizable settings. This article will guide you through the capabilities of this action, helping you integrate it seamlessly into your applications.

Prerequisites

Before you begin using the Cognitive Actions, ensure you have the following:

  • An API key for the Cognitive Actions platform, which you will use to authenticate your requests.
  • Familiarity with making HTTP requests and handling JSON payloads in your preferred programming language.

Authentication typically involves including the API key in the headers of your requests, allowing secure access to the actions.

Cognitive Actions Overview

Upscale Selected Image Area

This action enables you to perform upscaling and detailing on a specific area of an image while allowing customization such as scale factor and variation seeds. Importantly, you can designate areas that should not be upscaled using a mask.

  • Category: Image Enhancement
  • Purpose: Enhance specific sections of images while preserving the quality of untouched areas.

Input

The input for this action requires the following fields:

{
  "image": "https://replicate.delivery/pbxt/L293tzfx8WiFQQrLRxPMwRwMZHzi9Bs5a1mUOgwySqf77men/img5a21b4bd1c924b0ba6d04f1c75ced25d.png",
  "mask": "https://replicate.delivery/pbxt/L293tY1UNaSlq01zA1VCCkNyv49jD4Ab3QrMau376xUON56q/inverse_image_mask.png",
  "seed": 42,
  "scaleFactor": 2,
  "numInferenceSteps": 20,
  "prompt": "masterpiece, best quality, highres, <lora:more_details:0.5> <lora:SDXLrender_v2.0:1>"
}
  • Required Fields:
    • image: URI of the input image to be processed.
  • Optional Fields:
    • mask: URI pointing to a mask image that designates areas not to be upscaled.
    • seed: Random seed value for variations (default is 42).
    • scaleFactor: Factor by which to upscale the image (default is 2).
    • numInferenceSteps: Steps for processing inference, ranging from 1 to 100 (default is 20).
    • prompt: Text prompt guiding the image processing, default includes artistic elements.

Output

Upon successful execution, the action typically returns a URL to the upscaled image:

[
  "https://assets.cognitiveactions.com/invocations/e1d2268e-4323-4c39-9d3a-d3ab1eb275c6/e3b6edad-d588-4a3e-b1ac-a546e8c023bc.png"
]

This URL points to the processed image that reflects the applied enhancements.

Conceptual Usage Example (Python)

Here’s a conceptual Python example demonstrating how to invoke the Upscale Selected Image Area 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 = "88209241-53d7-4bef-a878-2e9fdf4d9d43" # Action ID for Upscale Selected Image Area

# Construct the input payload based on the action's requirements
payload = {
    "mask": "https://replicate.delivery/pbxt/L293tY1UNaSlq01zA1VCCkNyv49jD4Ab3QrMau376xUON56q/inverse_image_mask.png",
    "seed": 42,
    "image": "https://replicate.delivery/pbxt/L293tzfx8WiFQQrLRxPMwRwMZHzi9Bs5a1mUOgwySqf77men/img5a21b4bd1c924b0ba6d04f1c75ced25d.png",
    "prompt": "masterpiece, best quality, highres, <lora:more_details:0.5> <lora:SDXLrender_v2.0:1>",
    "scaleFactor": 2,
    "numInferenceSteps": 20
}

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 the COGNITIVE_ACTIONS_API_KEY and COGNITIVE_ACTIONS_EXECUTE_URL with your actual API key and endpoint. The action ID and input payload are structured according to the specifications provided.

Conclusion

The prakharsaxena24/masked-upscaler Cognitive Action provides an effective way to enhance images with precision. By utilizing this action, developers can create visually stunning applications that leverage advanced image processing techniques. Whether you’re upscaling images for a gallery, enhancing photographs, or optimizing visuals for user engagement, this action opens up new possibilities in image enhancement. Start integrating it into your projects and explore the creative potential it offers!