你的邊緣非常清晰 - 對於概率Hough線變換絕對夠用。我想你只需要更多地使用免費參數。
import numpy as np
import matplotlib.pyplot as plt
from skimage.transform import probabilistic_hough_line
from skimage import draw
def restore_lines(distorted):
lines = probabilistic_hough_line(distorted,
threshold=2,
line_length=20,
line_gap=15)
restored = np.zeros_like(distorted, dtype=np.uint8)
for line in lines:
p0, p1 = line
rr, cc = draw.line(p0[1], p0[0], p1[1], p1[0])
restored[rr, cc] += 1
return restored
# distorted = plt.imread('backslash.png')
distorted = plt.imread('tick.png')
# imread returns non-grayscale image in this case
distorted = distorted[:,:,0]
# restore
restored = restore_lines(distorted)
fig, axes = plt.subplots(1,2)
axes[0].imshow(distorted, cmap='gray', interpolation='none')
axes[1].imshow(restored, cmap='gray', interpolation='none')
axes[0].set_title('Original')
axes[1].set_title('Restored')
for ax in axes:
ax.set_xticks([])
ax.set_yticks([])
感謝您的例子,它幫助了很多。我曾使用相當愚蠢的參數值。我現在得到非常好的結果。我遇到的另一個問題是返回結果的錯誤用法。 DanMašek在這裏的答案正確地使用opencv的好解釋:http://stackoverflow.com/a/36453133/6120437 –