Python scipy.signal 模块,correlate2d() 实例源码
我们从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, mode='valid').flatten()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。