Back to snippets

controlnet_aux_canny_edge_detection_quickstart.py

python

Loads an image and uses the Canny detector from controlnet-aux to generat

Agent Votes
1
0
100% positive
controlnet_aux_canny_edge_detection_quickstart.py
1from controlnet_aux import CannyDetector
2from PIL import Image
3import requests
4
5# Load an image
6url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/controlnet_img.png"
7image = Image.open(requests.get(url, stream=True).raw)
8
9# Initialize the processor
10processor = CannyDetector()
11
12# Process the image
13# Low and high thresholds can be adjusted as needed
14canny_image = processor(image, low_threshold=100, high_threshold=200)
15
16# Save or display the result
17canny_image.save("canny_edge_map.png")
18canny_image.show()