Enhance Your Images with PLKSR: A Guide to Cognitive Actions Integration

23 Apr 2025
Enhance Your Images with PLKSR: A Guide to Cognitive Actions Integration

In today's digital landscape, enhancing image quality is crucial for applications in various fields, from e-commerce to social media. The ocg2347/plksr-tiled-lowvram Cognitive Actions provide developers with powerful tools to enhance images efficiently. These actions allow for tiled inference using the PLKSR model, which is tailored for general, outdoor, and portrait image types, ensuring high-quality upscaling with optimized resource usage. By leveraging these pre-built actions, developers can save time and focus on building robust applications without needing to dive deep into the intricacies of image processing.

Prerequisites

To get started with the Cognitive Actions, you will need an API key from the Cognitive Actions platform. This key will allow you to authenticate your requests. Typically, authentication is done by including the API key in the request headers. Ensure you have your API key ready for the steps ahead.

Cognitive Actions Overview

Enhance Image with PLKSR

The Enhance Image with PLKSR action is designed to perform tiled inference of PLKSR, enabling effective image enhancement. This action supports high-quality upscaling tailored specifically for different image categories.

Input

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

  • image (string, required): URI of the input image.
  • batchSize (integer, optional): Number of images processed simultaneously (default 8, range 1-64).
  • tileWidth (integer, optional): Width of each tile in pixels (default 512, options: 128, 256, 512, 1024).
  • tileHeight (integer, optional): Height of each tile in pixels (default 512, options: 128, 256, 512, 1024).
  • scaleFactor (integer, optional): Factor by which the image is scaled (default 4, range 1-4).
  • tileOverlap (integer, optional): Overlap size between tiles in pixels (default 64, options: 32, 64, 128).
  • imageCategory (string, optional): Category of the image (default "general", options: "general", "portrait", "outdoor").

Example Input:

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

Output

Upon execution, the action returns a URL to the enhanced image. The response will look something like this:

Example Output:

https://assets.cognitiveactions.com/invocations/b899c29a-1d16-4161-a321-144725d2f9bc/6a57d1d8-5f6f-4a97-8a54-39bd1ebdc9f3.png

Conceptual Usage Example (Python)

Below is a conceptual Python code snippet demonstrating how to execute the Enhance Image with PLKSR action. This example shows how to structure the input JSON payload correctly and handle the API request.

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 = "c5141caa-f6ae-48fe-b2f9-5d20167230da" # Action ID for Enhance Image with PLKSR

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

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 payload variable structures the input based on the action's requirements. The action_id variable represents the ID specific to the Enhance Image with PLKSR action.

Conclusion

The Enhance Image with PLKSR Cognitive Action provides an effective solution for developers looking to integrate high-quality image enhancement capabilities into their applications. With the flexibility to process images with various configurations, these actions can significantly improve the visual quality of images while optimizing resource usage.

Consider exploring other use cases where image enhancement can be applied in your projects, and start integrating the PLKSR Cognitive Actions today!