本文整理汇总了Python中skimage.draw.line函数的典型用法代码示例。如果您正苦于以下问题:Python line函数的具体用法?Python line怎么用?Python line使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了line函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: drawBounds
def drawBounds(img, boxes):
outimg = np.zeros((img.shape[0], img.shape[1], 3))
outimg[:,:]=[255,255,255]
outimg[~img]=[0,0,0]
for box in boxes:
if abs(box.x1-box.x2) < 10 or abs(box.y1-box.y2) < 15:
continue
rr,cc = line(box.x1, box.y1, box.x1, box.y2)
try:
outimg[cc,rr]=[255,0,0]
except IndexError:
pass
rr,cc = line(box.x1, box.y1, box.x2, box.y1)
try:
outimg[cc,rr]=[255,0,0]
except IndexError:
pass
rr,cc = line(box.x1, box.y2, box.x2, box.y2)
try:
outimg[cc,rr]=[255,0,0]
except IndexError:
pass
rr,cc = line(box.x2, box.y1, box.x2, box.y2)
try:
outimg[cc,rr]=[255,0,0]
except IndexError:
pass
return outimg
示例2: test_skeletonize_num_neighbours
def test_skeletonize_num_neighbours():
# an empty image
image = np.zeros((300, 300))
# foreground object 1
image[10:-10, 10:100] = 1
image[-100:-10, 10:-10] = 1
image[10:-10, -100:-10] = 1
# foreground object 2
rs, cs = draw.line(250, 150, 10, 280)
for i in range(10):
image[rs + i, cs] = 1
rs, cs = draw.line(10, 150, 250, 280)
for i in range(20):
image[rs + i, cs] = 1
# foreground object 3
ir, ic = np.indices(image.shape)
circle1 = (ic - 135)**2 + (ir - 150)**2 < 30**2
circle2 = (ic - 135)**2 + (ir - 150)**2 < 20**2
image[circle1] = 1
image[circle2] = 0
result = skeletonize_3d(image)
# there should never be a 2x2 block of foreground pixels in a skeleton
mask = np.array([[1, 1],
[1, 1]], np.uint8)
blocks = ndi.correlate(result, mask, mode='constant')
assert_(not np.any(blocks == 4))
示例3: setUp
def setUp(self):
# We create an artificial lf
imgs = np.zeros((50,100,150), dtype=np.uint8)
for i in range(50):
for j in range(2):
rr, cc = line(0, 10+j+i, 99, 10+j+i)
imgs[i, rr, cc] = 75
for j in range(5):
rr, cc = line(0, 12+j+i, 99, 12+j+i)
imgs[i, rr, cc] = 125
for j in range(2):
rr, cc = line(0, 17+j+i, 99, 17+j+i)
imgs[i, rr, cc] = 75
for j in range(5):
rr, cc = line(0, 20+j+2*i, 99, 20+j+2*i)
imgs[i, rr, cc] = 175
for j in range(10):
rr, cc = line(0, 35+j+2*i, 99, 35+j+2*i)
imgs[i, rr, cc] = 250
#ski.io.imsave("img_{i}.png".format(i=i), imgs[i])
# We create epis out of it
self.epis = np.zeros((100,50,150), dtype=np.uint8)
for i in range(100):
self.epis[i] = np.reshape(imgs[:,i], (50,150))
#ski.io.imsave("epi_{i}.png".format(i=i), epis[i])
self.epi = self.epis[25]
示例4: add_rectangle
def add_rectangle(img, y0, x0, y1, x1, color="r", width=1):
"""Colors: 'r', 'g', 'b', 'w', 'k'"""
im = np.copy(img)
if im.ndim == 2:
im = gray2rgb(im)
max_val = 1
if np.max(img) > 1:
max_val = 255
channel = 3 # Bogus value when color = 'w' or 'k'
if color == "r":
channel = 0
if color == "g":
channel = 1
if color == "b":
channel = 2
for i in range(width):
yy0 = y0 + i
xx0 = x0 + i
yy1 = y1 - i
xx1 = x1 - i
rr, cc = line(yy0, xx0, yy1, xx0) # left
im = paint_line(im, rr, cc, color, channel, max_val)
rr, cc = line(yy1, xx0, yy1, xx1) # bottom
im = paint_line(im, rr, cc, color, channel, max_val)
rr, cc = line(yy1, xx1, yy0, xx1) # right
im = paint_line(im, rr, cc, color, channel, max_val)
rr, cc = line(yy0, xx1, yy0, xx0) # top
im = paint_line(im, rr, cc, color, channel, max_val)
return im
示例5: houghLines
def houghLines(img):
w,h = img.shape
acc=[]
for i in range(h):
rr,cc = line(0, i, w-1, h-i-1)
acc.append(np.sum(img[rr, cc]))
#print acc[i]
mi = np.argmax(acc)
ret = np.zeros(img.shape, dtype=np.bool)
rr,cc = line(0, mi, w-1, h-mi-1)
ret[rr,cc]=True
return ret
示例6: display_triangle
def display_triangle(im, tr, col):
rows, cols = im.shape
rr, cc = line(*map(int, tr[0]), *map(int, tr[1]))
ind = logical_and.reduce((rr >= 0, rr < rows, cc >= 0, cc < cols))
rr, cc = rr[ind], cc[ind]
im[rr, cc] = col
rr, cc = line(*map(int, tr[1]), *map(int, tr[2]))
ind = logical_and.reduce((rr >= 0, rr < rows, cc >= 0, cc < cols))
rr, cc = rr[ind], cc[ind]
im[rr, cc] = col
rr, cc = line(*map(int, tr[2]), *map(int, tr[0]))
ind = logical_and.reduce((rr >= 0, rr < rows, cc >= 0, cc < cols))
rr, cc = rr[ind], cc[ind]
im[rr, cc] = col
示例7: draw_keypoints
def draw_keypoints(img, keypoints, draw_prob):
"""Draws for each keypoint a circle (roughly matching the sigma of the scale)
with a line for the orientation.
Args:
img The image to which to add the keypoints (gets copied)
keypoints The keypoints to draw
draw_prob Probability of drawing a keypoint (the lower the less keypoints are drawn)
Returns:
Image with keypoints"""
height, width = img.shape
img = np.copy(img)
# convert from grayscale image to RGB so that keypoints can be drawn in red
img = img[:, :, np.newaxis]
img = np.repeat(img, 3, axis=2)
for (y, x), orientation, scale_idx, scale_size, kp_type in keypoints:
if draw_prob < 1.0 and random.random() <= draw_prob:
# draw the circle
radius = int(scale_size)
rr, cc = draw.circle_perimeter(y, x, radius, shape=img.shape)
img[rr, cc, 0] = 1.0
img[rr, cc, 1:] = 0
# draw orientation
orientation = util.quantize(orientation, [-135, -90, -45, 0, 45, 90, 135, 180])
x_start = x
y_start = y
if orientation == 0:
x_end = x + radius
y_end = y
elif orientation == 45:
x_end = x + radius*(1/math.sqrt(2))
y_end = y + radius*(1/math.sqrt(2))
elif orientation == 90:
x_end = x
y_end = y + radius
elif orientation == 135:
x_end = x - radius*(1/math.sqrt(2))
y_end = y - radius*(1/math.sqrt(2))
elif orientation == 180:
x_end = x - radius
y_end = y
elif orientation == -135:
x_end = x - radius*(1/math.sqrt(2))
y_end = y - radius*(1/math.sqrt(2))
elif orientation == -90:
x_end = x
y_end = y - radius
elif orientation == -45:
x_end = x + radius*(1/math.sqrt(2))
y_end = y - radius*(1/math.sqrt(2))
x_end = np.clip(x_end, 0, width-1)
y_end = np.clip(y_end, 0, height-1)
rr, cc = draw.line(int(y_start), int(x_start), int(y_end), int(x_end))
img[rr, cc, 0] = 1.0
img[rr, cc, 1:] = 0
img = np.clip(img, 0, 1.0)
return img
示例8: lines
def lines(end_points, shape):
"""
Parameters
----------
end_points : iterable
coordinates of the starting point and the ending point of each
line: e.g., [(start_x, start_y, end_x, end_y), (x1, y1, x2, y2)]
shape : tuple
Image shape which is used to determine the maximum extent of output
pixel coordinates. Order is (rr, cc).
Returns
-------
label_array : array
Elements not inside any ROI are zero; elements inside each
ROI are 1, 2, 3, corresponding to the order they are specified
in coords. Order is (rr, cc).
"""
label_array = np.zeros(shape, dtype=np.int64)
label = 0
for points in end_points:
if len(points) != 4:
raise ValueError("end points should have four number of"
" elements, giving starting co-ordinates,"
" ending co-ordinates for each line")
rr, cc = line(np.max([points[0], 0]), np.max([points[1], 0]),
np.min([points[2], shape[0]-1]),
np.min([points[3], shape[1]-1]))
label += 1
label_array[rr, cc] = label
return label_array
示例9: output
def output(self):
"""Return the drawn line and the resulting scan.
Returns
-------
line_image : (M, N) uint8 array, same shape as image
An array of 0s with the scanned line set to 255.
If the linewidth of the line tool is greater than 1,
sets the values within the profiled polygon to 128.
scan : (P,) or (P, 3) array of int or float
The line scan values across the image.
"""
end_points = self.line_tool.end_points
line_image = np.zeros(self.image_viewer.image.shape[:2],
np.uint8)
width = self.line_tool.linewidth
if width > 1:
rp, cp = measure.profile._line_profile_coordinates(
*end_points[:, ::-1], linewidth=width)
# the points are aliased, so create a polygon using the corners
yp = np.rint(rp[[0, 0, -1, -1],[0, -1, -1, 0]]).astype(int)
xp = np.rint(cp[[0, 0, -1, -1],[0, -1, -1, 0]]).astype(int)
rp, cp = draw.polygon(yp, xp, line_image.shape)
line_image[rp, cp] = 128
(x1, y1), (x2, y2) = end_points.astype(int)
rr, cc = draw.line(y1, x1, y2, x2)
line_image[rr, cc] = 255
return line_image, self.scan_data
示例10: polygon_perimeter
def polygon_perimeter(polygon, img_side=28):
"""
Generate the perimeter of a polygon including the vertices.
"""
# Create empty image
img_shape = [img_side, img_side]
img = np.zeros(img_shape, dtype=np.float32)
prev_idx, cur_idx = -1, 0
poly_len = len(polygon)
while cur_idx < poly_len:
# Get vertices
prev_vertex = polygon[prev_idx]
cur_vertex = polygon[cur_idx]
# Get line pixels
prev_rr, prev_cc = draw.line(
prev_vertex[1], prev_vertex[0],
cur_vertex[1], cur_vertex[0]
)
# Draw lines
img[prev_rr, prev_cc] = 1.
# Increment prev_idx and cur_idx
prev_idx += 1
cur_idx += 1
return img
示例11: remove_deep_points
def remove_deep_points(self, CIRCLE_RADIUS = 5, MINIMUM_BOUNDARY = 70):
for point in self.POINTS_initial:
segments = []
circle_x, circle_y = circle_perimeter(point[0],point[1],CIRCLE_RADIUS)
circle_points = np.array(list(sorted(set(zip(circle_x,circle_y)))))
sortedpoints = np.empty([len(circle_points), 2], dtype=int)
test1 = circle_points[circle_points[:,0] == point[0] - CIRCLE_RADIUS]
start = len(test1)
end = len_cpoints = len(sortedpoints)
sortedpoints[0:start] = test1
for x in xrange(point[0] - CIRCLE_RADIUS + 1, point[0] + CIRCLE_RADIUS):
test1 = circle_points[circle_points[:,0] == x]
testlen = len(test1)
if x <= point[0]:
sortedpoints[start:start+testlen/2] = test1[testlen/2:]
sortedpoints[end-testlen/2:end] = test1[:testlen/2]
else:
sortedpoints[start:start+testlen/2] = test1[testlen/2:][::-1]
sortedpoints[end-testlen/2:end] = test1[:testlen/2][::-1]
start += testlen/2
end -= testlen/2
test1 = circle_points[circle_points[:,0] == point[0] + CIRCLE_RADIUS]
sortedpoints[start:start + len(test1)] = test1[::-1]
for c_perimeter in sortedpoints:
segments.append(True)
line_x, line_y = line(point[0], point[1], c_perimeter[0], c_perimeter[1])
for line_points in zip(line_x,line_y)[1:]:
# if original_image[line_points[0]][line_points[1]] != 0:
if self.FOOTPRINT_cleaned_opening[line_points[0]][line_points[1]] != 0:
segments[-1] = False
break
min_boundpoints = (MINIMUM_BOUNDARY / 360.0) * len_cpoints
seg_sizes = []
new_segment = True
for segment in segments:
if segment:
if new_segment:
seg_sizes.append(1)
new_segment = False
else:
seg_sizes[-1] += 1
else:
new_segment = True
if segments[0] == True and segments[-1] == True and len(seg_sizes) > 1:
seg_sizes[0] = seg_sizes[0] + seg_sizes[-1]
seg_sizes.pop()
if(len(seg_sizes) == 0 or max(seg_sizes) < min_boundpoints):
# boundary_image[point[0]][point[1]] = 0 #TAMA BANG TANGGALIN?
if (point[0],point[1]) in self.POINTS_ordered: ## IDENTIFY KUNG BAKIT NAGKA-ERRROR, EXAMPLE pt000120_merged4.py obj 1301
self.POINTS_ordered.remove((point[0],point[1]))
示例12: footprint_fitness_error
def footprint_fitness_error(self, points):
temp_footprint = np.zeros(self.FOOTPRINT_added_boundary.shape, dtype=np.uint8)
len_points = len(points)
for idx1 in xrange(0, len_points):
rr,cc = line(points[idx1][0], points[idx1][1], points[idx1-1][0],points[idx1-1][1])
temp_footprint[rr,cc] = 1
temp_footprint = ndimage.binary_fill_holes(temp_footprint)
temp_footprint = temp_footprint * 1
rr,cc = np.nonzero(temp_footprint)
#RATIO OF ZEROS AND ONES SA LOOB
zero_counter = 0.0
nonzero_counter = 0.0
for point in zip(rr,cc):
if self.FOOTPRINT_added_boundary[point[0]][point[1]] == 0:
zero_counter += 1.0
else:
nonzero_counter += 1.0
footprint_copy = copy.deepcopy(self.FOOTPRINT_added_boundary)
footprint_copy[rr,cc] = 0
nonzero = len(footprint_copy[footprint_copy != 0])
total = (len(footprint_copy[footprint_copy == 0]) + nonzero) * 1.0
return (nonzero / total) + (zero_counter / (nonzero_counter + zero_counter))
示例13: draw_hough_line
def draw_hough_line(image, dist, theta, color=0):
"""
Draws a line described by the hough transform to an image
:param image: Image to draw on
:param dist: Hough transform distance
:param theta: Hough transform angle
:param color: intensity to draw line
"""
rows, cols = image.shape
if abs(theta) < pi/4:
# Find the x (col) intercepts
x0 = int_(dist/cos(theta))
x1 = int_(x0 - rows * sin(theta))
intercepts = (0, x0, rows, x1)
else:
# Find the y (row) intercepts
y0 = int_(dist/sin(theta))
y1 = int_(y0 + cols * cos(theta))
intercepts = (y0, 0, y1, cols)
r, c = line(*intercepts)
# Check to make sure each point stays in the image bounds and draw it
for n in range(r.size):
if r[n] >= 0 and c[n] >= 0:
if r[n] < rows and c[n] < cols:
image[r[n], c[n]] = color
示例14: display_edges
def display_edges(image, g, threshold):
"""Draw edges of a RAG on its image
Returns a modified image with the edges drawn.Edges are drawn in green
and nodes are drawn in yellow.
Parameters
----------
image : ndarray
The image to be drawn on.
g : RAG
The Region Adjacency Graph.
threshold : float
Only edges in `g` below `threshold` are drawn.
Returns:
out: ndarray
Image with the edges drawn.
"""
image = image.copy()
for edge in g.edges_iter():
n1, n2 = edge
r1, c1 = map(int, rag.node[n1]['centroid'])
r2, c2 = map(int, rag.node[n2]['centroid'])
line = draw.line(r1, c1, r2, c2)
circle = draw.circle(r1,c1,2)
if g[n1][n2]['weight'] < threshold :
image[line] = 0,1,0
image[circle] = 1,1,0
return image
示例15: line_image
def line_image(shape, lines):
image = np.zeros(shape, dtype=bool)
for end_points in lines:
# hough lines returns (x, y) points, draw.line wants (row, columns)
end_points = np.asarray(end_points)[:, ::-1]
image[draw.line(*np.ravel(end_points))] = 1
return image