mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-09 00:47:37 +08:00
Template mean is precalculated and referenced
This commit is contained in:
@@ -131,8 +131,9 @@ def match_template(image, template, pad_input=False, mode='constant',
|
||||
image_window_sum = _window_sum_3d(image, template.shape)
|
||||
image_window_sum2 = _window_sum_3d(image ** 2, template.shape)
|
||||
|
||||
template_mean = template.mean()
|
||||
template_volume = np.prod(template.shape)
|
||||
template_ssd = np.sum((template - template.mean()) ** 2)
|
||||
template_ssd = np.sum((template - template_mean) ** 2)
|
||||
|
||||
if image.ndim == 2:
|
||||
xcorr = fftconvolve(image, template[::-1, ::-1],
|
||||
@@ -141,7 +142,7 @@ def match_template(image, template, pad_input=False, mode='constant',
|
||||
xcorr = fftconvolve(image, template[::-1, ::-1, ::-1],
|
||||
mode="valid")[1:-1, 1:-1, 1:-1]
|
||||
|
||||
nom = xcorr - image_window_sum * (template.sum() / template_volume)
|
||||
nom = xcorr - image_window_sum * template_mean
|
||||
|
||||
denom = image_window_sum2
|
||||
np.multiply(image_window_sum, image_window_sum, out=image_window_sum)
|
||||
|
||||
Reference in New Issue
Block a user