• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python draw.polygon函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中skimage.draw.polygon函数的典型用法代码示例。如果您正苦于以下问题:Python polygon函数的具体用法?Python polygon怎么用?Python polygon使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了polygon函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_face_mask

def get_face_mask(img,landmarks):
    mask = np.zeros((img.shape[0],img.shape[1]), dtype=img.dtype)
    r = landmarks[0:17,0]
    c = landmarks[0:17,1]
    #rr: row is y-coord, cc: col is x-coord
    rr, cc = draw.polygon(r, c)
    mask[cc, rr] = 255

    #remove left eyes
    r = landmarks[36:42,0]
    c = landmarks[36:42,1]
    rr, cc = draw.polygon(r, c)
    mask[cc, rr] = 0

    #remove right eyes
    r = landmarks[42:48,0]
    c = landmarks[42:48,1]
    rr, cc = draw.polygon(r, c)
    mask[cc, rr] = 0

    #remove lips
    r = landmarks[48:60,0]
    c = landmarks[48:60,1]
    rr, cc = draw.polygon(r, c)
    mask[cc, rr] = 0
    return mask
开发者ID:Kenhouse,项目名称:Leonardo,代码行数:26,代码来源:skinDetection.py


示例2: remove_eyes_and_lips_area

def remove_eyes_and_lips_area(mask,landmarks):
    r = landmarks[0:17,0]
    c = landmarks[0:17,1]
    #rr: row is y-coord, cc: col is x-coord
    rr, cc = draw.polygon(r, c)
    mask[cc, rr] = 255

    #remove left eyes
    r = landmarks[36:42,0]
    c = landmarks[36:42,1]
    rr, cc = draw.polygon(r, c)
    mask[cc, rr] = 0

    #remove right eyes
    r = landmarks[42:48,0]
    c = landmarks[42:48,1]
    rr, cc = draw.polygon(r, c)
    mask[cc, rr] = 0

    #remove lips
    r = landmarks[48:60,0]
    c = landmarks[48:60,1]
    rr, cc = draw.polygon(r, c)
    mask[cc, rr] = 0
    return mask
开发者ID:Kenhouse,项目名称:Leonardo,代码行数:25,代码来源:skinDetection.py


示例3: draw_reference_frame

def draw_reference_frame(x, y, z, h, theta):
    frame = np.ones((2 * y + 1, x + 1))
    frame.fill(0)
    red_x = np.array([0, x // 2, x, 0])
    red_y = np.array([0, y, 0, 0])
    rr, cc = draw.polygon(red_y, red_x)
    frame[rr, cc] = 2
    m = h * x // (2 * y)
    white_x = np.array([m, x - m, z, m])
    white_y = np.array([h, h, 0, h])
    rr, cc = draw.polygon(white_y, white_x)
    frame[rr, cc] = 3

    cy = y
    cx = x // 2 - 1
    radius = cx
    rr, cc = draw.circle(cy, cx, radius)
    zeros = np.ones_like(frame)
    zeros[rr, cc] = 0
    frame[zeros == 1] = 1

    c_in = np.array(frame.shape) // 2
    c_out = np.array(frame.shape) // 2
    transform = np.array([[np.cos(theta), -np.sin(theta)], [np.sin(theta), np.cos(theta)]])
    offset = c_in - c_out.dot(transform)
    frame = ndimage.interpolation.affine_transform(frame, transform.T, order=0, cval=1, offset=offset).astype(int)
    return frame.astype("uint8")
开发者ID:121onto,项目名称:noaa,代码行数:27,代码来源:facial_alignment.py


示例4: create_ringed_spider_mask

def create_ringed_spider_mask(im_shape, ann_out, ann_in=0, sp_width=10,
                              sp_angle=0):
    """
    Mask out information is outside the annulus and inside the spiders (zeros).

    Parameters
    ----------
    im_shape : tuple of int
        Tuple of length two with 2d array shape (Y,X).
    ann_out : int
        Outer radius of the annulus.
    ann_in : int
        Inner radius of the annulus.
    sp_width : int
        Width of the spider arms (3 branches).
    sp_angle : int
        angle of the first spider arm (on the positive horizontal axis) in
        counter-clockwise sense.

    Returns
    -------
    mask : numpy ndarray
        2d array of zeros and ones.

    """
    mask = np.zeros(im_shape)

    s = im_shape[0]
    r = s/2
    theta = np.arctan2(sp_width/2, r)

    t0 = np.array([theta, np.pi-theta, np.pi+theta, np.pi*2 - theta])
    t1 = t0 + sp_angle/180 * np.pi
    t2 = t1 + np.pi/3
    t3 = t2 + np.pi/3

    x1 = r * np.cos(t1) + s/2
    y1 = r * np.sin(t1) + s/2
    x2 = r * np.cos(t2) + s/2
    y2 = r * np.sin(t2) + s/2
    x3 = r * np.cos(t3) + s/2
    y3 = r * np.sin(t3) + s/2

    rr1, cc1 = polygon(y1, x1)
    rr2, cc2 = polygon(y2, x2)
    rr3, cc3 = polygon(y3, x3)

    cy, cx = frame_center(mask)
    rr0, cc0 = circle(cy, cx, min(ann_out, cy))
    rr4, cc4 = circle(cy, cx, ann_in)

    mask[rr0, cc0] = 1
    mask[rr1, cc1] = 0
    mask[rr2, cc2] = 0
    mask[rr3, cc3] = 0
    mask[rr4, cc4] = 0
    return mask
开发者ID:carlgogo,项目名称:VIP,代码行数:57,代码来源:shapes.py


示例5: 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
开发者ID:SamHames,项目名称:scikit-image,代码行数:28,代码来源:lineprofile.py


示例6: __init__

    def __init__(self,image):
        """Extract points, compute Delaunay tessellation, compute features, and make properties
        available:

        image - ndimage the image data
        segments - a set of N indexes of segments that still exist
        vertices(N) - for each segment, the coordinates of its vertices
        pixels(N) - for each segment, the coordinates of its boundary and interior pixels
        neighbors(N) - for each segment, a set of indicies of neighboring segments
        features(N) - for each segment, a dictionary of features"""
        self.image = image
        points = self.find_points()
        tri = Delaunay(points)
        self.segments = set()
        self.vertices = {}
        self.pixels = {}
        self.neighbors = {}
        self.features = {}
        N = len(tri.vertices)
        for v,n in zip(tri.vertices,range(N)):
            py,px = np.rot90(points[v],3) # ccw for y,x
            iy,ix = [f.astype(int) for f in polygon(py,px)] # interior
            oy,ox = outline(py,px) # edges
            self.segments.add(n)
            self.vertices[n] = (py,px)
            self.pixels[n] = (np.concatenate((iy,oy)),np.concatenate((ix,ox)))
            self.neighbors[n] = set(tri.neighbors[n])
            self.features[n] = self.compute_features(n)
开发者ID:LouisK130,项目名称:oii,代码行数:28,代码来源:delaunay.py


示例7: get_indices

 def get_indices(self):
     """Returns a set of points that lie inside the picked polygon."""
     coo = self.get_coords()
     if coo is None:
         return None
     y,x = coo
     return polygon(x,y, self.im)
开发者ID:JoshBradshaw,项目名称:bloodtools,代码行数:7,代码来源:ROI.py


示例8: fromRadialShape

def fromRadialShape(a, r, shape):

	"""
	desc:
		Generates an image array based on angle and radius information. The
		image will be 0 for background and 1 for shape.

	arguments:
		a:
			desc:	An array with angles (radial).
			type:	ndarray
		r:
			desc:	An array with radii (pixels).
			type:	ndarray
		shape:
			desc:	The shape (width, height) for the resulting shape.
			type:	tuple

	returns:
		desc:	An image.
		type:	ndarray
	"""

	x = shape[0]/2 + r * np.cos(a)
	y = shape[1]/2 + r * np.sin(a)
	rr, cc = draw.polygon(x, y)
	im = np.zeros(shape)
	im[rr, cc] = 1
	return im
开发者ID:lvanderlinden,项目名称:004,代码行数:29,代码来源:shape.py


示例9: get_morph

def get_morph(im1, im2, im1_pts_array, imt2_pts_array, t):
    # Get the average image
    mean_pts_array = (im1_pts_array) * (1-t) + (im2_pts_array) * (t)

    # Delaunay Mean
    tri_mean = Delaunay(mean_pts_array)

    #mean_pts_array[:,0], mean_pts_array[:,1] = mean_pts_array[:,1], mean_pts_array[:,0].copy()
    mean_im = np.zeros(im1.shape).astype(float)

    for tri_vert_idxs in tri_mean.simplices.copy():
        vert_idx1, vert_idx2, vert_idx3 = tri_vert_idxs

        im1_tri = np.array([im1_pts_array[vert_idx1], im1_pts_array[vert_idx2], im1_pts_array[vert_idx3]])
        im2_tri = np.array([im2_pts_array[vert_idx1], im2_pts_array[vert_idx2], im2_pts_array[vert_idx3]])
        im_mean_tri = np.array([mean_pts_array[vert_idx1], mean_pts_array[vert_idx2], mean_pts_array[vert_idx3]])

        Trans1 = TriAffine(im_mean_tri, im1_tri)
        Trans2 = TriAffine(im_mean_tri, im2_tri)

        poly_mean_x_idxs, poly_mean_y_idxs = polygon(im_mean_tri[:,0], im_mean_tri[:,1])

        poly1_x_idxs, poly1_y_idxs = Trans1.transform(poly_mean_x_idxs, poly_mean_y_idxs)
        poly2_x_idxs, poly2_y_idxs = Trans2.transform(poly_mean_x_idxs, poly_mean_y_idxs)

        mean_im[poly_mean_x_idxs, poly_mean_y_idxs] = im1[poly1_x_idxs, poly1_y_idxs] * (1-t) + im2[poly2_x_idxs, poly2_y_idxs] * (t)
    return mean_im
开发者ID:girishbalaji,项目名称:girishbalaji.github.io,代码行数:27,代码来源:main.py


示例10: tomask

    def tomask(coords):
        mask = np.zeros(dims)
        coords = np.array(coords)
        rr, cc = polygon(coords[:, 0] + 1, coords[:, 1] + 1)
        mask[rr, cc] = 1

        return mask
开发者ID:Peichao,项目名称:Constrained_NMF,代码行数:7,代码来源:rois.py


示例11: _segment_polygon

    def _segment_polygon(self, image, frame, target,
                         dim,
                         cthreshold, mi, ma):

        src = frame[:]

        wh = get_size(src)
        # make image with polygon
        im = zeros(wh)
        points = asarray(target.poly_points)

        rr, cc = polygon(*points.T)
        im[cc, rr] = 255

        # do watershedding
        distance = ndimage.distance_transform_edt(im)
        local_maxi = feature.peak_local_max(distance, labels=im,
                                            indices=False,
#                                             footprint=ones((1, 1))
                                            )
        markers, ns = ndimage.label(local_maxi)
        wsrc = watershed(-distance, markers,
                        mask=im
                        )
        wsrc = wsrc.astype('uint8')


#         self.test_image.setup_images(3, wh)
#         self.test_image.set_image(distance, idx=0)
#         self.test_image.set_image(wsrc, idx=1)

#         self.wait()

        targets = self._find_polygon_targets(wsrc)
        ct = cthreshold * 0.75
        target = self._test_targets(wsrc, targets, ct, mi, ma)
        if not target:
            values, bins = histogram(wsrc, bins=max((10, ns)))
            # assume 0 is the most abundant pixel. ie the image is mostly background
            values, bins = values[1:], bins[1:]
            idxs = nonzero(values)[0]

            '''
                polygon is now segmented into multiple regions
                consectutively remove a region and find targets
            '''
            nimage = ones_like(wsrc, dtype='uint8') * 255
            nimage[wsrc == 0] = 0
            for idx in idxs:
                bl = bins[idx]
                bu = bins[idx + 1]
                nimage[((wsrc >= bl) & (wsrc <= bu))] = 0

                targets = self._find_polygon_targets(nimage)
                target = self._test_targets(nimage, targets, ct, mi, ma)
                if target:
                    break

        return target
开发者ID:UManPychron,项目名称:pychron,代码行数:59,代码来源:locator.py


示例12: poly_to_mask

def poly_to_mask(vertex_row_coords, vertex_col_coords, shape):
    '''
    Creates a poligon mask
    '''
    fill_row_coords, fill_col_coords = draw.polygon(vertex_row_coords, vertex_col_coords, shape)
    mask = np.zeros(shape, dtype=np.bool)
    mask[fill_row_coords, fill_col_coords] = True
    return mask
开发者ID:ERCpy,项目名称:ercpy,代码行数:8,代码来源:utils.py


示例13: assignPts2Triangles

def assignPts2Triangles(triangles_vertices):
    triLabels = []
    for i,triangle in enumerate(triangles_vertices):
        triangle = np.array(triangle)
        y = triangle[:,1:]
        x = triangle[:,:1]
        rr, cc = polygon(y,x)
        triLabels.append([tuple(pair) for pair in np.vstack((cc,rr)).T])
    return np.array(triLabels)
开发者ID:minyoungg,项目名称:Frankenstein,代码行数:9,代码来源:morph_data_generator.py


示例14: add_background

 def add_background(self):
     dis = self.lv_radius**2/self.e_h
     poly = np.array((
     (self.e_center[0]+self.e_h, self.e_center[1]),
     (self.e_center[0]-self.e_h, self.e_center[1]),
     (self.lv_center[0]-self.lv_radius, self.lv_center[1]),
     (self.lv_center[0]+self.lv_radius, self.lv_center[1]),
     ))
     self.back = d.polygon(poly[:, 0], poly[:, 1])
开发者ID:ZijiaLewisLu,项目名称:HeartDeep-Kaggle-DSB2,代码行数:9,代码来源:maker.py


示例15: __init__

 def __init__(self,roilist,image):
     ''' Construct a list of ROI masks'''
     self.image = image
     self.masks = []
     for roi in roilist:
         empty = np.zeros(image.shape, dtype=np.uint8)
         rr,cc = polygon(roi[1,:],roi[0,:])
         empty[rr, cc] = 1 
         self.masks.append(empty)
开发者ID:mridulafmach,项目名称:Py-MSI,代码行数:9,代码来源:image_tools.py


示例16: test_polygon_rectangle

def test_polygon_rectangle():
    img = np.zeros((10, 10), 'uint8')

    rr, cc = polygon((1, 4, 4, 1, 1), (1, 1, 4, 4, 1))
    img[rr, cc] = 1

    img_ = np.zeros((10, 10))
    img_[1:4, 1:4] = 1

    assert_array_equal(img, img_)
开发者ID:ameya005,项目名称:scikit-image,代码行数:10,代码来源:test_draw.py


示例17: test_polygon_exceed

def test_polygon_exceed():
    img = np.zeros((10, 10), 'uint8')
    poly = np.array(((1, -1), (100, -1), (100, 100), (1, 100), (1, 1)))

    rr, cc = polygon(poly[:, 0], poly[:, 1], img.shape)
    img[rr, cc] = 1

    img_ = np.zeros((10, 10))
    img_[1:, :] = 1

    assert_array_equal(img, img_)
开发者ID:AlexG31,项目名称:scikit-image,代码行数:11,代码来源:test_draw.py


示例18: test_polygon_rectangle

def test_polygon_rectangle():
    img = np.zeros((10, 10), 'uint8')
    poly = np.array(((1, 1), (4, 1), (4, 4), (1, 4), (1, 1)))

    rr, cc = polygon(poly[:, 0], poly[:, 1])
    img[rr, cc] = 1

    img_ = np.zeros((10, 10))
    img_[1:4, 1:4] = 1

    assert_array_equal(img, img_)
开发者ID:AlexG31,项目名称:scikit-image,代码行数:11,代码来源:test_draw.py


示例19: getMeanPoint

def getMeanPoint(outer_axis,inner_axis,pts_array):
    poly=np.array([p for p in inner_axis.coords]+[p for p in reversed(outer_axis.coords)])
    rr, cc = polygon(poly[:, 0], poly[:, 1])
    box_array=np.column_stack((rr,cc))
    pts_inside=multidim_intersect(pts_array,box_array)
    x,y=line2vector(outer_axis)
    center=outer_axis.centroid
    pts_shifted=pts_inside-np.array([center.x,center.y])
    pts_mean=np.mean(pts_shifted[:,0]*x+pts_shifted[:,1]*y)
    new_pt=translate(center,xoff=pts_mean*x, yoff=pts_mean*y)
    return new_pt
开发者ID:kyleellefsen,项目名称:rodentTracker,代码行数:11,代码来源:rodentTracker.py


示例20: convex_hull_image

def convex_hull_image(hull,shape):
    """this can also be computed using
    skimage.measure.regionprops"""
    chi = np.zeros(shape,dtype=np.bool)
    # points in the convex hull
    y, x = polygon(hull[:,0], hull[:,1])
    chi[y,x] = 1
    # points on the convex hull
    for row in np.hstack((hull, np.roll(hull,1,axis=0))):
        chi[line(*row)]=1
    return chi
开发者ID:joefutrelle,项目名称:oii,代码行数:11,代码来源:blob_geometry.py



注:本文中的skimage.draw.polygon函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python exposure.adjust_gamma函数代码示例发布时间:2022-05-27
下一篇:
Python draw.line_aa函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap