Enhance Your Images with Instructir's Restoration Actions

In the world of digital imagery, having the ability to restore and enhance images can significantly elevate the quality of visual content. Instructir provides developers with a powerful set of Cognitive Actions aimed at image restoration, enabling high-quality results using textual instructions. This innovative approach simplifies the restoration process by allowing users to specify exactly what modifications they want—be it removing noise, rain, or enhancing clarity—resulting in stunning images tailored to their needs.
With Instructir, developers can seamlessly integrate image restoration capabilities into their applications, enhancing user experiences across various industries. Common use cases include restoring old photographs, enhancing images for e-commerce, or improving visuals for marketing campaigns. By leveraging the power of human-written prompts, developers can achieve precision and quality that traditional image processing methods often lack.
Prerequisites
To get started with Instructir's Cognitive Actions, you'll need access to a Cognitive Actions API key and a basic understanding of making API calls.
Execute Image Restoration with InstructIR
The "Execute Image Restoration with InstructIR" action allows developers to perform advanced image restoration tasks guided by custom textual instructions. This action is particularly valuable for scenarios requiring high-quality results in denoising, deraining, deblurring, dehazing, and general image enhancement.
Input Requirements
To use this action, you need to provide:
- Image: A publicly accessible URI of the input image that you want to process. For example:
https://replicate.delivery/pbxt/KKLe7Hb195UNMS5JVasS3aRi21EF9Mz9Y9inDBdPaDeWZJXk/rain-020.png. - Prompt: A descriptive text prompt detailing the modifications needed, such as "please remove the rain drops, keep the rest untouched."
- Random Seed (optional): An integer to initialize the random number generator for consistent outputs.
Expected Output
The expected output is a URI pointing to the restored image. For example: https://assets.cognitiveactions.com/invocations/2b6b2fca-f147-4c3b-9708-6573096e74af/d235b16f-a683-4ba1-8d09-6d97bd2c257c.png.
Use Cases for this Action
- Old Photo Restoration: Bring back the vibrancy of aged photographs by removing unwanted artifacts while preserving the original details.
- E-commerce Image Enhancement: Improve product images by removing distractions like watermarks or background elements, resulting in a cleaner presentation.
- Content Creation: Enable creators to refine their images, making them more appealing for social media or marketing materials by addressing specific issues.
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 = "ee361318-02a4-496e-9357-4637a732acdd" # Action ID for: Execute Image Restoration with InstructIR
# 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/KKLe7Hb195UNMS5JVasS3aRi21EF9Mz9Y9inDBdPaDeWZJXk/rain-020.png",
"prompt": "please remove the rain drops, keep the rest untouched"
}
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
Instructir's image restoration capabilities offer developers a powerful tool to enhance and restore images with precision and ease. By harnessing the power of human-written prompts, you can create applications that deliver high-quality results tailored to user needs. Whether you’re working on photo restoration, e-commerce, or content creation, integrating these Cognitive Actions into your workflow can significantly improve the quality of your visual content. Start exploring the possibilities of image enhancement with Instructir today!