Enhance Your Images with Canny Edges: Integrating the Adirik T2I-Adapter

In today's digital landscape, image processing plays a critical role in content creation and editing. The Adirik T2I-Adapter based on Stable Diffusion-XL offers powerful capabilities for modifying images using Cognitive Actions. One of its standout features is the ability to enhance images by assessing canny edges, allowing for a more refined and controlled editing experience. By integrating these pre-built actions into your application, you can leverage advanced image manipulation techniques with ease.
Prerequisites
To use the Cognitive Actions provided by the Adirik T2I-Adapter, you'll need an API key for the platform. Authentication typically involves passing this API key in the request headers. Ensure you have set up your development environment to make HTTP requests, such as using the requests library in Python.
Cognitive Actions Overview
Modify Image with Canny Edges
The Modify Image with Canny Edges action allows developers to enhance image editing by utilizing canny edge detection alongside other parameters like depth maps and text prompts. This capability aligns internal model knowledge with external control signals, making it ideal for precise image editing tasks.
Input
The input for this action requires a structured JSON object, detailed below:
| Field | Type | Required | Description | Example |
|---|---|---|---|---|
image | string | Yes | The URI of the input image to be processed. | https://replicate.delivery/pbxt/Jbn8dWczMIyZiWFABt3p78K3mSEwR1d7LK6LQ8KqUyKuBPYd/org_canny.jpg |
prompt | string | No | Text prompt to guide the image generation (defaults to a predefined value). | Mystical fairy in real, magic, 4k picture, high quality |
scheduler | string | No | Algorithm for image generation (defaults to K_EULER_ANCESTRAL). | K_EULER_ANCESTRAL |
randomSeed | integer | No | Random seed for reproducibility; leave blank to randomize output. | 42 |
guidanceScale | number | No | Level of adherence to the prompt, ranging from 0 to 10 (defaults to 7.5). | 7.5 |
negativePrompt | string | No | List of elements to avoid in the generated output. | extra digit, fewer digits, cropped, worst quality, low quality |
numberOfSamples | integer | No | Specifies number of image samples to generate (1 to 4, defaults to 1). | 1 |
numberOfInferenceSteps | integer | No | Number of diffusion steps for image generation (0 to 100, defaults to 30). | 30 |
adapterConditioningScale | number | No | Conditioning scale during the adaptation process (0 to 5, defaults to 0.8). | 0.8 |
adapterConditioningFactor | number | No | Factor by which the image adaptation is scaled (0 to 1, defaults to 1). | 1 |
Example Input:
{
"image": "https://replicate.delivery/pbxt/Jbn8dWczMIyZiWFABt3p78K3mSEwR1d7LK6LQ8KqUyKuBPYd/org_canny.jpg",
"prompt": "Mystical fairy in real, magic, 4k picture, high quality",
"scheduler": "K_EULER_ANCESTRAL",
"guidanceScale": 7.5,
"negativePrompt": "extra digit, fewer digits, cropped, worst quality, low quality, glitch, deformed, mutated, ugly, disfigured",
"numberOfSamples": 1,
"numberOfInferenceSteps": 30,
"adapterConditioningScale": 0.8,
"adapterConditioningFactor": 1
}
Output
The output from this action will typically return an array of processed image URIs. Here’s a sample output:
[
"https://assets.cognitiveactions.com/invocations/515d7017-55c0-4a76-a99f-b064ecf3a666/06fbecaa-bfcc-4e9c-9dd6-73d4adcd105d.png",
"https://assets.cognitiveactions.com/invocations/515d7017-55c0-4a76-a99f-b064ecf3a666/a65e129a-5603-401c-b21b-a71bbe7a701b.png"
]
Conceptual Usage Example (Python):
Here’s how you might call the Modify Image with Canny Edges 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 = "637631d5-270a-4aeb-86a5-2db4d0112c33" # Action ID for Modify Image with Canny Edges
# Construct the input payload based on the action's requirements
payload = {
"image": "https://replicate.delivery/pbxt/Jbn8dWczMIyZiWFABt3p78K3mSEwR1d7LK6LQ8KqUyKuBPYd/org_canny.jpg",
"prompt": "Mystical fairy in real, magic, 4k picture, high quality",
"scheduler": "K_EULER_ANCESTRAL",
"guidanceScale": 7.5,
"negativePrompt": "extra digit, fewer digits, cropped, worst quality, low quality, glitch, deformed, mutated, ugly, disfigured",
"numberOfSamples": 1,
"numberOfInferenceSteps": 30,
"adapterConditioningScale": 0.8,
"adapterConditioningFactor": 1
}
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, you replace the action ID and input payload with those specific to the Modify Image with Canny Edges action. The endpoint URL and the overall structure are illustrative, demonstrating how you might interact with the Cognitive Actions API.
Conclusion
The Adirik T2I-Adapter's Modify Image with Canny Edges action provides developers with a robust tool for enhancing image quality and precision in editing. By leveraging this and other Cognitive Actions, you can elevate your applications with advanced image processing capabilities. As you explore these features, consider various use cases such as automated content creation, graphic design, or enhancing user-generated content. Happy coding!