当前位置: 首页>>代码示例>>Python>>正文


Python holoviews.Polygons方法代码示例

本文整理汇总了Python中holoviews.Polygons方法的典型用法代码示例。如果您正苦于以下问题:Python holoviews.Polygons方法的具体用法?Python holoviews.Polygons怎么用?Python holoviews.Polygons使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在holoviews的用法示例。


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

示例1: setUp

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import Polygons [as 别名]
def setUp(self):
        xs = [1, 2, 3]
        ys = [2, 0, 7]
        holes = [[[(1.5, 2), (2, 3), (1.6, 1.6)], [(2.1, 4.5), (2.5, 5), (2.3, 3.5)]]]
        self.single_poly = Polygons([{'x': xs, 'y': ys, 'holes': holes}])

        xs = [1, 2, 3, np.nan, 6, 7, 3]
        ys = [2, 0, 7, np.nan, 7, 5, 2]
        holes = [
            [[(1.5, 2), (2, 3), (1.6, 1.6)], [(2.1, 4.5), (2.5, 5), (2.3, 3.5)]],
            []
        ]
        self.multi_poly = Polygons([{'x': xs, 'y': ys, 'holes': holes}])
        self.multi_poly_no_hole = Polygons([{'x': xs, 'y': ys}])

        self.distinct_polys = Polygons([
            {'x': xs, 'y': ys, 'holes': holes, 'value': 0},
            {'x': [4, 6, 6], 'y': [0, 2, 1], 'value': 1}], vdims='value') 
开发者ID:holoviz,项目名称:holoviews,代码行数:20,代码来源:testpaths.py

示例2: _process

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import Polygons [as 别名]
def _process(self, element, key=None):
        try:
            import cv2 as cv
        except:
            # HACK: Avoids error loading OpenCV the first time
            # ImportError dlopen: cannot load any more object with static TLS
            try:
                import cv2 as cv
            except ImportError:
                raise ImportError('GrabCut algorithm requires openCV')

        if isinstance(self.p.foreground, hv.Polygons):
            rasterize_op = rasterize_polygon
        else:
            rasterize_op = rasterize.instance(aggregator=ds.any())

        kwargs = {'dynamic': False, 'target': element}
        fg_mask = rasterize_op(self.p.foreground, **kwargs)
        bg_mask = rasterize_op(self.p.background, **kwargs)
        fg_mask = fg_mask.dimension_values(2, flat=False)
        bg_mask = bg_mask.dimension_values(2, flat=False)
        if fg_mask[np.isfinite(fg_mask)].sum() == 0 or bg_mask[np.isfinite(bg_mask)].sum() == 0:
            return element.clone([], vdims=['Foreground'], new_type=gv.Image,
                                 crs=element.crs)

        mask = np.where(fg_mask, 1, 2)
        mask = np.where(bg_mask, 0, mask).copy()
        bgdModel = np.zeros((1,65), np.float64)
        fgdModel = np.zeros((1,65), np.float64)

        if isinstance(element, hv.RGB):
            img = np.dstack([element.dimension_values(d, flat=False)
                             for d in element.vdims])
        else:
            img = element.dimension_values(2, flat=False)
        mask, _, _ = cv.grabCut(img, mask.astype('uint8'), None, bgdModel, fgdModel,
                                self.p.iterations, cv.GC_INIT_WITH_MASK)
        fg_mask = np.where((mask==2)|(mask==0),0,1).astype('bool')
        xs, ys = (element.dimension_values(d, expanded=False) for d in element.kdims)
        return element.clone((xs, ys, fg_mask), vdims=['Foreground'], new_type=gv.Image,
                             crs=element.crs) 
开发者ID:pyviz-topics,项目名称:EarthSim,代码行数:43,代码来源:grabcut.py

示例3: __init__

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import Polygons [as 别名]
def __init__(self, poly_data=[], **params):
        super(SelectRegionPanel, self).__init__(**params)
        self.boxes = gv.Polygons(poly_data).options(
            fill_alpha=0.5, color='grey', line_color='white',
            line_width=2, width=self.width, height=self.height
        )
        if not self.boxes:
            self.boxes = self.boxes.options(global_extent=True)
        self.box_stream = BoxEdit(source=self.boxes, num_objects=1) 
开发者ID:pyviz-topics,项目名称:EarthSim,代码行数:11,代码来源:grabcut.py

示例4: test_bivariate_kde_contours_filled

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import Polygons [as 别名]
def test_bivariate_kde_contours_filled(self):
        np.random.seed(1)
        bivariate = Bivariate(np.random.rand(100, 2))
        kde = bivariate_kde(bivariate, n_samples=100, x_range=(0, 1),
                            y_range=(0, 1), contours=True, filled=True, levels=10)
        self.assertIsInstance(kde, Polygons)
        self.assertEqual(len(kde.data), 10) 
开发者ID:holoviz,项目名称:holoviews,代码行数:9,代码来源:teststatsoperations.py

示例5: test_multi_poly_empty_holes

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import Polygons [as 别名]
def test_multi_poly_empty_holes(self):
        poly = Polygons([])
        self.assertFalse(poly.interface.has_holes(poly))
        self.assertEqual(poly.interface.holes(poly), []) 
开发者ID:holoviz,项目名称:holoviews,代码行数:6,代码来源:testpaths.py

示例6: test_single_poly_hole_validation

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import Polygons [as 别名]
def test_single_poly_hole_validation(self):
        xs = [1, 2, 3]
        ys = [2, 0, 7]
        with self.assertRaises(DataError):
            Polygons([{'x': xs, 'y': ys, 'holes': [[], []]}]) 
开发者ID:holoviz,项目名称:holoviews,代码行数:7,代码来源:testpaths.py

示例7: test_multi_poly_hole_validation

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import Polygons [as 别名]
def test_multi_poly_hole_validation(self):
        xs = [1, 2, 3, np.nan, 6, 7, 3]
        ys = [2, 0, 7, np.nan, 7, 5, 2]
        with self.assertRaises(DataError):
            Polygons([{'x': xs, 'y': ys, 'holes': [[]]}]) 
开发者ID:holoviz,项目名称:holoviews,代码行数:7,代码来源:testpaths.py

示例8: _box

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import Polygons [as 别名]
def _box(self, data):
        if data is None:
            return hv.Polygons([])
        else:
            diag = pd.DataFrame(data)
            corners = []
            for ir, r in diag.iterrows():
                corners.append(
                    np.array([(r['x0'], r['y0']), (r['x0'], r['y1']),
                              (r['x1'], r['y1']), (r['x1'], r['y0'])]))
            return hv.Polygons([{
                ('x', 'y'): cnr.squeeze()
            } for cnr in corners]) 
开发者ID:DeniseCaiLab,项目名称:minian,代码行数:15,代码来源:visualization.py

示例9: roi_draw

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import Polygons [as 别名]
def roi_draw(im):
    h, w = im.sizes['height'], im.sizes['width']
    opts_im = {'plot': {'height': h, 'width': w}, 'style': {'cmap': 'Viridis'}}
    opts_box = {'style': {'fill_alpha': 0.3, 'line_color': 'white'}}
    hv_im = regrid(hv.Image(im, kdims=['width', 'height'])).opts(**opts_im)
    hv_box = hv.Polygons([]).opts(**opts_box)
    str_box = BoxEdit(source=hv_box)
    return hv_im * hv_box, str_box 
开发者ID:DeniseCaiLab,项目名称:minian,代码行数:10,代码来源:visualization.py


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