From 2c39c773f44a257db1abfc050d25fba688d76d28 Mon Sep 17 00:00:00 2001 From: Pradyumna Narayana Date: Thu, 3 Mar 2016 11:45:09 -0700 Subject: [PATCH] Template mean is precalculated and referenced --- skimage/feature/template.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/skimage/feature/template.py b/skimage/feature/template.py index 7aad0dfb..b58ef983 100644 --- a/skimage/feature/template.py +++ b/skimage/feature/template.py @@ -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)