diff --git a/skimage/detection/_template.pyx b/skimage/detection/_template.pyx index 67a462d7..90bfe666 100644 --- a/skimage/detection/_template.pyx +++ b/skimage/detection/_template.pyx @@ -163,7 +163,8 @@ def match_template(np.ndarray[float, ndim=2, mode="c"] image, np.ndarray[float, ndim=2, mode="c"] template, int num_type): # convolve the image with template by frequency domain multiplication cdef np.ndarray[np.double_t, ndim=2] result - result = np.ascontiguousarray(fftconvolve(image, np.fliplr(template), mode="valid"), dtype=np.double) + result = np.ascontiguousarray(fftconvolve(image, np.fliplr(template), + mode="valid"), dtype=np.double) # calculate squared integral images used for normalization cdef np.ndarray[np.double_t, ndim=2, mode="c"] integral_sum cdef np.ndarray[np.double_t, ndim=2, mode="c"] integral_sqr @@ -193,12 +194,16 @@ def match_template(np.ndarray[float, ndim=2, mode="c"] image, num = result[i, j] window_mean2 = 0 if num_type == 1: - t = sum_integral(integral_sum, i, j, i + template.shape[0], j + template.shape[1]) + t = sum_integral(integral_sum, i, j, + i + template.shape[0], + j + template.shape[1]) window_mean2 = t * t * inv_area num -= t*template_mean # calculate squared template window sum in the image - window_sum2 = sum_integral(integral_sqr, i, j, i + template.shape[0], j + template.shape[1]) + window_sum2 = sum_integral(integral_sqr, i, j, + i + template.shape[0], + j + template.shape[1]) normed = sqrt(window_sum2 - window_mean2) * template_norm # enforce some limits if fabs(num) < normed: diff --git a/skimage/detection/template.py b/skimage/detection/template.py index eb780799..3d8b9a0c 100644 --- a/skimage/detection/template.py +++ b/skimage/detection/template.py @@ -20,10 +20,13 @@ def match_template_cv(image, template, out=None, method="norm-coeff"): Returns ------- output : ndarray, dtype=float - Correlation results between 0.0 and 1.0, maximum indicating the most probable match. + Correlation results between 0.0 and 1.0, maximum indicating the most + probable match. """ if out == None: - out = np.empty((image.shape[0] - template.shape[0] + 1,image.shape[1] - template.shape[1] + 1), dtype=image.dtype) + out = np.empty((image.shape[0] - template.shape[0] + 1, + image.shape[1] - template.shape[1] + 1), + dtype=image.dtype) if method == "norm-corr": cv.MatchTemplate(image, template, out, cv.CV_TM_CCORR_NORMED) elif method == "norm-corr": diff --git a/skimage/detection/tests/test_template.py b/skimage/detection/tests/test_template.py index 987a3496..b5cc9bcd 100644 --- a/skimage/detection/tests/test_template.py +++ b/skimage/detection/tests/test_template.py @@ -23,7 +23,8 @@ def test_template(): if not found_positions: found_positions.append((x, y)) for position in found_positions: - distance = np.sqrt((x - position[0]) ** 2 + (y - position[1]) ** 2) + distance = np.sqrt((x - position[0]) ** 2 + + (y - position[1]) ** 2) if distance > delta: found_positions.append((x, y)) result[y, x] = 0 @@ -34,7 +35,8 @@ def test_template(): print x, y found = False for position in found_positions: - distance = np.sqrt((x - position[0]) ** 2 + (y - position[1]) ** 2) + distance = np.sqrt((x - position[0]) ** 2 + + (y - position[1]) ** 2) if distance < delta: found = True assert found