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