Python skimage.draw.line_aa() Examples
The following are 6
code examples of skimage.draw.line_aa().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
skimage.draw
, or try the search function
.
Example #1
Source File: pose_utils.py From Human-Pose-Transfer with MIT License | 6 votes |
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
Example #2
Source File: pose_utils.py From everybody_dance_now_pytorch with GNU Affero General Public License v3.0 | 6 votes |
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
Example #3
Source File: layer.py From uchroma with GNU Lesser General Public License v3.0 | 6 votes |
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
Example #4
Source File: svg_utils.py From magenta with Apache License 2.0 | 6 votes |
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
Example #5
Source File: line_dataset.py From DSACLine with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #6
Source File: drawing.py From pyImSegm with BSD 3-Clause "New" or "Revised" License | 4 votes |
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