Enhance Your Images with Canny Edge Detection Using ControlNet Deliberate Actions

The philz1337x/controlnet-deliberate API offers developers a powerful way to modify images through advanced image processing techniques, specifically leveraging Canny edge detection with the Deliberate model. This integration allows for precise image generation based on Stable Diffusion (SD) 1.5, making it an excellent choice for applications requiring enhanced visual content.
Prerequisites
To utilize the Cognitive Actions provided by the ControlNet Deliberate API, you will need to set up an API key for authentication. This key should be included in the header of your requests to ensure secure access. Here’s a conceptual overview of how you might structure your authentication:
- API Key: A unique key that allows you to access the service.
- Authorization: Typically passed in headers as a Bearer token.
Cognitive Actions Overview
Modify Image with Canny Edge Detection
The Modify Image with Canny Edge Detection action uses the Canny edge detection technique combined with the Deliberate model. This action modifies images based on your input, allowing for detailed and precise output.
Category: image-processing
Input
The input schema requires the following fields:
- image (string, required): The URI of the input image to be processed.
- prompt (string, required): A text prompt guiding the model's output.
- seed (integer, optional): A random seed value for generating consistent results.
- scale (number, optional): Scale factor for classifier-free guidance (default: 9).
- weight (number, optional): Weight influencing the model's consideration of constraints (default: 1).
- negativePrompt (string, optional): Traits or objects to avoid in the output.
- numberOfSamples (string, optional): How many image samples to generate (default: "1").
- additionalPrompt (string, optional): Additional text to refine output.
- cannyLowThreshold (integer, optional): Lower threshold for Canny edge detection (default: 100).
- cannyHighThreshold (integer, optional): Upper threshold for Canny edge detection (default: 200).
- detectionResolution (integer, optional): Resolution for detection (default: 512).
- outputImageResolution (string, optional): Resolution for the generated image (default: "512").
- estimatedTimeToArrival (number, optional): Controls noise level during denoising diffusion (default: 0).
- deterministicDiffusionSteps (integer, optional): Number of deterministic diffusion steps (default: 20).
Example Input:
{
"seed": -67,
"image": "https://replicate.delivery/pbxt/IW3cOsyRN9tZv2fRDZa8XmtQJ9ni2f1mm14dQyhKgHjGQfuN/Nofretete_Neues_Museum.jpg",
"scale": 9,
"prompt": "RAW photo, portrait photo of 30 y.o woman queen, pale skin, slim body, (high detailed skin:1.2), background ocean, 8k uhd, dslr, soft lighting, high quality, film grain, Fujifilm XT3",
"weight": 0.6,
"negativePrompt": "longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality",
"numberOfSamples": "1",
"additionalPrompt": "best quality, extremely detailed",
"cannyLowThreshold": 100,
"cannyHighThreshold": 200,
"detectionResolution": 512,
"outputImageResolution": "512",
"deterministicDiffusionSteps": 20
}
Output
The action returns an array of URLs pointing to the generated image samples. An example output might look like this:
Example Output:
[
"https://assets.cognitiveactions.com/invocations/1ef02329-bc7b-4c51-9f51-9350ffa60f35/c618de26-53d8-4ab8-a523-42720977ae55.png",
"https://assets.cognitiveactions.com/invocations/1ef02329-bc7b-4c51-9f51-9350ffa60f35/9ff5528d-c2c0-4b17-9882-99b2aab06d1a.png"
]
Conceptual Usage Example (Python)
Here’s how you might call the Modify Image with Canny Edge Detection 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 = "e4bb303b-95ca-49f1-8963-822296a4cf46" # Action ID for Modify Image with Canny Edge Detection
# Construct the input payload based on the action's requirements
payload = {
"seed": -67,
"image": "https://replicate.delivery/pbxt/IW3cOsyRN9tZv2fRDZa8XmtQJ9ni2f1mm14dQyhKgHjGQfuN/Nofretete_Neues_Museum.jpg",
"scale": 9,
"prompt": "RAW photo, portrait photo of 30 y.o woman queen, pale skin, slim body, (high detailed skin:1.2), background ocean, 8k uhd, dslr, soft lighting, high quality, film grain, Fujifilm XT3",
"weight": 0.6,
"negativePrompt": "longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality",
"numberOfSamples": "1",
"additionalPrompt": "best quality, extremely detailed",
"cannyLowThreshold": 100,
"cannyHighThreshold": 200,
"detectionResolution": 512,
"outputImageResolution": "512",
"deterministicDiffusionSteps": 20
}
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, we set up the API call to execute the Modify Image with Canny Edge Detection action. The action ID and input payload are populated according to the required schema. The endpoint URL and request structure are illustrative and should be adapted based on your actual API specifications.
Conclusion
The philz1337x/controlnet-deliberate Cognitive Actions provide a robust framework for developers to enhance images through advanced processing techniques like Canny edge detection. Whether you’re generating art, modifying photographs, or creating unique visual content, these actions offer a flexible solution. Explore the possibilities and integrate them into your applications to elevate your image processing capabilities!