I am trying to get the edges of a cube in the image below using the Hough transform in the Scikit-Image library .
Update Here is the code I am working with:
smoothed_image = filters.frangi(gray_image)
# Perform edge detection using the Canny edge detector
low_threshold = 0.1
high_threshold = 3
low_threshold = low * smoothed_image.max()
high_threshold = high * low_threshold
edges = canny(smoothed_image, sigma, low_threshold=low_threshold,
high_threshold=high_threshold)
# Hough transform to detect the filament profile
hspace, theta, dist = hough_line(edges)
# Find the vertical lines
vertical_peaks = hough_line_peaks(hspace, theta, dist, num_peaks=2)
vertical_lines = []
for _, angle, dist in zip(*vertical_peaks):
x = dist * np.cos(angle)
y = dist * np.sin(angle)
vertical_lines.append((x, y))
# Visualize the results
fig, axes = plt.subplots(1, 3, figsize=(15, 5))
axes[0].imshow(smoothed_image)
axes[0].set_title('Smoothed Image')
#axes[0].axis('off')
axes[1].imshow(edges, cmap='gray')
axes[1].set_title('Canny Edge Detection')
axes[1].axis('off')
axes[2].imshow(edges, cmap='gray')
for x, y in vertical_lines:
axes[2].axvline(x=x, color='red')
axes[2].set_xlim((0, image.shape[1]))
axes[2].set_ylim((image.shape[0], 0))
axes[2].set_title('Detected Lines')
axes[2].axis('off')
plt.tight_layout()
plt.show()
And this is the resulting output
Any ideas on how to make the Hough transform detect the other edge?