本文整理汇总了Python中skimage.transform.probabilistic_hough_line函数的典型用法代码示例。如果您正苦于以下问题:Python probabilistic_hough_line函数的具体用法?Python probabilistic_hough_line怎么用?Python probabilistic_hough_line使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了probabilistic_hough_line函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_probabilistic_hough_bad_input
def test_probabilistic_hough_bad_input():
img = np.zeros(100)
img[10] = 1
# Expected error, img must be 2D
with testing.raises(ValueError):
transform.probabilistic_hough_line(img)
示例2: get_image_dynamics
def get_image_dynamics(image):
edges = canny(image, 1, .4, .6)
lines = probabilistic_hough_line(edges, line_gap=6)
TAN15 = 0.26794919243
TAN75 = 3.73205080757
EPS = 0.0000000005
c1, c2, c3 = (0, 0, 0)
dynamics = np.zeros(6, dtype=np.float64)
for (x1, y1), (x2, y2) in lines:
aslope = abs((x2 - x1) / (y2 - y1 + EPS))
linelen = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
if (aslope < TAN15):
c1 = c1 + 1
dynamics[0] = dynamics[0] + aslope
dynamics[3] = linelen
elif (aslope > TAN75):
c2 = c2 + 1
dynamics[1] = dynamics[1] + aslope
dynamics[4] = linelen
else:
c3 = c3 + 1
dynamics[2] = dynamics[2] + aslope
dynamics[5] = linelen
if (c1 > 0):
dynamics[0] /= c1
dynamics[1] /= c1
if (c2 > 0):
dynamics[2] /= c2
dynamics[3] /= c2
if (c3 > 0):
dynamics[4] /= c3
dynamics[5] /= c3
return dynamics;
示例3: my_hough_2
def my_hough_2(edges, hough_start, hough_end, hough_line_len=30, line_gap=50, fn = None, show=False, raw=None, xdiff=0, ydiff=0):
height = edges.shape[0]
width = edges.shape[1]
hough_gap = 0.001
hough_angle = np.arange(hough_start,hough_end, hough_gap)
lines_ret = probabilistic_hough_line(edges, threshold=30, line_gap=line_gap,line_length=hough_line_len, theta=hough_angle)
from src.utils.util import tuple2list
lines_temp1 = tuple2list(lines_ret)
from src.utils.util import sortlines_len
lines = sortlines_len(lines_temp1)
from src.utils.util import changecoord
if xdiff != 0 and ydiff != 0:
lines = changecoord(lines, xdiff=xdiff, ydiff=ydiff)
if lines is not None:
if show is True:
if raw is None:
logging.error('background image is not provided')
sys.exit(1)
from src.utils.io import add_lines
raw = add_lines(lines, raw)
return lines, raw
示例4: hough_vertical
def hough_vertical(edges, fn=None, hough_line_len=30, line_gap=5, save=False, show=False, raw=None, xdiff=0, ydiff=0):
height = edges.shape[0]
width = edges.shape[1]
div = 9
hough_end = 0 + math.pi/div
hough_start = 0 - math.pi/div
hough_gap = 0.001
hough_angle = np.arange(hough_start,hough_end, hough_gap)
lines_ret = probabilistic_hough_line(edges, threshold=30, line_gap=line_gap,line_length=hough_line_len, theta=hough_angle)
from src.utils.util import tuple2list
lines = tuple2list(lines_ret)
from src.utils.util import changecoord
if xdiff != 0 and ydiff !=0:
lines= changecoord(lines, xdiff, ydiff)
if lines is not None:
if save is True or show is True:
if raw is None:
logging.error('background image is not provided')
sys.exit(1)
from src.utils.io import add_lines
raw = add_lines(lines, raw)
if show is True:
raw.show()
if save is True:
raw.save(fn + '.jpg')
return lines, raw
示例5: hough_vertical_mask
def hough_vertical_mask(edges, background, fn, hough_line_len=30, save=True, show=True):
#hough line features.
div = 9
hough_start = -math.pi/div
ds = round(180/div)
hough_end= 0
de = 0
hough_gap = 0.001
hough_line_gap = 10
hough_angle = np.arange(hough_start,hough_end, hough_gap)
#detect lines
lines = probabilistic_hough_line(edges, threshold=30, line_gap=hough_line_gap,line_length=hough_line_len, theta=hough_angle)
canvas = background.copy()
draw = ImageDraw.Draw(canvas)
pts = []
ret = []
for line in lines:
p0, p1 = line
# 400 <= x <= 2000, 800 <= y <= 1000
if 1000<= p0[1]<=2500 and 1000 <=p1[1]<=2500 and 500<= p0[0]<=1000 and 500<= p1[0] <= 1000:
pts.append(p0)
pts.append(p1)
ret.append(line)
draw.line(line, fill='red')
if save:
feature = 'v_range' + str(int(ds))+ '_' + str(int(de)) + '_gap' + str(int(hough_line_gap)) + '_len' + str(int(hough_line_len))
fn = fn + feature + '.tiff'
canvas.save(fn)
if show:
canvas.show('vertical hough line')
return pts, ret
示例6: hough_horizontal
def hough_horizontal(edges, fn, hough_line_len=30, save=True, show=True):
div = 9
hough_end = math.pi/2
de = 180/div
hough_start = math.pi/2 - math.pi/div
ds = 0
hough_gap = 0.001
hough_line_gap = 5
hough_angle = np.arange(hough_start,hough_end, hough_gap)
lines = probabilistic_hough_line(edges, threshold=30, line_gap=hough_line_gap,line_length=hough_line_len, theta=hough_angle)
plt.close()
plt.imshow(edges, cmap=plt.cm.gray)
pts = []
for line in lines:
p0, p1 = line
pts.append(p0)
pts.append(p1)
plt.plot((p0[0], p1[0]), (p0[1], p1[1]), linewidth=1, color='g')
if save:
feature = 'h_range' + str(int(ds))+ '_' + str(int(de)) + '_gap' + str(int(hough_line_gap)) + '_len' + str(int(hough_line_len))
fn = fn + feature
plt.title('horizontal hough line' + feature )
saveplot(plt, fn)
return pts, lines
示例7: hough_v
def hough_v():
hough_line_len = 30
div = 9
hough_start = -math.pi/div
ds = round(180/div)
hough_end=0
de = 0
hough_gap = 0.001
hough_line_gap = 8
hough_angle = np.arange(hough_start,hough_end, hough_gap)
lines = probabilistic_hough_line(edges, threshold=30, line_gap=hough_line_gap,line_length=hough_line_len, theta=hough_angle)
#plt.imshow(gray, cmap=plt.cm.gray)
plt.imshow(edges, cmap=plt.cm.gray)
#im = Image.new('L', gray.shape)
#im.putdata(gray)
#draw = ImageDraw.Draw(im)
for line in lines:
p0, p1 = line
plt.plot((p0[0], p1[0]), (p0[1], p1[1]), linewidth=1, color='r')
#draw.line((line), width=2)
#plt.show()
fn = dir +'/canny_hough/canny_'+str(canny_sigma) + '_V_range' + str(ds)+ '_' + str(de) + '_gap' + str(hough_line_gap) + '_len' + str(hough_line_len) + '.png'
plt.title('vertical hough line')
Util.saveplot(plt, fn)
#im.show()
return lines
示例8: plot_hough
def plot_hough(angle, precision):
lines = probabilistic_hough_line(edges,
theta=linspace(angle - precision, angle + precision, 3),
line_gap=0,
line_length=10)
for line in lines:
p0, p1 = line
plot((p0[0], p1[0]), (p0[1], p1[1]))
示例9: test_probabilistic_hough_seed
def test_probabilistic_hough_seed():
# Load image that is likely to give a randomly varying number of lines
image = data.checkerboard()
# Use constant seed to ensure a deterministic output
lines = transform.probabilistic_hough_line(image, threshold=50,
line_length=50, line_gap=1,
seed=1234)
assert len(lines) == 65
示例10: draw_lines
def draw_lines(array, width=105):
m = to_matrix(array, width=width)
x = skeletonize(m)
ax = plt.subplot(1, 3, 0)
ax.imshow(m, cmap=plt.cm.gray_r, interpolation='nearest')
ax = plt.subplot(1, 3, 1)
ax.imshow(x, cmap=plt.cm.gray_r, interpolation='nearest')
ax = plt.subplot(1, 3, 2)
ax.imshow(x*0, cmap=plt.cm.gray_r, interpolation='nearest')
lines = probabilistic_hough_line(x, threshold=10, line_length=5, line_gap=3)
for line in lines:
p0, p1 = line
ax.plot((p0[0], p1[0]), (p0[1], p1[1]))
plt.show()
示例11: test_probabilistic_hough
def test_probabilistic_hough():
# Generate a test image
img = np.zeros((100, 100), dtype=int)
for i in range(25, 75):
img[100 - i, i] = 100
img[i, i] = 100
# decrease default theta sampling because similar orientations may confuse
# as mentioned in article of Galambos et al
theta = np.linspace(0, np.pi, 45)
lines = tf.probabilistic_hough_line(img, threshold=10, line_length=10, line_gap=1, theta=theta)
# sort the lines according to the x-axis
sorted_lines = []
for line in lines:
line = list(line)
line.sort(key=lambda x: x[0])
sorted_lines.append(line)
assert [(25, 75), (74, 26)] in sorted_lines
assert [(25, 25), (74, 74)] in sorted_lines
# Execute with default theta
tf.probabilistic_hough_line(img, line_length=10, line_gap=3)
示例12: hough_transform
def hough_transform(self, vary=False, plot=False):
"""
:param vary: turn edge detection tunable plotting on
:param plot: turn plotting on
:return: numpy array of probabilistically found straight lines
"""
if self.name == "":
raise ValueError('Missing image: you need to specify the image file using add_image.')
self.edges = self._detect_edges(self.name, vary=vary, plot=plot)
self.lines = probabilistic_hough_line(self.edges, threshold=10, line_length=5, line_gap=3)
if plot:
for line in self.lines:
p0, p1 = line
plt.plot((p0[0], p1[0]), (p0[1], p1[1]))
plt.show()
示例13: __get_grid_segments__
def __get_grid_segments__(self):
horiz_segments = []
vert_segments = []
horiz_intercepts = []
vert_intercepts = []
print "getting edges"
edges = cv2.Canny(self.template,25,150,apertureSize = 3)
print "probabilistic houghes"
lines = probabilistic_hough_line(edges, threshold=5, line_length=3,line_gap=1)
# plt.close()
# fig, ax1 = plt.subplots(1, 1)
# fig.set_size_inches(52,78)
# ax1.imshow(self.image)
for line in lines:
p0, p1 = line
X = p0[0],p1[0]
Y = p0[1],p1[1]
if (min(X) >= self.big_lower_x) and (max(X) <= self.big_upper_x) and (min(Y) >= self.big_lower_y) and (max(Y) <= self.big_upper_y):
d,t = hesse_line(line)
if math.fabs(t) <= 0.1:
# horiz_list.append(line)
# hesse_list.append(hesse_line(line))
m = (Y[0]-Y[1])/float(X[0]-X[1])
b = Y[0]-m*X[0]
horiz_intercepts.append(b+m*big_lower_x)
horiz_segments.append(line)
elif math.fabs(t-math.pi/2.) <= 0.1:
# vert_list.append(line)
m = (X[0]-X[1])/float(Y[0]-Y[1])
b = X[0]-m*Y[0]
vert_intercepts.append(b+m*big_lower_y)
vert_segments.append(line)
else:
continue
# ax1.plot(X, Y,color="red")
# plt.savefig("/home/ggdhines/Databases/new.jpg",bbox_inches='tight', pad_inches=0,dpi=72)
return horiz_segments,vert_segments,horiz_intercepts,vert_intercepts
示例14: main
def main():
ground_truth = np.array([2,2,1,5,2,3,3,3,2,6,2,3,6,3,5,6,3,2,3,2,4,6,2,2,3,3,2,1,3,0,3,3,2,3,3,3,5,3,6,2,2,5,3,6,2,3,3,3,6,2,0,2,0,2,5,2,3,2,2,0,4,2,1,0,2,2,2,0,3,5,3,3,6,3,3,3,3,3,0,3,0,2,3,0,0,3,2,0,0,2,2,3,2,2,2,0,3,2,0,1,3,3,2,3,3,3,3,2,3,0,3,3,1,2,3,2,0,0,0,0,0,0,0,0,3,2,3,2,2,3,3,3,3,3,3,2,2])
simple_ground_truth = []
for i in np.arange(len(ground_truth)):
if ground_truth[i] >=4:
simple_ground_truth.append(4)
else:
simple_ground_truth.append(ground_truth[i])
simple_ground_truth = np.array(simple_ground_truth)
with open("test_fig/img_data.dat", "rb") as fin:
img_data = cPickle.load(fin)
img = img_data[1]
fig = plt.figure(figsize=const.figsize)
ax = fig.add_subplot(121, aspect='equal')
ax.imshow(img>0, cmap='gray')
lines = probabilistic_hough_line(img,line_length=20)
print len(lines)
N_BIN = 32
theta_bins = np.arange(N_BIN)*np.pi/N_BIN
bin_hist = np.zeros(N_BIN)
for line in lines:
ax.plot([line[0][0],line[1][0]],
[line[0][1],line[1][1]],'-r')
vec = np.array([line[1][0]-line[0][0], line[1][1]-line[0][1]])*1.0
vec_norm = np.linalg.norm(vec)
if vec_norm > 1.0:
vec /= vec_norm
cross_product = abs(np.dot(vec, np.array([1,0])))
theta_bin_idx = int(np.arccos(cross_product) / np.pi * N_BIN)
bin_hist[theta_bin_idx] += 1
ax.set_xlim([0, img.shape[0]])
ax.set_ylim([img.shape[1], 0])
ax = fig.add_subplot(122)
x_vals = np.arange(N_BIN)*90.0/N_BIN
ax.plot(x_vals, bin_hist, '.-')
plt.show()
示例15: linesFromBinary
def linesFromBinary(binaryData, minLen, debug=False):
# find edges
edges = filters.sobel(binaryData)
# get directions
lines = probabilistic_hough_line(edges, threshold=10, line_length=minLen,
line_gap=3)
if lines == []:
if debug:
print('No lines detected with Hough line algorithm')
return None, None, lines
else:
angleArr = np.zeros(len(lines))
for l in np.arange(len(lines)):
p0, p1 = lines[l]
# get the m coefficient of the lines and the angle
try:
m = (p1[0] - p0[0])/(p1[1] - p0[1])
angle = (180/np.pi)*np.arctan(m)
except ZeroDivisionError:
angle = 90
angleArr[l] = angle
# Before calculating the mean angle, we have to make sure we're using
# the same quadrant for all the angles. We refer all the angles to the
# first one
opt = np.array([180, 0, -180])
for i in np.arange(1, len(angleArr)):
dists = np.abs(angleArr[0] - (opt + angleArr[i]))
angleArr[i] += opt[np.argmin(dists)]
mean, std = np.mean(angleArr), np.std(angleArr)
# We like angles in [0, 180)
if mean < 0:
mean += 180
return mean, std, lines