當前位置: 首頁>>代碼示例>>Python>>正文


Python draw.line方法代碼示例

本文整理匯總了Python中skimage.draw.line方法的典型用法代碼示例。如果您正苦於以下問題:Python draw.line方法的具體用法?Python draw.line怎麽用?Python draw.line使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在skimage.draw的用法示例。


在下文中一共展示了draw.line方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _find_superpixels

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line [as 別名]
def _find_superpixels(skeleton, heatmap, min_sp_dist):
    logger.debug('Finding superpixels')
    conf_map = heatmap * skeleton
    sp_idx = np.unravel_index(np.argsort(1.-conf_map, axis=None), conf_map.shape)
    if not sp_idx[0].any():
        logger.info('No superpixel candidates found for line vectorizer. Likely empty page.')
        return np.empty(0)
    zeroes_idx = conf_map[sp_idx].argmin()
    if not zeroes_idx:
        logger.info('No superpixel candidates found for line vectorizer. Likely empty page.')
        return np.empty(0)
    sp_idx = sp_idx[0][:zeroes_idx], sp_idx[1][:zeroes_idx]
    sp_can = [(sp_idx[0][0], sp_idx[1][0])]
    for x in range(len(sp_idx[0])):
        loc = np.array([[sp_idx[0][x], sp_idx[1][x]]])
        if min(cdist(sp_can, loc)) > min_sp_dist:
            sp_can.extend(loc.tolist())
    return np.array(sp_can) 
開發者ID:mittagessen,項目名稱:kraken,代碼行數:20,代碼來源:segmentation.py

示例2: LineKernel

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line [as 別名]
def LineKernel(dim, angle, linetype):
    kernelwidth = dim
    kernelCenter = int(math.floor(dim/2))
    angle = SanitizeAngleValue(kernelCenter, angle)
    kernel = np.zeros((kernelwidth, kernelwidth), dtype=np.float32)
    lineAnchors = lineDict.lines[dim][angle]
    if(linetype == 'right'):
        lineAnchors[0] = kernelCenter
        lineAnchors[1] = kernelCenter
    if(linetype == 'left'):
        lineAnchors[2] = kernelCenter
        lineAnchors[3] = kernelCenter
    rr,cc = line(lineAnchors[0], lineAnchors[1], lineAnchors[2], lineAnchors[3])
    kernel[rr,cc]=1
    normalizationFactor = np.count_nonzero(kernel)
    kernel = kernel / normalizationFactor        
    return kernel 
開發者ID:lospooky,項目名稱:pyblur,代碼行數:19,代碼來源:LinearMotionBlur.py

示例3: draw_lines_on_img

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line [as 別名]
def draw_lines_on_img(img, point_ver, point_hor, point_class):
    line_list = [[0, 1], [1, 2], [3, 4], [4, 5], [6, 7], [7, 8], [9, 10],
               [10, 11], [12, 13], [13, 6], [13, 9], [13, 0], [13, 3]]

    # key point class: 1:visible, 2: not visible, 3: not marked
    for start_point_id in range(len(point_class)):
        if point_class[start_point_id] == 3:
            continue
        for end_point_id in range(len(point_class)):
            if point_class[end_point_id] == 3:
                continue

            if [start_point_id, end_point_id] in line_list:
                rr, cc = draw.line(int(point_ver[start_point_id]), int(point_hor[start_point_id]),
                                   int(point_ver[end_point_id]), int(point_hor[end_point_id]))
                draw.set_color(img, [rr, cc], [255, 0, 0])

    return img 
開發者ID:VXallset,項目名稱:deep-high-resolution-net.TensorFlow,代碼行數:20,代碼來源:dataset.py

示例4: to_abs

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line [as 別名]
def to_abs(annos, types, img_size):
    '''Convert relative annotation coordinates to absolute ones
    
    Args:
        annos (list of list):
        types (list of str):
        img_size (tuple): (width, height) of the image in pixels.
    
    Returns:
        list of list: Annotations in absolute format.
    '''
    w, h = img_size
    new = []
    for twod, t in zip(annos,types):
        if t == 'bbox':
            new.append([
                twod[0]*w, twod[1]*h,
                twod[2]*w, twod[3]*h
            ])
        elif t == 'line' or t == 'polygon':
            lp = np.array(twod)
            lp[:,0] = lp[:,0]*w
            lp[:,1] = lp[:,1]*h
            new.append(lp.tolist())
        elif t=='point':
            new.append([twod[0]*w, twod[1]*h])
        else:
            raise Exception('Unknown annotation type: {}'.format(t))
    return np.array(new, dtype=int).tolist() 
開發者ID:l3p-cv,項目名稱:lost,代碼行數:31,代碼來源:anno_helper.py

示例5: joints_plot_image

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line [as 別名]
def joints_plot_image(joints, weight, img, radius=3, thickness=2):
    """ Plot the joints on image

    :param joints:      (np.array)Assuming input of shape (num, joint_num, dim)
    :param img:         (image)Assuming input of shape (num, w, h, c)
    :param weight:      (np.array)Assuming input of shape (num, joint_num)
    :param radius:      (int)Radius
    :param thickness:   (int)Thickness
    :return:            set of RGB image (num, w, h, c)
    """
    assert len(joints.shape) == 3 and len(img.shape) == 4 and len(weight.shape) == 2
    assert joints.shape[0] == img.shape[0] == weight.shape[0]
    colors = [(241, 242, 224), (196, 203, 128), (136, 150, 0), (64, 77, 0),
              (201, 230, 200), (132, 199, 129), (71, 160, 67), (32, 94, 27),
              (130, 224, 255), (7, 193, 255), (0, 160, 255), (0, 111, 255),
              (220, 216, 207), (174, 164, 144), (139, 125, 96), (100, 90, 69),
              (252, 229, 179), (247, 195, 79), (229, 155, 3), (155, 87, 1),
              (231, 190, 225), (200, 104, 186), (176, 39, 156), (162, 31, 123),
              (210, 205, 255), (115, 115, 229), (80, 83, 239), (40, 40, 198)]
    ret = np.zeros(img.shape, np.uint8)
    assert len(joints.shape) == 3 and len(img.shape) == 4
    assert img.shape[-1] == 3
    ret = img.copy()
    for num in range(joints.shape[0]):
        for jnum in range(joints.shape[1]):
            if weight[num, jnum] == 1:
                rr, cc = draw.circle(
                    int(joints[num, jnum, 0]), int(joints[num, jnum, 1]), radius)
                ret[num, rr, cc] = colors[jnum]
    for num in range(joints.shape[0]):
        for lnk in range(len(LINKS)):
            if weight[num, LINKS[lnk][0]] == 1 and weight[num, LINKS[lnk][1]] == 1:
                rr, cc = draw.line(int(joints[num, LINKS[lnk][0], 0]), int(joints[num, LINKS[lnk][0], 1]),
                                int(joints[num, LINKS[lnk][1], 0]), int(joints[num, LINKS[lnk][1], 1]))
                ret[num, rr, cc] = colors[lnk]
    return ret 
開發者ID:mpskex,項目名稱:Convolutional-Pose-Machine-tf,代碼行數:38,代碼來源:predict.py

示例6: closest_point_on_line

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line [as 別名]
def closest_point_on_line(start, end, point):
    """ projection of the point to the line

    :param list(int) start: line starting point
    :param list(int) end: line ending point
    :param list(int) point: point for extimation
    :return list(int): point on the line

    >>> closest_point_on_line([0, 0], [1, 2], [0, 2])
    array([ 0.8,  1.6])
    """
    start, end, point = [np.array(a) for a in [start, end, point]]
    line = pl_line.Line(start, (end - start))
    proj = np.array(line.project(point))
    return proj 
開發者ID:Borda,項目名稱:pyImSegm,代碼行數:17,代碼來源:drawing.py

示例7: __init__

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line [as 別名]
def __init__(self, imgW = 64, imgH = 64, margin = -5, bg_clr = 0.5):
		'''
		Constructor. 

		imgW -- image width (default 64)
		imgH -- image height (default 64)
		margin -- lines segments are sampled within this margin, negative value means that a line segment can start or end outside the image (default -5)
		bg_clr -- background intensity (default 0.5)
		'''
		
		self.imgW = imgW
		self.imgH = imgH
		self.margin = margin
		self.bg_clr = bg_clr 
開發者ID:vislearn,項目名稱:DSACLine,代碼行數:16,代碼來源:line_dataset.py

示例8: draw_line

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line [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) 
開發者ID:vislearn,項目名稱:DSACLine,代碼行數:17,代碼來源:line_dataset.py

示例9: draw_hyps

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line [as 別名]
def draw_hyps(self, labels, scores, data=None):
		'''
		Draw a set of line hypothesis for a batch of images.
		
		labels -- line parameters, array shape (NxMx2) where 
			N is the number of images in the batch
			M is the number of hypotheses per image
			2 is the number of line parameters (intercept, slope)
		scores -- hypotheses scores, array shape (NxM), see above, higher score will be drawn with higher opacity
		data -- batch of images to draw to, if empty a new batch wil be created according to the shape of labels
		
		'''

		n = labels.shape[0] # number of images
		m = labels.shape[1] # number of hypotheses

		if data is None: # create new batch of images
			data = np.zeros((n, self.imgH, self.imgW, 3), dtype=np.float32)
			data.fill(self.bg_clr)

		clr = (0, 0, 1)

		for i in range (0, n):
			for j in range (0, m):
				lY1 = int(labels[i, j, 0] * self.imgH)
				lY2 = int(labels[i, j, 1] * self.imgW + labels[i, j, 0] * self.imgH)
				self.draw_line(data[i], 0, lY1, self.imgW, lY2, clr, scores[i, j])

		return data 
開發者ID:vislearn,項目名稱:DSACLine,代碼行數:31,代碼來源:line_dataset.py

示例10: draw_models

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line [as 別名]
def draw_models(self, labels, data=None, correct=None):
		'''
		Draw lines for a batch of images.
	
		labels -- line parameters, array shape (Nx2) where 
			N is the number of images in the batch
			2 is the number of line parameters (intercept, slope)
		data -- batch of images to draw to, if empty a new batch wil be created according to the shape of labels 
			and lines will be green, lines will be blue otherwise
		correct -- array of shape (N) indicating whether a line estimate is correct 
		'''

		n = labels.shape[0]
		if data is None: 
			data = np.zeros((n, self.imgH, self.imgW, 3), dtype=np.float32)
			data.fill(self.bg_clr)
			clr = (0, 1, 0)
		else:
			clr = (0, 0, 1)

		for i in range (0, n):
			lY1 = int(labels[i, 0] * self.imgH)
			lY2 = int(labels[i, 1] * self.imgW + labels[i, 0] * self.imgH)
			self.draw_line(data[i], 0, lY1, self.imgW, lY2, clr)

			if correct is not None:
				
				# draw border green if estiamte is correct, red otherwise
				if correct[i]: borderclr = (0, 1, 0)
				else: borderclr = (1, 0, 0)
				
				set_color(data[i], line(0, 0, 0, self.imgW-1), borderclr)			
				set_color(data[i], line(0, 0, self.imgH-1, 0), borderclr)			
				set_color(data[i], line(self.imgH-1, 0, self.imgH-1, self.imgW-1), borderclr)			
				set_color(data[i], line(0, self.imgW-1, self.imgH-1, self.imgW-1), borderclr)			

		return data 
開發者ID:vislearn,項目名稱:DSACLine,代碼行數:39,代碼來源:line_dataset.py

示例11: draw_line

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line [as 別名]
def draw_line(output_frame, frame_shape, o, l, color=[255, 0, 0]):
    """

    Parameters
    ----------
    output_frame : numpy.darray
        Video frame to draw the circle. The value of video frame should be of type int [0, 255]
    frame_shape : list or tuple or numpy.darray
        Shape of the frame. For example, (240, 320)
    o : list or tuple or numpy.darray
        Origin of the line, with shape (2,) denoting (x, y).
    l : list or tuple or numpy.darray
        Vector with length. Body of the line. Shape = (2, ), denoting (x, y)
    color : tuple or list or numpy.darray
        RBG colors, e.g. [255, 0, 0] (red color), values of type int [0, 255]

    Returns
    -------
    output frame : numpy.darray
        Frame with the ellipse drawn.
    """
    R, G, B = color
    rr, cc = line(int(np.round(o[0])), int(np.round(o[1])), int(np.round(o[0] + l[0])), int(np.round(o[1] + l[1])))
    rr[rr > int(frame_shape[1]) - 1] = frame_shape[1] - 1
    cc[cc > int(frame_shape[0]) - 1] = frame_shape[0] - 1
    rr[rr < 0] = 0
    cc[cc < 0] = 0
    output_frame[cc, rr, 0] = R
    output_frame[cc, rr, 1] = G
    output_frame[cc, rr, 2] = B
    return output_frame 
開發者ID:pydsgz,項目名稱:DeepVOG,代碼行數:33,代碼來源:visualisation.py

示例12: draw_image

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line [as 別名]
def draw_image(image, segmentation, adjacency, neighborhood):
    neighborhood = list(neighborhood)

    image = mark_boundaries(image, segmentation, (0, 0, 0))

    graph = nx.from_numpy_matrix(adjacency)

    segmentation += np.ones_like(segmentation)
    segments = regionprops(segmentation)

    # Save the centroids in the node properties.
    for (n, data), segment in zip(graph.nodes_iter(data=True), segments):
        data['centroid'] = segment['centroid']

    # Iterate over all edges and draw them.
    for n1, n2, data in graph.edges_iter(data=True):
        y1, x1 = map(int, graph.node[n1]['centroid'])
        y2, x2 = map(int, graph.node[n2]['centroid'])
        line = draw.line(y1, x1, y2, x2)

        n1_idx = neighborhood.index(n1) if n1 in neighborhood else -1
        n2_idx = neighborhood.index(n2) if n2 in neighborhood else -1
        if abs(n1_idx - n2_idx) == 1 and n1_idx != -1 and n2_idx != -1:
            image[line] = [1, 0, 0]
        else:
            image[line] = [0, 1, 0]

    # Draw a circle at the root node.
    for i in range(0, len(neighborhood)):
        if neighborhood[i] < 0:
            continue

        y1, x1 = graph.node[neighborhood[i]]['centroid']
        circle = draw.circle(y1, x1, 2)

        if i == 0:
            image[circle] = [1, 1, 0]
        else:
            j = (i-1)/(len(neighborhood) - 2)
            image[circle] = [j, j, j]

    return image 
開發者ID:rusty1s,項目名稱:graph-based-image-classification,代碼行數:44,代碼來源:segmentation.py

示例13: make_hog_block_image

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line [as 別名]
def make_hog_block_image(hog, config=None):
    """
    References:
        https://github.com/scikit-image/scikit-image/blob/master/skimage/feature/_hog.py
    """
    from skimage import draw

    if config is None:
        config = HOGConfig()

    cx, cy = config['pixels_per_cell']

    normalised_blocks = hog
    (n_blocksy, n_blocksx, by, bx, orientations) = normalised_blocks.shape

    n_cellsx = (n_blocksx - 1) + bx
    n_cellsy = (n_blocksy - 1) + by

    # Undo the normalization step
    orientation_histogram = np.zeros((n_cellsy, n_cellsx, orientations))

    for x in range(n_blocksx):
        for y in range(n_blocksy):
            norm_block = normalised_blocks[y, x, :]
            # hack, this only works right for block sizes of 1
            orientation_histogram[y:y + by, x:x + bx, :] = norm_block

    sx = n_cellsx * cx
    sy = n_cellsy * cy

    radius = min(cx, cy) // 2 - 1
    orientations_arr = np.arange(orientations)
    dx_arr = radius * np.cos(orientations_arr / orientations * np.pi)
    dy_arr = radius * np.sin(orientations_arr / orientations * np.pi)
    hog_image = np.zeros((sy, sx), dtype=float)
    for x in range(n_cellsx):
        for y in range(n_cellsy):
            for o, dx, dy in zip(orientations_arr, dx_arr, dy_arr):
                centre = tuple([y * cy + cy // 2, x * cx + cx // 2])
                rr, cc = draw.line(int(centre[0] - dx),
                                   int(centre[1] + dy),
                                   int(centre[0] + dx),
                                   int(centre[1] - dy))
                hog_image[rr, cc] += orientation_histogram[y, x, o]
    return hog_image 
開發者ID:Erotemic,項目名稱:ibeis,代碼行數:47,代碼來源:core_annots.py

示例14: draw_annos

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line [as 別名]
def draw_annos(annos, types, img, color=(255,0,0), point_r=2):
    '''Draw annotations inside a image

    Args:
        annos (list): List of annotations.
        types (list): List of types.
        img (numpy.array): The image to draw annotations in.
        color (tuple): (R,G,B) color that is used for drawing.
    
    Note:
        The given image will be directly edited!

    Returns:
        numpy.array: Image with drawn annotations
    '''
    if annos:
        if len(img.shape) < 3: 
            img = gray2rgb(img)
        img_h, img_w, _ = img.shape
        for anno, t in zip(annos, types):
            if t == 'bbox':
                anno = trans_boxes_to([anno])[0]
                anno = to_abs([anno], [t], (img_w, img_h))[0]
                xmin, ymin, xmax, ymax = anno
                rr, cc = polygon_perimeter([ymin, ymin, ymax, ymax],
                    [xmin, xmax, xmax, xmin ], shape=img.shape)
            elif t == 'polygon':
                anno = to_abs([anno], [t], (img_w, img_h))[0]
                anno = np.array(anno)
                rr, cc = polygon_perimeter(anno[:,1].tolist(),
                    anno[:,0].tolist(), shape=img.shape)
            elif t == 'point':
                anno = to_abs([anno], [t], (img_w, img_h))[0]
                rr, cc = circle(anno[1], anno[0], point_r, shape=img.shape)
            elif t == 'line':
                anno = to_abs([anno], [t], (img_w, img_h))[0]
                for i, point in enumerate(anno):
                    if i >= (len(anno)-1):
                        break
                    rr, cc = line(point[1], point[0], 
                        anno[i+1][1], anno[i+1][0])
                    img[rr,cc] = color
            else:
                raise ValueError('Unknown annotation type: {}'.format(t))
            img[rr,cc] = color
        return img
    else:
        return [] 
開發者ID:l3p-cv,項目名稱:lost,代碼行數:50,代碼來源:anno_helper.py

示例15: reading_order

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import line [as 別名]
def reading_order(lines: Sequence, text_direction: str = 'lr') -> List:
    """Given the list of lines (a list of 2D slices), computes
    the partial reading order.  The output is a binary 2D array
    such that order[i,j] is true if line i comes before line j
    in reading order."""

    logger.info('Compute reading order on {} lines in {} direction'.format(len(lines), text_direction))

    order = np.zeros((len(lines), len(lines)), 'B')

    def _x_overlaps(u, v):
        return u[1].start < v[1].stop and u[1].stop > v[1].start

    def _above(u, v):
        return u[0].start < v[0].start

    def _left_of(u, v):
        return u[1].stop < v[1].start

    def _separates(w, u, v):
        if w[0].stop < min(u[0].start, v[0].start):
            return 0
        if w[0].start > max(u[0].stop, v[0].stop):
            return 0
        if w[1].start < u[1].stop and w[1].stop > v[1].start:
            return 1
        return 0

    if text_direction == 'rl':
        def horizontal_order(u, v):
            return not _left_of(u, v)
    else:
        horizontal_order = _left_of

    for i, u in enumerate(lines):
        for j, v in enumerate(lines):
            if _x_overlaps(u, v):
                if _above(u, v):
                    order[i, j] = 1
            else:
                if [w for w in lines if _separates(w, u, v)] == []:
                    if horizontal_order(u, v):
                        order[i, j] = 1
    return order 
開發者ID:mittagessen,項目名稱:kraken,代碼行數:46,代碼來源:segmentation.py


注:本文中的skimage.draw.line方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。