我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用scipy.signal.correlate2d()。
def correlate(self, image): ''' scipy correlate function. veri slow, based on convolution''' corr = signal.correlate2d(image.data, self.data, boundary='symm', mode='same') return Corr(corr)
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
def forward(self, input, filter): result = correlate2d(input.numpy(), filter.numpy(), mode='valid') self.save_for_backward(input, filter) return torch.FloatTensor(result)
def find_template_1D(t, s): c = sp.correlate2d(s, t, mode='valid') raw_index = np.argmax(c) return raw_index
def find_template_2D(template, img): c = sp.correlate2d(img, template, mode='same') # These y, x coordinates represent the peak. This point needs to be # translated to be the top-left corner as the quiz suggests y, x = np.unravel_index(np.argmax(c), c.shape) return y - template.shape[0] // 2, x - template.shape[1] // 2
def _dotProdsWithAllWindows(x, X): """Slide x along the columns of X and compute the dot product""" return sig.correlate2d(X, x, mode='valid').flatten()
def dotProdsWithAllWindows(x, X): """Slide x along the columns of X and compute the dot product >>> x = np.array([[1, 1], [2, 2]]) >>> X = np.arange(12).reshape((2, -1)) >>> dotProdsWithAllWindows(x, X) # doctest: +NORMALIZE_WHITESPACE array([27, 33, 39, 45, 51]) """ return sig.correlate2d(X, x, mode='valid').flatten()