Enhance Your Images with the Magic Image Refiner

The Magic Image Refiner is a powerful tool designed for developers who want to elevate their image processing capabilities. By leveraging advanced cognitive actions, this service provides detailed quality improvements, including inpainting and upscaling, that significantly outperform standard refiners. Whether you’re working on enhancing images for e-commerce, social media, or any creative project, the Magic Image Refiner offers a streamlined solution that saves time and delivers impressive results.
Common use cases for the Magic Image Refiner include refining product images for online stores, enhancing visuals for digital marketing campaigns, or simply improving personal photos for sharing on social platforms. With its user-friendly API, developers can integrate this functionality into applications, ensuring high-quality images with minimal effort.
Prerequisites
To get started with the Magic Image Refiner, you will need a Cognitive Actions API key and a basic understanding of how to make API calls.
Enhance Image with Magic Refiner
The "Enhance Image with Magic Refiner" action is designed to refine images by applying detailed quality improvements. This action addresses the common challenges of image degradation and allows for targeted enhancements through inpainting and upscaling techniques.
Input Requirements
To utilize this action, you will need to provide the following inputs:
- Image: A URI pointing to the image that requires refinement.
- Prompt: A descriptive text prompt to guide the refinement process.
- Mask (optional): A URI for a mask image if you want to refine specific areas.
- Steps: The number of denoising steps to be performed (default is 20).
- Guess Mode: Enables automatic content recognition without prompts (default is false).
- Scheduler: Select from various options to control the refinement process (default is "DDIM").
- Creativity: A value indicating the strength of denoising (default is 0.25).
- Resolution: Specifies the output image resolution (default is "original").
- Resemblance: A conditioning scale for maintaining original image features (default is 0.75).
- Guidance Scale: A factor for classifier-free guidance (default is 7).
- HDR Improvement: A value indicating HDR enhancement (default is 0).
- Negative Prompt: A list of undesirable features to avoid in the refined image.
Expected Output
The expected output is a URI pointing to the refined image that showcases the enhancements made based on the input parameters.
Example Input
{
"image": "https://replicate.delivery/pbxt/KA9yP9n3ZX5A5mkoPz3gsPzKTH1NA7LqVkQRTg7Sov46lOfo/0_1.webp",
"steps": 20,
"prompt": "UHD 4k vogue, a woman resting in a magic pool, face above the surface of the water, red freckles",
"guessMode": false,
"scheduler": "DDIM",
"creativity": 0.25,
"resolution": "original",
"resemblance": 0.75,
"guidanceScale": 7,
"hdrImprovement": 0,
"negativePrompt": "teeth, tooth, open mouth, longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, mutant"
}
Example Output
[
"https://assets.cognitiveactions.com/invocations/4cc39261-77ec-4d5b-9290-f5675a650d1c/8a5f0f39-5920-4554-bdcf-a86c099dfde4.png"
]
Use Cases for this Specific Action
This action is particularly beneficial for:
- E-commerce: Improving product images to attract more customers and increase sales.
- Marketing: Enhancing visuals for advertisements or social media posts to improve engagement.
- Content Creation: Offering creators the ability to refine images for blogs, videos, or other media, elevating their overall presentation.
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 = "90ab8d7e-bbfd-465a-9fe8-585af83e3267" # Action ID for: Enhance Image with Magic Refiner
# 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/KA9yP9n3ZX5A5mkoPz3gsPzKTH1NA7LqVkQRTg7Sov46lOfo/0_1.webp",
"steps": 20,
"prompt": "UHD 4k vogue, a woman resting in a magic pool, face above the surface of the water, red freckles",
"guessMode": false,
"scheduler": "DDIM",
"creativity": 0.25,
"resolution": "original",
"resemblance": 0.75,
"guidanceScale": 7,
"hdrImprovement": 0,
"negativePrompt": "teeth, tooth, open mouth, longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, mutant"
}
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
The Magic Image Refiner provides developers with a robust tool to enhance images effortlessly while maintaining high quality. With its various input options and flexible output capabilities, it caters to a wide range of use cases, from marketing to personal projects. By integrating this service into your applications, you can ensure that your images stand out, making a lasting impression on your audience. Start refining your images today and unlock new possibilities in visual content creation!