Python Implementation of HED

We will use a pre-trained HED model to detect the edge of our input image 

Input Image:

Input image for HED 

Python3




import cv2
img = cv2.imread("input.webp")
(H, W) = img.shape[:2]
blob = cv2.dnn.blobFromImage(img, scalefactor=1.0, size=(W, H),
    swapRB=False, crop=False)
net = cv2.dnn.readNetFromCaffe("deploy.prototxt", "hed_pretrained_bsds.caffemodel")
net.setInput(blob)
hed = net.forward()
hed = cv2.resize(hed[0, 0], (W, H))
hed = (255 * hed).astype("uint8")
cv2.imshow("Input", img)
cv2.imshow("HED", hed)
cv2.waitKey(0)


Output:

Output

Using Different Input image 

Input image:

Input image for HED

Python3




import cv2
img = cv2.imread("pexels-ylanite-koppens-2343170(1).jpg")
(H, W) = img.shape[:2]
blob = cv2.dnn.blobFromImage(img, scalefactor=1.0, size=(W, H),
    swapRB=False, crop=False)
net = cv2.dnn.readNetFromCaffe("deploy.prototxt", "hed_pretrained_bsds.caffemodel")
net.setInput(blob)
hed = net.forward()
hed = cv2.resize(hed[0, 0], (W, H))
hed = (255 * hed).astype("uint8")
cv2.imshow("Input", img)
cv2.imshow("HED", hed)
cv2.waitKey(0)


Output

Output



Holistically-Nested Edge Detection with OpenCV and Deep Learning

Holistically-nested edge detection (HED) is a deep learning model that uses fully convolutional neural networks and deeply-supervised nets to do image-to-image prediction. HED develops rich hierarchical representations automatically (directed by deep supervision on side replies) that are critical for resolving ambiguity in edge and object boundary detection.

Similar Reads

Why Holistically-Nested Edge Detection(HED)

The proposed holistically nested edge detector (HED) tackles two critical issues:...

Model Architecture of Holistically-Nested Edge Detection

The model is VGGNet with a few modifications-...

Python Implementation of HED

We will use a pre-trained HED model to detect the edge of our input image...

Contact Us