From a52cb01a49038870d7e0f91a9ddbcf0b027da153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20M=C3=A1rquez=20Neila?= Date: Sun, 17 Aug 2014 22:09:03 +0200 Subject: [PATCH] Fix bugs in HOG --- skimage/feature/_hog.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/skimage/feature/_hog.py b/skimage/feature/_hog.py index 67922b92..da9f737e 100644 --- a/skimage/feature/_hog.py +++ b/skimage/feature/_hog.py @@ -1,6 +1,6 @@ import numpy as np from scipy import sqrt, pi, arctan2, cos, sin -from scipy.ndimage import uniform_filter +from scipy.ndimage import uniform_filter, convolve1d def hog(image, orientations=9, pixels_per_cell=(8, 8), @@ -80,10 +80,8 @@ def hog(image, orientations=9, pixels_per_cell=(8, 8), # to avoid problems with subtracting unsigned numbers in np.diff() image = image.astype('float') - gx = np.zeros(image.shape) - gy = np.zeros(image.shape) - gx[:, :-1] = np.diff(image, n=1, axis=1) - gy[:-1, :] = np.diff(image, n=1, axis=0) + gx = convolve1d(image, [-1,0,1], axis=1, mode='nearest') + gy = convolve1d(image, [-1,0,1], axis=0, mode='nearest') """ The third stage aims to produce an encoding that is sensitive to @@ -144,9 +142,9 @@ def hog(image, orientations=9, pixels_per_cell=(8, 8), dx = radius * cos(float(o) / orientations * np.pi) dy = radius * sin(float(o) / orientations * np.pi) rr, cc = draw.line(int(centre[0] - dx), - int(centre[1] - dy), + int(centre[1] + dy), int(centre[0] + dx), - int(centre[1] + dy)) + int(centre[1] - dy)) hog_image[rr, cc] += orientation_histogram[y, x, o] """