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


Python util.view_as_windows方法代码示例

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


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

示例1: patchify

# 需要导入模块: from skimage import util [as 别名]
# 或者: from skimage.util import view_as_windows [as 别名]
def patchify(image: np.ndarray, patch_size: Imsize, step: int = 1) -> np.ndarray:
    """
    Split a 2D or 3D image into small patches given the patch size.

    Parameters
    ----------
    image: the image to be split. It can be 2d (m, n) or 3d (k, m, n)
    patch_size: the size of a single patch
    step: the step size between patches

    Examples
    --------
    >>> image = np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]])
    >>> patches = patchify(image, (2, 2), step=1)  # split image into 2*3 small 2*2 patches.
    >>> assert patches.shape == (2, 3, 2, 2)
    >>> reconstructed_image = unpatchify(patches, image.shape)
    >>> assert (reconstructed_image == image).all()
    """
    return view_as_windows(image, patch_size, step) 
开发者ID:dovahcrow,项目名称:patchify.py,代码行数:21,代码来源:__init__.py

示例2: get_reg_ftr

# 需要导入模块: from skimage import util [as 别名]
# 或者: from skimage.util import view_as_windows [as 别名]
def get_reg_ftr(self, channels, smp_loc=None):
        """
        Compute regular features.

        :param channels: shrunk channels for regular features
        :param smp_loc: shrunk sample locations (None for all)
        :return: regular features
        """

        shrink = self.options["shrink"]
        p_size = self.options["p_size"] / shrink
        n_r, n_c, n_ch = channels.shape

        reg_ftr = view_as_windows(channels, (p_size, p_size, n_ch))
        reg_ftr = reg_ftr.reshape((n_r - p_size + 1, n_c - p_size + 1,
                                   p_size ** 2 * n_ch))

        if smp_loc is not None:
            r_pos = [r - p_size / 2 for r, _ in smp_loc]
            c_pos = [c - p_size / 2 for _, c in smp_loc]
            reg_ftr = reg_ftr[r_pos, c_pos]

        return reg_ftr 
开发者ID:ArtanisCV,项目名称:StructuredForests,代码行数:25,代码来源:BaseStructuredForests.py

示例3: _search_minimum_distance

# 需要导入模块: from skimage import util [as 别名]
# 或者: from skimage.util import view_as_windows [as 别名]
def _search_minimum_distance(self, ref, buff):
        if len(ref) < self.fl:
            ref = np.r_[ref, np.zeros(self.fl - len(ref))]

        # slicing and windowing one sample by one
        buffmat = view_as_windows(buff, self.fl) * self.win
        refwin = np.array(ref * self.win).reshape(1, self.fl)
        corr = correlate2d(buffmat, refwin, mode='valid')

        return np.argmax(corr) - self.sl 
开发者ID:k2kobayashi,项目名称:sprocket,代码行数:12,代码来源:wsola.py

示例4: _get_patches

# 需要导入模块: from skimage import util [as 别名]
# 或者: from skimage.util import view_as_windows [as 别名]
def _get_patches(mspec, w, step):
    h = mspec.shape[1]
    data = vaw(mspec, (w,h), step=step)
    data.shape = (len(data), w*h)
    data = (data - np.mean(data, axis=1).reshape((len(data), 1))) / np.std(data, axis=1).reshape((len(data), 1))
    lfill = [data[0,:].reshape(1, h*w)] * (w // (2 * step))
    rfill = [data[-1,:].reshape(1, h*w)] * (w // (2* step) - 1 + len(mspec) % 2)
    data = np.vstack(lfill + [data] + rfill )
    finite = np.all(np.isfinite(data), axis=1)
    data.shape = (len(data), w, h)
    return data, finite 
开发者ID:ina-foss,项目名称:inaSpeechSegmenter,代码行数:13,代码来源:segmenter.py

示例5: colfilt

# 需要导入模块: from skimage import util [as 别名]
# 或者: from skimage.util import view_as_windows [as 别名]
def colfilt(A, kernelSize, option):
    
    from skimage.util import view_as_windows as viewW
    import numpy as np
    
    A = np.lib.pad(A,((int((kernelSize[0]-1)/2),int((kernelSize[0]-1)/2)),(int((kernelSize[1]-1)/2),int((kernelSize[1]-1)/2))),mode='constant',constant_values=np.nan)
    
    B = viewW(A, kernelSize).reshape(-1,kernelSize[0]*kernelSize[1]).T[:,::1]
    
    output_size = (A.shape[0]-kernelSize[0]+1,A.shape[1]-kernelSize[1]+1)
    C = np.zeros(output_size,dtype=A.dtype)
    if option == 0:#    max
        C = np.nanmax(B,axis=0).reshape(output_size)
    elif option == 1:#  min
        C = np.nanmin(B,axis=0).reshape(output_size)
    elif option == 2:#  mean
        C = np.nanmean(B,axis=0).reshape(output_size)
    elif option == 3:#  median
        C = np.nanmedian(B,axis=0).reshape(output_size)
    elif option == 4:#  range
        C = np.nanmax(B,axis=0).reshape(output_size) - np.nanmin(B,axis=0).reshape(output_size)
    elif option == 6:#  MAD (Median Absolute Deviation)
        m = B.shape[0]
        D = np.abs(B - np.dot(np.ones((m,1),dtype=A.dtype), np.array([np.nanmedian(B,axis=0)])))
        C = np.nanmedian(D,axis=0).reshape(output_size)
    elif option[0] == 5:#  displacement distance count with option[1] being the threshold
        m = B.shape[0]
        c = int(np.round((m + 1) / 2)-1)
#        c = 0
        D = np.abs(B - np.dot(np.ones((m,1),dtype=A.dtype), np.array([B[c,:]])))
        C = np.sum(D<option[1],axis=0).reshape(output_size)
    else:
        sys.exit('invalid option for columnwise neighborhood filtering')

    C = C.astype(A.dtype)
    
    return C 
开发者ID:leiyangleon,项目名称:autoRIFT,代码行数:39,代码来源:autoRIFT.py

示例6: get_ss_ftr

# 需要导入模块: from skimage import util [as 别名]
# 或者: from skimage.util import view_as_windows [as 别名]
def get_ss_ftr(self, channels, smp_loc=None):
        """
        Compute self-similarity features

        :param channels: shrunk channels for self-similarity features
        :param smp_loc: shrunk sample locations (None for all)
        :return: self-similarity features
        """

        shrink = self.options["shrink"]
        p_size = self.options["p_size"] / shrink
        n_r, n_c, n_ch = channels.shape

        ss_ftr = view_as_windows(channels, (p_size, p_size, n_ch))

        if smp_loc is not None:
            ss_ftr = ss_ftr.reshape((n_r - p_size + 1, n_c - p_size + 1,
                                     p_size ** 2, n_ch))
            r_pos = [r - p_size / 2 for r, _ in smp_loc]
            c_pos = [c - p_size / 2 for _, c in smp_loc]
            ss_ftr = ss_ftr[r_pos, c_pos]
        else:
            ss_ftr = ss_ftr.reshape((-1, p_size ** 2, n_ch))

        n_cell = self.options["n_cell"]
        half_cell_size = int(round(p_size / (2.0 * n_cell)))
        grid_pos = [int(round((i + 1) * (p_size + 2 * half_cell_size - 1) / \
                              (n_cell + 1.0) - half_cell_size))
                    for i in xrange(n_cell)]
        grid_pos = [r * p_size + c for r in grid_pos for c in grid_pos]
        ss_ftr = ss_ftr[:, grid_pos]

        ss_ftr = pdist(ss_ftr)
        return ss_ftr.reshape((ss_ftr.shape[0], -1)) 
开发者ID:ArtanisCV,项目名称:StructuredForests,代码行数:36,代码来源:BaseStructuredForests.py

示例7: run

# 需要导入模块: from skimage import util [as 别名]
# 或者: from skimage.util import view_as_windows [as 别名]
def run(self, xs, ys=None, batch_size=None):
        self._check_input_compatibility(xs, ys, batch_size)
        input_shape = xs.shape[1:]
        batch_size = xs.shape[0]
        total_dim = np.asscalar(np.prod(input_shape))

        # Create mask
        index_matrix = np.arange(total_dim).reshape(input_shape)
        idx_patches = view_as_windows(index_matrix, self.window_shape, self.step).reshape((-1,) + self.window_shape)
        heatmap = np.zeros_like(xs, dtype=np.float32).reshape((-1), total_dim)
        w = np.zeros_like(heatmap)

        # Compute original output
        eval0 = self._session_run(self.T, xs, ys, batch_size)

        # Start perturbation loop
        for i, p in enumerate(idx_patches):
            mask = np.ones(input_shape).flatten()
            mask[p.flatten()] = self.replace_value
            masked_xs = mask.reshape((1,) + input_shape) * xs
            delta = eval0 - self._session_run(self.T, masked_xs, ys, batch_size)
            delta_aggregated = np.sum(delta.reshape((batch_size, -1)), -1, keepdims=True)
            heatmap[:, p.flatten()] += delta_aggregated
            w[:, p.flatten()] += p.size

        attribution = np.reshape(heatmap / w, xs.shape)
        if np.isnan(attribution).any():
            warnings.warn('Attributions generated by Occlusion method contain nans, '
                          'probably because window_shape and step do not allow to cover the all input.')
        return attribution 
开发者ID:marcoancona,项目名称:DeepExplain,代码行数:32,代码来源:methods.py


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