File size: 828 Bytes
8ad5847
 
9c8790e
8ad5847
 
9c8790e
8ad5847
 
 
d9f5705
8ad5847
 
d9f5705
8ad5847
 
 
d9f5705
8ad5847
 
9c8790e
8ad5847
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import cv2
import numpy as np

# Load the image (assuming it's a binary image with edges)
image = cv2.imread('path/to/edge_detected_image.jpg', cv2.IMREAD_GRAYSCALE)

# Apply morphological operations to clean up the edges
kernel = np.ones((5, 5), np.uint8)
closed_image = cv2.morphologyEx(image, cv2.MORPH_CLOSE, kernel)

# Find contours in the closed image
contours, _ = cv2.findContours(closed_image, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

# Create a mask for the exterior contours
mask = np.zeros_like(image)
cv2.drawContours(mask, contours, -1, (255), thickness=cv2.FILLED)

# Apply the mask to the original image to get only the exterior edges
exterior_edges = cv2.bitwise_and(image, mask)

# Display the result or save it to a file
cv2.imshow('Exterior Edges', exterior_edges)
cv2.waitKey(0)
cv2.destroyAllWindows()