當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。