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


Python draw.polygon_perimeter方法代碼示例

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


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

示例1: coord2_boarder

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import polygon_perimeter [as 別名]
def coord2_boarder(mean_x, mean_y, length, aspect_ratio, rotate, img_size):

    W2 = np.array([[np.cos(rotate), np.sin(rotate)], [-np.sin(rotate), np.cos(rotate)]])

    height = length
    width = height / aspect_ratio

    c = np.array([[-height/2, -width/2], [height/2, -width/2], [height/2, width/2], [-height/2, width/2]])
    c = (W2 @ c.T).T + np.array([mean_y, mean_x])

    img = np.zeros((img_size, img_size), dtype=np.uint8)
    rr, cc = polygon_perimeter(c[:, 0], c[:, 1])

    index = (rr >= 0) * (rr < img_size) * (cc >= 0) * (cc < img_size)

    img[rr[index], cc[index]] = 255
    return img 
開發者ID:toshi-k,項目名稱:kaggle-airbus-ship-detection-challenge,代碼行數:19,代碼來源:img2_coord_ica.py

示例2: draw_on_image

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import polygon_perimeter [as 別名]
def draw_on_image(self, img, color=[0, 255, 0], alpha=1.0, thickness=1, copy=copy):
        assert img.dtype in [np.uint8, np.float32, np.int32, np.int64]

        result = np.copy(img) if copy else img
        for i in range(thickness):
            y = [self.y1-i, self.y1-i, self.y2+i, self.y2+i]
            x = [self.x1-i, self.x2+i, self.x2+i, self.x1-i]
            rr, cc = draw.polygon_perimeter(y, x, shape=img.shape)
            if alpha >= 0.99:
                result[rr, cc, 0] = color[0]
                result[rr, cc, 1] = color[1]
                result[rr, cc, 2] = color[2]
            else:
                if result.dtype == np.float32:
                    result[rr, cc, 0] = (1 - alpha) * result[rr, cc, 0] + alpha * color[0]
                    result[rr, cc, 1] = (1 - alpha) * result[rr, cc, 1] + alpha * color[1]
                    result[rr, cc, 2] = (1 - alpha) * result[rr, cc, 2] + alpha * color[2]
                    result = np.clip(result, 0, 255)
                else:
                    result = result.astype(np.float32)
                    result[rr, cc, 0] = (1 - alpha) * result[rr, cc, 0] + alpha * color[0]
                    result[rr, cc, 1] = (1 - alpha) * result[rr, cc, 1] + alpha * color[1]
                    result[rr, cc, 2] = (1 - alpha) * result[rr, cc, 2] + alpha * color[2]
                    result = np.clip(result, 0, 255).astype(np.uint8)

        return result 
開發者ID:aleju,項目名稱:cat-bbs,代碼行數:28,代碼來源:bbs.py

示例3: _rasterize_polygons

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import polygon_perimeter [as 別名]
def _rasterize_polygons(polygons, bounds = [[-100, -100], [100, 100]], dx = 1, dy = 1):
    try:
        from skimage import draw
    except:
        raise ImportError("""
            The fill function requires the module "scikit-image"
            to operate.  Please retry after installing scikit-image:

            $ pip install --upgrade scikit-image """)


    # Prepare polygon array by shifting all points into the first quadrant and
    # separating points into x and y lists
    xpts = []
    ypts = []
    for p in polygons:
        p_array = np.asarray(p)
        x = p_array[:,0]
        y = p_array[:,1]
        xpts.append((x-bounds[0][0])/dx-0.5)
        ypts.append((y-bounds[0][1])/dy-0.5)

    # Initialize the raster matrix we'll be writing to
    xsize = int(np.ceil((bounds[1][0]-bounds[0][0]))/dx)
    ysize = int(np.ceil((bounds[1][1]-bounds[0][1]))/dy)
    raster = np.zeros((ysize, xsize), dtype=np.bool)

    # TODO: Replace polygon_perimeter with the supercover version
    for n in range(len(xpts)):
        rr, cc = draw.polygon(ypts[n], xpts[n], shape=raster.shape)
        rrp, ccp = draw.polygon_perimeter(ypts[n], xpts[n], shape=raster.shape, clip=False)
        raster[rr, cc] = 1
        raster[rrp, ccp] = 1

    return raster 
開發者ID:amccaugh,項目名稱:phidl,代碼行數:37,代碼來源:geometry.py

示例4: draw_triangle

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import polygon_perimeter [as 別名]
def draw_triangle(self, center: List, length: int):
        """
        Draw a triangle
        :param center: center of the triangle
        :param radius: radius of the triangle
        :return:
        """
        arr = np.zeros(self.canvas_shape, dtype=bool)
        length = 1.732 * length
        rows = [
            int(center[1] + length / (2 * 1.732)),
            int(center[1] + length / (2 * 1.732)),
            int(center[1] - length / 1.732)
        ]
        cols = [
            int(center[0] - length / 2.0),
            int(center[0] + length / 2.0), center[0]
        ]

        rr_inner, cc_inner = draw.polygon(rows, cols, shape=self.canvas_shape)
        rr_boundary, cc_boundary = draw.polygon_perimeter(
            rows, cols, shape=self.canvas_shape)

        ROWS = np.concatenate((rr_inner, rr_boundary))
        COLS = np.concatenate((cc_inner, cc_boundary))
        arr[ROWS, COLS] = True
        return arr 
開發者ID:Hippogriff,項目名稱:CSGNet,代碼行數:29,代碼來源:mixed_len_generator.py

示例5: draw_square

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import polygon_perimeter [as 別名]
def draw_square(self, center: list, length: int):
        """
        Draw a square
        :param center: center of square
        :param length: length of square
        :return:
        """
        arr = np.zeros(self.canvas_shape, dtype=bool)
        length *= 1.412
        # generate the row vertices
        rows = np.array([
            int(center[0] - length / 2.0),
            int(center[0] + length / 2.0),
            int(center[0] + length / 2.0),
            int(center[0] - length / 2.0)
        ])
        cols = np.array([
            int(center[1] + length / 2.0),
            int(center[1] + length / 2.0),
            int(center[1] - length / 2.0),
            int(center[1] - length / 2.0)
        ])

        # generate the col vertices
        rr_inner, cc_inner = draw.polygon(rows, cols, shape=self.canvas_shape)
        rr_boundary, cc_boundary = draw.polygon_perimeter(
            rows, cols, shape=self.canvas_shape)

        ROWS = np.concatenate((rr_inner, rr_boundary))
        COLS = np.concatenate((cc_inner, cc_boundary))

        arr[COLS, ROWS] = True
        return arr 
開發者ID:Hippogriff,項目名稱:CSGNet,代碼行數:35,代碼來源:mixed_len_generator.py

示例6: render_UV_atlas

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import polygon_perimeter [as 別名]
def render_UV_atlas(self, image_name, size=1024):
        if self.vt_faces is None:
            print('Cyka Blyat: Load an obj file first!')
        
        faces = (self.texcoords[self.vt_faces] * size).astype(np.int32)
        img = np.zeros((size, size), dtype=np.uint8)
        for f in faces:
            rr, cc = pope(f[:,0], f[:,1], shape=(size, size))
            img[rr, cc] = 255
            
        imsave(image_name, img) 
開發者ID:Lotayou,項目名稱:densebody_pytorch,代碼行數:13,代碼來源:uv_map_generator.py

示例7: coord2_boarder

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import polygon_perimeter [as 別名]
def coord2_boarder(mean_x, mean_y, length, width, rotate, img_size, img_base=None, weight=1.0):

    polygon_perimeter_clip = partial(polygon_perimeter, clip=True)

    return coord_draw(polygon_perimeter_clip, mean_x, mean_y, length, width, rotate,
                      img_size=img_size, img_base=img_base, weight=weight) 
開發者ID:toshi-k,項目名稱:kaggle-airbus-ship-detection-challenge,代碼行數:8,代碼來源:visualize.py

示例8: overlay_route

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import polygon_perimeter [as 別名]
def overlay_route(image, lat, lon, rgb):
    x, y = latlon_to_xy(image, lat, lon)
    mask = np.zeros((image.height, image.width), dtype=np.float)
    rows, columns = polygon_perimeter(y, x, shape=mask.shape, clip=False)
    mask[rows, columns] = 1
    mask = anti_alias(mask)
    return overlay(image, mask, rgb) 
開發者ID:andrewcooke,項目名稱:choochoo,代碼行數:9,代碼來源:image.py

示例9: draw_on_image

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import polygon_perimeter [as 別名]
def draw_on_image(self, image, color=[0, 255, 0], alpha=1.0, thickness=1, copy=True, raise_if_out_of_image=False): # pylint: disable=locally-disabled, dangerous-default-value, line-too-long
        if raise_if_out_of_image and self.is_out_of_image(image):
            raise Exception("Cannot draw bounding box x1=%.8f, y1=%.8f, x2=%.8f, y2=%.8f on image with shape %s." % (self.x1, self.y1, self.x2, self.y2, image.shape))

        result = np.copy(image) if copy else image
        for i in range(thickness):
            y = [self.y1_int-i, self.y1_int-i, self.y2_int+i, self.y2_int+i]
            x = [self.x1_int-i, self.x2_int+i, self.x2_int+i, self.x1_int-i]
            rr, cc = draw.polygon_perimeter(y, x, shape=result.shape)
            if alpha >= 0.99:
                result[rr, cc, 0] = color[0]
                result[rr, cc, 1] = color[1]
                result[rr, cc, 2] = color[2]
            else:
                if result.dtype in [np.float32, np.float64]:
                    result[rr, cc, 0] = (1 - alpha) * result[rr, cc, 0] + alpha * color[0]
                    result[rr, cc, 1] = (1 - alpha) * result[rr, cc, 1] + alpha * color[1]
                    result[rr, cc, 2] = (1 - alpha) * result[rr, cc, 2] + alpha * color[2]
                    result = np.clip(result, 0, 255)
                else:
                    input_dtype = result.dtype
                    result = result.astype(np.float32)
                    result[rr, cc, 0] = (1 - alpha) * result[rr, cc, 0] + alpha * color[0]
                    result[rr, cc, 1] = (1 - alpha) * result[rr, cc, 1] + alpha * color[1]
                    result[rr, cc, 2] = (1 - alpha) * result[rr, cc, 2] + alpha * color[2]
                    result = np.clip(result, 0, 255).astype(input_dtype)

        return result 
開發者ID:JoshuaPiinRueyPan,項目名稱:ViolenceDetection,代碼行數:30,代碼來源:imgaug.py

示例10: draw_annos

# 需要導入模塊: from skimage import draw [as 別名]
# 或者: from skimage.draw import polygon_perimeter [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


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