Enhance Your Application's Visuals: Integrating Tiled Image Upscaling with PLKSR

23 Apr 2025
Enhance Your Application's Visuals: Integrating Tiled Image Upscaling with PLKSR

In the world of image processing, enhancing the quality of images while maintaining efficiency is crucial for developers. The ocg2347/plksr-tiled-lowvram API offers a powerful Cognitive Action specifically designed for this purpose: Perform Tiled Image Upscaling with PLKSR. This action allows developers to upscale images effectively by executing a tiled inference implementation of the PLKSR model, optimized for various image types and dimensions. By leveraging this pre-built solution, applications can deliver high-quality visual content with minimal resource overhead.

Prerequisites

Before you can start integrating the Cognitive Actions from the ocg2347/plksr-tiled-lowvram API, ensure you have the following:

  • An API key for the Cognitive Actions platform.
  • Basic understanding of making HTTP requests and handling JSON data.

To authenticate your requests, you will typically pass your API key in the headers of your HTTP requests.

Cognitive Actions Overview

Perform Tiled Image Upscaling with PLKSR

This action is designed to execute a tiled inference implementation of the PLKSR model for image upscaling. It supports different image types—general, outdoor, and portrait—applying specific models to optimize super-resolution based on the provided parameters.

Input

The input for this action is structured as follows:

  • image (string, required): The URI of the image to be processed. Must be a valid URL.
  • imageType (string, optional): The category of the image. Options are 'general', 'portrait', or 'outdoor'. Default is 'general'.
  • tileWidth (integer, optional): Width of each tile in pixels. Options include 128, 256, 512, or 1024. Default is 256.
  • tileHeight (integer, optional): Height of each tile in pixels. Options include 128, 256, 512, or 1024. Default is 256.
  • scaleFactor (integer, optional): Scaling factor for the image in all dimensions, must be between 1 and 4. Default is 4.
  • tileOverlap (integer, optional): Number of overlapping pixels between tiles. Options are 32, 64, or 128. Default is 32.

Here’s an example of the input JSON payload:

{
  "image": "https://replicate.delivery/pbxt/MS5ByHEEA9rxVeDv8sPaiPhfsBnyegXry5xl6podPKW26M6Y/lion1.png",
  "imageType": "general",
  "tileWidth": 512,
  "tileHeight": 512,
  "scaleFactor": 4,
  "tileOverlap": 64
}

Output

The action returns a URL to the upscaled image. For example:

https://assets.cognitiveactions.com/invocations/e79d600c-dbca-4ef1-871b-2c8e7aecbe7c/aa8507e1-6a1d-4dd4-a061-0064b7ff6d83.jpeg

This output is a direct link to the processed image, ready to be used in your application or displayed to users.

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet illustrating how to invoke this Cognitive Action. The example demonstrates how to structure the input JSON payload and make the request to the Cognitive Actions endpoint.

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 = "f8ea3a8d-cce0-41ec-b6e8-a5092c983924" # Action ID for Perform Tiled Image Upscaling with PLKSR

# Construct the input payload based on the action's requirements
payload = {
    "image": "https://replicate.delivery/pbxt/MS5ByHEEA9rxVeDv8sPaiPhfsBnyegXry5xl6podPKW26M6Y/lion1.png",
    "imageType": "general",
    "tileWidth": 512,
    "tileHeight": 512,
    "scaleFactor": 4,
    "tileOverlap": 64
}

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:

  • Replace "YOUR_COGNITIVE_ACTIONS_API_KEY" with your actual API key.
  • The action_id corresponds to the ID for the Tiled Image Upscaling action.
  • The payload variable contains the necessary inputs structured according to the action's requirements.
  • The response from the API call will contain the URL to the upscaled image, which you can then utilize as needed.

Conclusion

The Perform Tiled Image Upscaling with PLKSR action from the ocg2347/plksr-tiled-lowvram API offers a robust solution for enhancing image quality with minimal resource requirements. By integrating this Cognitive Action, developers can significantly improve the visual appeal of their applications. Consider exploring other use cases, such as batch processing or integrating with user-uploaded images, to leverage the full potential of this action. Start enhancing your application’s visuals today!