Enhance Your Applications with Photo-Realistic Image Quality Using SUPIR-v0Q

In the realm of image processing, enhancing the quality of images can significantly improve user experience and application outcomes. The SUPIR-v0Q Cognitive Actions provide a powerful toolset designed to scale and restore photo-realistic images, ensuring high quality and generalization. By integrating these Cognitive Actions into your applications, you can easily enhance low-quality images, making them suitable for various use cases—from personal projects to commercial applications.
Prerequisites
Before diving into the integration of the SUPIR-v0Q Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform.
- Basic knowledge of making HTTP requests and handling JSON data.
- Familiarity with image processing concepts can be helpful.
To authenticate with the Cognitive Actions API, you will typically pass your API key in the headers of your requests.
Cognitive Actions Overview
Enhance Photo-Realistic Image Quality
The Enhance Photo-Realistic Image Quality action utilizes the SUPIR-v0Q model to enhance photo-realistic images, making them clearer and more detailed. This action falls under the image-enhancement category.
Input
The input requires a structured JSON object with the following fields:
- image (required): URL of the input image (low quality) in URI format.
- seed (optional): Specifies a random seed for reproducibility.
- upscale (optional): The ratio for upsampling the image (default is 1).
- churnRate (optional): Hyperparameter for the EDM algorithm (default is 5).
- noiseLevel (optional): Noise level hyperparameter in the EDM process (default is 1.003).
- guidanceScale (optional): Classifier-free guidance scale for prompts (default is 7.5).
- samplingSteps (optional): Number of steps for the EDM sampling schedule (default is 50).
- linearGuidance (optional): Determines if CFG linearly increases with sigma (default is false).
- linearStageTwo (optional): Indicates if 's_stage2' linearly increases with sigma (default is false).
- negativePrompt (optional): Defines elements to exclude from the inputs.
- positivePrompt (optional): Defines favorable elements to emphasize in the inputs.
- stageOneStrength (optional): Controls the strength of Stage 1 processing (default is -1).
- stageTwoStrength (optional): Controls the strength of Stage 2 processing (default is 1).
- minimumResolution (optional): Sets the minimum resolution for output images (default is 1024 pixels).
- startPointGuidance (optional): Initial starting point for increasing CFG linearly with sigma (default is 1).
- startPointStageTwo (optional): Initial starting point for increasing 's_stage2' linearly with sigma (default is 0).
- colorCorrectionType (optional): Specifies the method for color correction (default is 'Wavelet').
Here’s an example input JSON payload:
{
"image": "https://replicate.delivery/pbxt/KSFlHUahItvQz4u9IZ9JZCQgra7IcGze7MLBsAQtl6isttyr/05.png",
"upscale": 1,
"churnRate": 5,
"noiseLevel": 1.003,
"guidanceScale": 7.5,
"samplingSteps": 50,
"linearGuidance": false,
"linearStageTwo": false,
"negativePrompt": "painting, oil painting, illustration, drawing, art, sketch, oil painting, cartoon, CG Style, 3D render, unreal engine, blurring, dirty, messy, worst quality, low quality, frames, watermark, signature, jpeg artifacts, deformed, lowres, over-smooth",
"positivePrompt": "Cinematic, High Contrast, highly detailed, taken using a Canon EOS R camera, hyper detailed photo - realistic maximum detail, 32k, Color Grading, ultra HD, extreme meticulous detailing, skin pore detailing, hyper sharpness, perfect without deformations.",
"stageOneStrength": -1,
"stageTwoStrength": 1,
"minimumResolution": 1024,
"startPointGuidance": 1,
"startPointStageTwo": 0,
"colorCorrectionType": "Wavelet"
}
Output
When the action is executed successfully, it typically returns a URL pointing to the enhanced image. For instance:
https://assets.cognitiveactions.com/invocations/73199a57-ceaf-4e41-9100-5a545346a468/7b37ff02-408a-4b1a-95d3-40963f41c422.png
Conceptual Usage Example (Python)
Here’s how you might call the Enhance Photo-Realistic Image Quality action using Python:
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 = "82c77e01-0f66-43be-815d-df3584460028" # Action ID for Enhance Photo-Realistic Image Quality
# Construct the input payload based on the action's requirements
payload = {
"image": "https://replicate.delivery/pbxt/KSFlHUahItvQz4u9IZ9JZCQgra7IcGze7MLBsAQtl6isttyr/05.png",
"upscale": 1,
"churnRate": 5,
"noiseLevel": 1.003,
"guidanceScale": 7.5,
"samplingSteps": 50,
"linearGuidance": False,
"linearStageTwo": False,
"negativePrompt": "painting, oil painting, illustration, drawing, art, sketch, oil painting, cartoon, CG Style, 3D render, unreal engine, blurring, dirty, messy, worst quality, low quality, frames, watermark, signature, jpeg artifacts, deformed, lowres, over-smooth",
"positivePrompt": "Cinematic, High Contrast, highly detailed, taken using a Canon EOS R camera, hyper detailed photo - realistic maximum detail, 32k, Color Grading, ultra HD, extreme meticulous detailing, skin pore detailing, hyper sharpness, perfect without deformations.",
"stageOneStrength": -1,
"stageTwoStrength": 1,
"minimumResolution": 1024,
"startPointGuidance": 1,
"startPointStageTwo": 0,
"colorCorrectionType": "Wavelet"
}
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 with your actual API key, and note that the endpoint URL and request structure are illustrative. The action ID and input payload must be structured correctly for successful execution.
Conclusion
The SUPIR-v0Q Cognitive Actions empower developers to enhance image quality seamlessly, making it an invaluable tool for applications requiring high-resolution visuals. By leveraging these actions, you can significantly improve the quality of images in your projects, whether for personal use or commercial deployment. Explore other potential use cases such as image restoration, enhancement for digital art, or even improving user-generated content. Integrate these actions today to elevate your application’s image processing capabilities!