本文整理匯總了Python中skimage.draw.line_aa方法的典型用法代碼示例。如果您正苦於以下問題:Python draw.line_aa方法的具體用法?Python draw.line_aa怎麽用?Python draw.line_aa使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類skimage.draw
的用法示例。
在下文中一共展示了draw.line_aa方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: draw_pose_from_cords
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line_aa [as 別名]
def draw_pose_from_cords(pose_joints, img_size, radius=2, draw_joints=True):
colors = np.zeros(shape=img_size + (3,), dtype=np.uint8)
mask = np.zeros(shape=img_size, dtype=bool)
if draw_joints:
for f, t in LIMB_SEQ:
from_missing = pose_joints[f][0] == MISSING_VALUE or pose_joints[f][1] == MISSING_VALUE
to_missing = pose_joints[t][0] == MISSING_VALUE or pose_joints[t][1] == MISSING_VALUE
if from_missing or to_missing:
continue
yy, xx, val = line_aa(pose_joints[f][0], pose_joints[f][1], pose_joints[t][0], pose_joints[t][1])
colors[yy, xx] = np.expand_dims(val, 1) * 255
mask[yy, xx] = True
for i, joint in enumerate(pose_joints):
if pose_joints[i][0] == MISSING_VALUE or pose_joints[i][1] == MISSING_VALUE:
continue
yy, xx = circle(joint[0], joint[1], radius=radius, shape=img_size)
colors[yy, xx] = COLORS[i]
mask[yy, xx] = True
return colors, mask
示例2: draw_pose_from_cords
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line_aa [as 別名]
def draw_pose_from_cords(pose_joints, img_size, radius=2, draw_joints=True):
colors = np.zeros(shape=img_size + (3, ), dtype=np.uint8)
mask = np.zeros(shape=img_size, dtype=bool)
if draw_joints:
for f, t in LIMB_SEQ:
from_missing = pose_joints[f][0] == MISSING_VALUE or pose_joints[f][1] == MISSING_VALUE
to_missing = pose_joints[t][0] == MISSING_VALUE or pose_joints[t][1] == MISSING_VALUE
if from_missing or to_missing:
continue
yy, xx, val = line_aa(pose_joints[f][0], pose_joints[f][1], pose_joints[t][0], pose_joints[t][1])
colors[yy, xx] = np.expand_dims(val, 1) * 255
mask[yy, xx] = True
for i, joint in enumerate(pose_joints):
if pose_joints[i][0] == MISSING_VALUE or pose_joints[i][1] == MISSING_VALUE:
continue
yy, xx = circle(joint[0], joint[1], radius=radius, shape=img_size)
colors[yy, xx] = COLORS[i]
mask[yy, xx] = True
return colors, mask
示例3: line
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line_aa [as 別名]
def line(self, row1: int, col1: int, row2: int, col2: int,
color: ColorType=None, alpha: float=1.0) -> 'Layer':
"""
Draw a line between two points
:param row1: Start row
:param col1: Start column
:param row2: End row
:param col2: End column
:param color: Color to draw with
"""
rr, cc, aa = draw.line_aa(clamp(0, self.height, row1), clamp(0, self.width, col1),
clamp(0, self.height, row2), clamp(0, self.width, col2))
self._draw(rr, cc, color, aa)
return self
示例4: _render_line
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line_aa [as 別名]
def _render_line(canvas, curr_pos, l_args, absolute, color):
"""Renders a line in the given canvas."""
end_point = l_args
if not absolute:
end_point[0] += curr_pos[0]
end_point[1] += curr_pos[1]
rr, cc, val = draw.line_aa(int(curr_pos[0]), int(curr_pos[1]),
int(end_point[0]), int(end_point[1]))
max_possible = len(canvas)
within_range = lambda x: 0 <= x < max_possible
filtered = [(x, y, v) for x, y, v in zip(rr, cc, val)
if within_range(x) and within_range(y)]
if not filtered:
return
rr, cc, val = list(zip(*filtered))
val = [(v * color) for v in val]
canvas[cc, rr, :] = val
示例5: draw_line
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line_aa [as 別名]
def draw_line(self, data, lX1, lY1, lX2, lY2, clr, alpha=1.0):
'''
Draw a line with the given color and opacity.
data -- image to draw to
lX1 -- x value of line segment start point
lY1 -- y value of line segment start point
lX2 -- x value of line segment end point
lY2 -- y value of line segment end point
clr -- line color, triple of values
alpha -- opacity (default 1.0)
'''
rr, cc, val = line_aa(lY1, lX1, lY2, lX2)
set_color(data, (rr, cc), clr, val*alpha)
示例6: draw_graphcut_weighted_edges
# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line_aa [as 別名]
def draw_graphcut_weighted_edges(segments, centers, edges, edge_weights,
img_bg=None, img_alpha=0.5):
""" visualise the edges on the overlapping a background image
:param [tuple(int,int)] centers: list of centers
:param ndarray segments: np.array<height, width>
:param ndarray edges: list of edges of shape <nb_edges, 2>
:param ndarray edge_weights: weight per edge <nb_edges, 1>
:param ndarray img_bg: image background
:param float img_alpha: transparency
:return ndarray: np.array<height, width, 3>
>>> slic = np.array([[0] * 3 + [1] * 3 + [2] * 3+ [3] * 3] * 4 +
... [[4] * 3 + [5] * 3 + [6] * 3 + [7] * 3] * 4)
>>> centres = [[1, 1], [1, 4], [1, 7], [1, 10],
... [5, 1], [5, 4], [5, 7], [5, 10]]
>>> edges = [[0, 1], [1, 2], [2, 3], [0, 4], [1, 5],
... [4, 5], [2, 6], [5, 6], [3, 7], [6, 7]]
>>> img = np.random.randint(0, 256, slic.shape + (3,))
>>> edge_weights = np.ones(len(edges))
>>> edge_weights[0] = 0
>>> img = draw_graphcut_weighted_edges(slic, centres, edges, edge_weights, img_bg=img)
>>> img.shape
(8, 12, 3)
"""
if img_bg is not None:
if img_bg.ndim == 2:
# duplicate channels to be like RGB
img_bg = np.rollaxis(np.tile(img_bg, (3, 1, 1)), 0, 3)
# convert to range 0,1 so the drawing is correct
max_val = 1.
if img_bg.dtype != np.float:
max_val = max(255., img_bg.max())
img = img_bg.astype(np.float) / max_val
# make it partialy transparent
img = (1. - img_alpha) + img * img_alpha
else:
img = np.zeros(segments.shape + (3,))
clrs = plt.get_cmap('Greens')
diff = (edge_weights.max() - edge_weights.min())
if diff > 0:
edge_ratio = (edge_weights - edge_weights.min()) / diff
else:
edge_ratio = np.zeros(edge_weights.shape)
for i, edge in enumerate(edges):
n1, n2 = edge
y1, x1 = map(int, centers[n1])
y2, x2 = map(int, centers[n2])
# line = draw.line(y1, x1, y2, x2) # , shape=img.shape[:2]
# img[line] = clrs(edge_ratio[i])[:3]
# using anti-aliasing
rr, cc, val = draw.line_aa(y1, x1, y2, x2) # , shape=img.shape[:2]
color_w = np.tile(val, (3, 1)).T
img[rr, cc, :] = color_w * clrs(edge_ratio[i])[:3] + (1 - color_w) * img[rr, cc, :]
circle = draw.circle(y1, x1, radius=2, shape=img.shape[:2])
img[circle] = 1., 1., 0.
return img