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


Python holoviews.RGB属性代码示例

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


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

示例1: _process

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import RGB [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

示例2: __init__

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import RGB [as 别名]
def __init__(self, data=None, *args, **kwargs):
        """Initialize a :class:`RGB`."""
        super(RGB, self).__init__(stream=Pipe, plot=holoviews.RGB, data=data, *args, **kwargs) 
开发者ID:FragileTech,项目名称:fragile,代码行数:5,代码来源:streaming.py

示例3: opts

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import RGB [as 别名]
def opts(
        self, xaxis=None, yaxis=None, *args, **kwargs,
    ):
        """
        Update the plot parameters. Same as ``holoviews`` ``opts``.

        The default values updates the plot axes independently when being \
        displayed in a :class:`Holomap`.
        """
        plot_opts = self.update_kwargs(**kwargs)
        self.plot = self.plot.opts(
            holoviews.opts.RGB(xaxis=xaxis, yaxis=yaxis, *args, **plot_opts)
        ) 
开发者ID:FragileTech,项目名称:fragile,代码行数:15,代码来源:streaming.py

示例4: generate_holo_map

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import RGB [as 别名]
def generate_holo_map(rgb_images, height, width):
    frame_map = {}
    for i, image in enumerate(rgb_images):

        # print('image type: ' + str(type(image)))
        hv_rgb = hv.RGB(np.array(image))
        shape = image.shape
        frame_map[i] = hv_rgb
    holomap = hv.HoloMap(frame_map)
    holomap = holomap.options(width=int(width), height=int(height))
    return holomap 
开发者ID:jhu-lcsr,项目名称:costar_plan,代码行数:13,代码来源:stack_player.py

示例5: test_rgb_ellipsis_slice_value

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import RGB [as 别名]
def test_rgb_ellipsis_slice_value(self):
        data = np.random.rand(10,10,3)
        sliced = hv.RGB(data)[:,:,'R']
        self. assertEqual(sliced.data, data[:,:,0]) 
开发者ID:holoviz,项目名称:holoviews,代码行数:6,代码来源:testellipsis.py

示例6: test_rgb_ellipsis_slice_value_missing

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import RGB [as 别名]
def test_rgb_ellipsis_slice_value_missing(self):
        rgb = hv.RGB(np.random.rand(10,10,3))
        try:
            rgb[...,'Non-existent']
        except Exception as e:
            if str(e) != repr("'Non-existent' is not an available value dimension"):
                raise AssertionError("Incorrect exception raised.") 
开发者ID:holoviz,项目名称:holoviews,代码行数:9,代码来源:testellipsis.py

示例7: init_data

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import RGB [as 别名]
def init_data(self):
        self.rgb = RGB(self.rgb_array[::-1], bounds=(-10, 0, 10, 10)) 
开发者ID:holoviz,项目名称:holoviews,代码行数:4,代码来源:testimageinterface.py

示例8: _rgb

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import RGB [as 别名]
def _rgb(self, dat, f):
        return hv.RGB(dat.select(frame=f), kdims=['width', 'height']) 
开发者ID:DeniseCaiLab,项目名称:minian,代码行数:4,代码来源:visualization.py

示例9: _temp_comp_sub

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import RGB [as 别名]
def _temp_comp_sub(self, usub=None):
        if usub is None:
            usub = self.strm_usub.usub
        if self._normalize:
            C, S = self.C_norm_sub, self.S_norm_sub
        else:
            C, S = self.C_sub, self.S_sub
        cur_temp = dict()
        if self._showC:
            cur_temp['C'] = (
                hv.Dataset(C.sel(unit_id=usub)
                           .compute().rename("Intensity (A. U.)")
                           .dropna('frame', how='all')).to(hv.Curve, 'frame'))
        if self._showS:
            cur_temp['S'] = (
                hv.Dataset(S.sel(unit_id=usub)
                           .compute().rename("Intensity (A. U.)")
                           .dropna('frame', how='all')).to(hv.Curve, 'frame'))
        cur_vl = (hv.DynamicMap(
            lambda f, y: hv.VLine(f) if f else hv.VLine(0),
            streams=[self.strm_f])
                  .opts(style=dict(color='red')))
        cur_cv = hv.Curve([], kdims=['frame'], vdims=['Internsity (A.U.)'])
        self.strm_f.source = cur_cv
        h_cv = len(self._w) // 8
        w_cv = len(self._w) * 2
        temp_comp = (cur_cv
                     * datashade_ndcurve(hv.HoloMap(cur_temp, 'trace')
                                         .collate().overlay('trace')
                                         .grid('unit_id')
                                         .add_dimension('time', 0, 0),
                                         'trace')                     
                     .opts(plot=dict(shared_xaxis=True))
                     .map(lambda p: p.opts(
                         plot=dict(frame_height=h_cv,
                                   frame_width=w_cv)),
                          hv.RGB)
                     * cur_vl)
        temp_comp[temp_comp.keys()[0]] = (temp_comp[temp_comp.keys()[0]]
                                           .opts(plot=dict(height=h_cv + 75)))
        return pn.panel(temp_comp) 
开发者ID:DeniseCaiLab,项目名称:minian,代码行数:43,代码来源:visualization.py

示例10: _rgb

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import RGB [as 别名]
def _rgb(self, f):
        dat_orig = list(self.varr.data_vars.values())[0]
        dat_mocc = list(self.varr.data_vars.values())[1]
        w = dat_orig.coords['width']
        h = dat_orig.coords['height']
        try:
            ma = self.match[f]
        except KeyError:
            ma = None
        if ma:
            up = ma['upsample']
            im_src = dat_orig.sel(frame=ma['src_fid']).reindex(
                method='nearest',
                width=np.linspace(w[0], w[-1], len(w) * up),
                height=np.linspace(h[0], h[-1], len(h) * up))
            im_dst = dat_orig.sel(frame=f).reindex(
                method='nearest',
                width=np.linspace(w[0], w[-1], len(w) * up),
                height=np.linspace(h[0], h[-1], len(h) * up))
            img = cv2.drawMatches(im_src.values, ma['src'][0], im_dst.values,
                                  ma['dst'][0], ma['match'], None)
        else:
            try:
                im_src = dat_orig.sel(frame=f - 1)
            except KeyError:
                im_src = dat_orig.sel(frame=f)
            im_dst = dat_orig.sel(frame=f)
            img = xr.concat([im_src, im_dst], dim='width')
            img = xr.concat([img] * 3, dim='color')
            img = img.transpose('height', 'width', 'color').values
        return hv.RGB(img, kdims=['width', 'height']) 
开发者ID:DeniseCaiLab,项目名称:minian,代码行数:33,代码来源:visualization_ply.py

示例11: next_image

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import RGB [as 别名]
def next_image(files, action):
    global file_textbox, button, button_next, button_prev, index
    print("next clicked")
    file_textbox.value = "Processing..."
    renderer = hv.renderer('bokeh')
    if action == 'next':
        index=(index + 1) % len(files)
    else:
        index=(index - 1) % len(files)
    #print("it ", iterator)
    print("index before check",index)
    index = check_errors(files, index, action)
    print("index after check", index)
    print("len", len(files))

    file_name = files[index]
    rgb_images, frame_indices, gripper_status, action_status, gripper_action_label, gripper_action_goal_idx = process_image(file_name)
    print("image loaded")
    print("action goal idx", gripper_action_goal_idx)
    height = int(rgb_images[0].shape[0])
    width = int(rgb_images[0].shape[1])
    start = 0
    end = len(rgb_images) - 1
    print(' End Index of RGB images: ' + str(end))

    def slider_update(attrname, old, new):
        plot.update(slider.value)

    slider = Slider(start=start, end=end, value=0, step=1, title="Frame", width=width)
    slider.on_change('value', slider_update)

    holomap = generate_holo_map(rgb_images, height, width)
    print("generated holomap")
    plot = renderer.get_plot(holomap)
    print("plot rendered")
    gripper_plot, action_plot, gripper_action_plot = load_data_plot(renderer, frame_indices, gripper_status, action_status, gripper_action_label, height, width)
    print("plot loaded..")
    plot_list = [[plot.state], [gripper_plot.state], [action_plot.state]]

    widget_list = [[slider, button, button_prev, button_next], [file_textbox]]

    # "gripper_action" plot, labels based on the gripper opening and closing
    plot_list.append([gripper_action_plot.state])
    layout_child = layout(plot_list + widget_list, sizing_mode='fixed')
    curdoc().clear()
    file_textbox.value = file_name.split("\\")[-1]
    #curdoc().remove_root(layout_child)
    #layout_root.children[0] = layout_child
    curdoc().add_root(layout_child)

#iterator = iter(file_name_list) 
开发者ID:jhu-lcsr,项目名称:costar_plan,代码行数:53,代码来源:stack_player.py

示例12: visualize_spatial_update

# 需要导入模块: import holoviews [as 别名]
# 或者: from holoviews import RGB [as 别名]
def visualize_spatial_update(
        A_dict, C_dict, kdims=None,
        norm=True, datashading=True):
    if not kdims:
        A_dict = dict(dummy=A_dict)
        C_dict = dict(dummy=C_dict)
    hv_pts_dict, hv_A_dict, hv_Ab_dict, hv_C_dict = (
        dict(), dict(), dict(), dict())
    for key, A in A_dict.items():
        A = A.compute()
        C = C_dict[key]
        if norm:
            C = xr.apply_ufunc(
                normalize,
                C.chunk(dict(frame=-1)),
                input_core_dims=[['frame']],
                output_core_dims=[['frame']],
                vectorize=True,
                dask='parallelized',
                output_dtypes=[C.dtype])
        C = C.compute()
        h, w = A.sizes['height'], A.sizes['width']
        cents_df = centroid(A)
        hv_pts_dict[key] = (hv.Points(cents_df,
                                      kdims=['width', 'height'],
                                      vdims=['unit_id'])
                            .opts(plot=dict(tools=['hover']),
                                  style=dict(fill_alpha=0.2,
                                             line_alpha=0, size=8)))
        hv_A_dict[key] = hv.Image(A.sum('unit_id').rename('A'),
                                  kdims=['width', 'height'])
        hv_Ab_dict[key] = hv.Image((A > 0).sum('unit_id').rename('A_bin'),
                                   kdims=['width', 'height'])
        hv_C_dict[key] = hv.Dataset(C.rename('C')).to(hv.Curve, kdims='frame')
    hv_pts = hv.HoloMap(hv_pts_dict, kdims=kdims)
    hv_A = hv.HoloMap(hv_A_dict, kdims=kdims)
    hv_Ab = hv.HoloMap(hv_Ab_dict, kdims=kdims)
    hv_C = (hv.HoloMap(hv_C_dict, kdims=kdims).collate()
            .grid('unit_id').add_dimension('time', 0, 0))
    if datashading:
        hv_A = regrid(hv_A)
        hv_Ab = regrid(hv_Ab)
        hv_C = datashade(hv_C)
    hv_A = hv_A.opts(frame_width=400, aspect=w/h,
                     colorbar=True, cmap='viridis')
    hv_Ab = hv_Ab.opts(frame_width=400, aspect=w/h,
                       colorbar=True, cmap='viridis')
    hv_C = hv_C.map(
        lambda cr: cr.opts(frame_width=500, frame_height=50),
        hv.RGB if datashading else hv.Curve)
    return (hv.NdLayout({
        'pseudo-color': (hv_pts * hv_A),
        'binary': (hv_pts * hv_Ab)}, kdims='Spatial Matrix').cols(1)
            + hv_C.relabel('Temporal Components')) 
开发者ID:DeniseCaiLab,项目名称:minian,代码行数:56,代码来源:visualization.py


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