I performed some canny edge with large sigma (4.5) in order to identify the main features of my image. So far I’ve gotten to this point where canny edges successfully identified the border of my region of interest (2 semi-parallel lines on top and two semi parallel lines at the bottom – all identified with red boxes).
The region that I want to extract lies in the middle of the red boxes – identified by the green boxes. The problem with Probabilistic Hough is it doesn’t quite have a neat border like presented in canny edges, making the extractable area inaccurate, in addition, it is impossible to have the lines connected neatly to each other since as you can see in the canny image, the border of the ROI is rough. Is there a better way to do this?
Canny & Probabilistic
This is the codes that I’ve written:
edges = canny(thresh, 4.5, 1, 175)
lines = probabilistic_hough_line(edges, threshold=10, line_length=50, line_gap=50, theta = np.arange(1.0472, 2.094, 0.0001))
# Generating figure 2
fig, axes = plt.subplots(1, 3, figsize=(15, 5), sharex=True, sharey=True)
ax = axes.ravel()
ax[0].imshow(thresh[:,:], cmap=cm.gray)
ax[0].set_title('Input image')
ax[1].imshow(edges, cmap=cm.gray)
ax[1].set_title('Canny edges')
ax[2].imshow(edges * 0)
for line in lines:
p0, p1 = line
ax[2].plot((p0[0], p1[0]), (p0[1], p1[1]))
ax[2].set_xlim((0, thresh.shape[1]))
ax[2].set_ylim((thresh.shape[0], 0))
ax[2].set_title('Probabilistic Hough')
for a in ax:
a.set_axis_off()
plt.tight_layout()
plt.show()
Trung Ha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.