本文整理汇总了Python中skimage.transform.probabilistic_hough_line函数的典型用法代码示例。如果您正苦于以下问题:Python probabilistic_hough_line函数的具体用法?Python probabilistic_hough_line怎么用?Python probabilistic_hough_line使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了probabilistic_hough_line函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:Cadair,项目名称:scikit-image,代码行数:7,代码来源:test_hough_transform.py
示例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;
开发者ID:HackKPV,项目名称:GimmeEmotionData,代码行数:33,代码来源:hough.py
示例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
开发者ID:sssruhan1,项目名称:xray,代码行数:27,代码来源:hough.py
示例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
开发者ID:sssruhan1,项目名称:xray,代码行数:33,代码来源:hough.py
示例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
开发者ID:sssruhan1,项目名称:xray,代码行数:34,代码来源:hough.py
示例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
开发者ID:sssruhan1,项目名称:xray,代码行数:26,代码来源:hough.py
示例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
开发者ID:sssruhan1,项目名称:xray,代码行数:28,代码来源:_hough.py
示例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]))
开发者ID:lgarcin,项目名称:TIPE,代码行数:8,代码来源:panneaux.py
示例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
开发者ID:Cadair,项目名称:scikit-image,代码行数:9,代码来源:test_hough_transform.py
示例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()
开发者ID:bingo4508,项目名称:ML-handwriting-recognition,代码行数:14,代码来源:util.py
示例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)
开发者ID:jjhelmus,项目名称:scikit-image,代码行数:23,代码来源:test_hough_transform.py
示例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()
开发者ID:brainsqueeze,项目名称:Image_correction,代码行数:16,代码来源:correct.py
示例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
开发者ID:amyrebecca,项目名称:aggregation,代码行数:45,代码来源:backup_weather.py
示例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()
开发者ID:cchen1986,项目名称:python_map_construction,代码行数:45,代码来源:road_junction_classification.py
示例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
开发者ID:lumasullo,项目名称:LabNanofisica,代码行数:43,代码来源:tools.py
示例16: text_sections
def text_sections(im, output_height):
im = im.convert('L')
im_array = image_to_array(im)
im_arary = im_array / 255
r = range(-50,50)
r_theta = [np.pi/2 + x*0.001 for x in r]
theta = np.array(r_theta)
edges = canny(im_array, 2, 1, 25)
lines = probabilistic_hough_line(edges, threshold=5, line_length=20,
line_gap=20, theta=theta)
lines_sorted = sorted(lines, cmp=cmp_lines)
rs = regions(lines_sorted, 2)
text_areas = [bounding_rectangle(ls, 4) for ls in rs]
for (x0, y0), (x1, y1) in text_areas:
width, height = x1 - x0, y1 - y0
output_width = width * output_height // height
yield(im.transform((output_width, output_height), Image.EXTENT,
(x0, y0, x1, y1)))
开发者ID:KayneWest,项目名称:Stuff,代码行数:22,代码来源:line_finding.py
示例17: process
def process(filename):
imagepath = os.path.join(os.getcwd(), filename)
orig_img = io.imread(filename,True,'pil')
img = orig_img > 0.9 # binary threshold
lines = probabilistic_hough_line(hsobel(img),line_length=200)
for l in lines:
x0, x1 = l[0][0],l[1][0]
y = l[0][1]
for x in range(x0,x1):
img[y+1,x] = 1
img[y,x] = 1
img[y-1,x] = 1
erode_img = erosion(img, square(2))
contours, lengths = compute_contours(erode_img,0.8)
lengths = pd.Series(lengths)
lengths = lengths[lengths > 400]
for i in lengths.index:
contour = contours[i]
box = get_boundingboxes([contour])[0]
x_sum = sum(map(abs, np.gradient(contour[:,1])))
y_sum = sum(map(abs, np.gradient(contour[:,0])))
area = (box[2] - box[0]) * (box[3] - box[1])
plt.plot(contour[:,1],contour[:,0])
contours = [contours[i] for i in lengths.index]
newboxes = set(link_contours(contours))
retboxes = []
for box in newboxes:
minx,miny,maxx,maxy = box
x = (minx, maxx, maxx, minx, minx)
y = (miny, miny, maxy, maxy, miny)
area = (maxx-minx) * (maxy-miny)
if area > 10000:
retboxes.append(box)
plt.plot(x, y, '-b', linewidth=2)
imshow(erode_img)
return retboxes, contours
开发者ID:funginstitute,项目名称:signature-disambiguation,代码行数:36,代码来源:signature.py
示例18: hough_transform
def hough_transform(H):
# this function takes the 2D histogram, finds and returns lines
print "let's do the hough and find some lines here"
# http://scikit-image.org/docs/dev/auto_examples/plot_line_hough_transform.html
# https://nabinsharma.wordpress.com/2012/12/26/linear-hough-transform-using-python/
# http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_houghlines/py_houghlines.html
builder = []
for row in H:
temprow = []
for i in row:
if i < 8: # clean data so it only finds edges when above a certain threshold
i = 0
temprow.append(i)
builder.append(temprow)
H = np.asanyarray(builder) # turn this row off to use normal H, there's too much noise in floor 1 though
edges = canny(H) # for noise set sigma=1.8; Edges also very interesting for stairs also! < not absolutely necessary
lines = probabilistic_hough_line(H, threshold=50, line_length=30, line_gap=5) # parameters to be set # threshold=50, line_length=5, line_gap=20
"""showme"""
# fig, (plt1, plt2, plt3) = plt.subplots(1, 3, sharex=True, sharey=True)
# plt1.imshow(H,cmap='spectral')
# plt1.set_title('vert hist')
# plt2.imshow(edges,cmap=plt.cm.gray)
# plt2.set_title('canny edges')
# for line in lines:
# startpt, endpt = line
# plt3.plot((startpt[0], endpt[0]), (startpt[1], endpt[1]))
# plt3.set_title('hough lines')
# plt.show() # can't get rid of stupid white space
return lines
开发者ID:fwfichtner,项目名称:msc-thesis,代码行数:36,代码来源:validate_walls.py
示例19: zip
for _, angle, dist in zip(*hough_line_peaks(h, theta, d)):
y0 = (dist - 0 * np.cos(angle)) / np.sin(angle)
y1 = (dist - image.shape[1] * np.cos(angle)) / np.sin(angle)
ax[2].plot((0, image.shape[1]), (y0, y1), '-r')
ax[2].set_xlim((0, image.shape[1]))
ax[2].set_ylim((image.shape[0], 0))
ax[2].set_axis_off()
ax[2].set_title('Detected lines')
plt.tight_layout()
plt.show()
# Line finding using the Probabilistic Hough Transform
image = data.camera()
edges = canny(image, 2, 1, 25)
lines = probabilistic_hough_line(edges, threshold=10, line_length=5,
line_gap=3)
# Generating figure 2
fig, axes = plt.subplots(1, 3, figsize=(15, 5), sharex=True, sharey=True)
ax = axes.ravel()
ax[0].imshow(image, 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]))
开发者ID:Cadair,项目名称:scikit-image,代码行数:32,代码来源:plot_line_hough_transform.py
示例20: hough_lines
def hough_lines(image, *args, **kwargs):
lines = probabilistic_hough_line(image, threshold=0.5, *args, **kwargs)
image = line_image(image.shape, lines)
return image
开发者ID:AllenDowney,项目名称:skimage-tutorials,代码行数:4,代码来源:7_probabilistic_hough.py
注:本文中的skimage.transform.probabilistic_hough_line函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论