Create Stunning Images with Edge Control Using Flux Canny Pro Actions

In the realm of image generation, the black-forest-labs/flux-canny-pro API offers a powerful Cognitive Action designed for artists and developers alike. By leveraging Canny edge detection, this action enables you to create detailed and structured images that maintain their composition and style. Whether you're transforming sketches into refined art or retexturing images, the possibilities are endless with this action.
Prerequisites
Before diving into the integration of the Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform.
- Basic familiarity with making HTTP requests and handling JSON data.
- A working environment to test your API calls (Python is recommended for the conceptual examples).
Authentication typically involves passing your API key in the headers of your requests to ensure secure access to the service.
Cognitive Actions Overview
Generate Images with Edge Control
Description:
This action allows you to create detailed, structured images using Canny edge detection, providing precise control over composition and style. It is particularly effective for turning sketches into artistic images or retexturing existing images while preserving their structural integrity.
Category: image-generation
Input: The action requires the following fields in the input JSON payload:
- controlImage (string, required): The URI of the image to be used as a control input. Supported formats include JPEG, PNG, GIF, or WEBP.
- prompt (string, required): A text prompt guiding the content of the generated image.
- seed (integer, optional): A random seed for reproducibility of the generated image.
- steps (integer, optional): The number of diffusion steps for image generation (default: 50, range: 15-50).
- guidance (number, optional): A value determining adherence to prompts (default: 30, range: 1-100).
- outputFormat (string, optional): The file format for the generated output images (default: "jpg").
- safetyTolerance (integer, optional): Level of safety filtering (default: 2, range: 1-6).
- promptUpsampling (boolean, optional): Enables automatic adjustment of the prompt for more creative output (default: false).
Example Input:
{
"steps": 28,
"prompt": "a photo of a car on a city street",
"guidance": 25,
"controlImage": "https://replicate.delivery/pbxt/M0j11UQhwUWoxUQ9hJCOaALsAHTeoPZcGGtUf6n3BJxtKHul/output-14.webp",
"outputFormat": "jpg",
"safetyTolerance": 2,
"promptUpsampling": false
}
Output: The action typically returns a URL to the generated image. For example:
https://assets.cognitiveactions.com/invocations/716a5ec0-63ea-4b92-a757-75da8b97a44c/3f1edee8-df2f-428c-bd20-c7828746a38c.jpg
Conceptual Usage Example (Python)
Here’s how you can invoke the "Generate Images with Edge Control" 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 = "cdac891c-c84a-4dd4-8e26-8a5ccff838d1" # Action ID for Generate Images with Edge Control
# Construct the input payload based on the action's requirements
payload = {
"steps": 28,
"prompt": "a photo of a car on a city street",
"guidance": 25,
"controlImage": "https://replicate.delivery/pbxt/M0j11UQhwUWoxUQ9hJCOaALsAHTeoPZcGGtUf6n3BJxtKHul/output-14.webp",
"outputFormat": "jpg",
"safetyTolerance": 2,
"promptUpsampling": False
}
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 YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action ID and input payload are structured to comply with the requirements of the "Generate Images with Edge Control" action.
Conclusion
The black-forest-labs/flux-canny-pro Cognitive Action for generating images with edge control offers developers an exciting tool for enhancing visual content creation. By harnessing edge detection techniques, you can create stunning images that align with specific prompts and artistic visions. As you explore this action, consider experimenting with various prompts, control images, and parameters to unlock the full potential of your creative projects. Happy coding!