From d55135ddbb64dba7b1d1c948bed18719a77430ea Mon Sep 17 00:00:00 2001 From: Tim Sheerman-Chase Date: Wed, 19 Jun 2013 09:45:26 +0100 Subject: [PATCH] Fix comments and tab whitespace --- skimage/feature/_hog.py | 1 + skimage/feature/_hoghistogram.pyx | 90 +++++++++++++++---------------- 2 files changed, 46 insertions(+), 45 deletions(-) diff --git a/skimage/feature/_hog.py b/skimage/feature/_hog.py index b9d62926..64ef3bdf 100644 --- a/skimage/feature/_hog.py +++ b/skimage/feature/_hog.py @@ -114,6 +114,7 @@ def hog(image, orientations=9, pixels_per_cell=(8, 8), n_cellsx = int(np.floor(sx // cx)) # number of cells in x n_cellsy = int(np.floor(sy // cy)) # number of cells in y + # compute orientations integral images orientation_histogram = np.zeros((n_cellsy, n_cellsx, orientations)) _hoghistogram.HogHistograms(gx, gy, cx, cy, sx, sy, n_cellsx, n_cellsy, visualise, orientations, diff --git a/skimage/feature/_hoghistogram.pyx b/skimage/feature/_hoghistogram.pyx index 96112730..df38f945 100644 --- a/skimage/feature/_hoghistogram.pyx +++ b/skimage/feature/_hoghistogram.pyx @@ -9,62 +9,62 @@ import numpy as np from scipy import pi, arctan2, cos, sin cdef float CellHog(np.ndarray[np.float64_t, ndim=2] magnitude, - np.ndarray[np.float64_t, ndim=2] orientation, - float ori1, float ori2, - int cx, int cy, int xi, int yi, int sx, int sy): - cdef int cx1, cy1 + np.ndarray[np.float64_t, ndim=2] orientation, + float ori1, float ori2, + int cx, int cy, int xi, int yi, int sx, int sy): + cdef int cx1, cy1 - cdef float total = 0. - for cy1 in range(-cy/2, cy/2): - for cx1 in range(-cx/2, cx/2): - if yi + cy1 < 0: continue - if yi + cy1 >= sy: continue - if xi + cx1 < 0: continue - if xi + cx1 >= sx: continue - if orientation[yi + cy1, xi + cx1] >= ori1: continue - if orientation[yi + cy1, xi + cx1] < ori2: continue + cdef float total = 0. + for cy1 in range(-cy/2, cy/2): + for cx1 in range(-cx/2, cx/2): + if yi + cy1 < 0: continue + if yi + cy1 >= sy: continue + if xi + cx1 < 0: continue + if xi + cx1 >= sx: continue + if orientation[yi + cy1, xi + cx1] >= ori1: continue + if orientation[yi + cy1, xi + cx1] < ori2: continue - total += magnitude[yi + cy1, xi + cx1] + total += magnitude[yi + cy1, xi + cx1] - return total + return total def HogHistograms(np.ndarray[np.float64_t, ndim=2] gx, \ - np.ndarray[np.float64_t, ndim=2] gy, - int cx, int cy, #Pixels per cell - int sx, int sy, #Image size - int n_cellsx, int n_cellsy, - int visualise, int orientations, - np.ndarray[np.float64_t, ndim=3] orientation_histogram): + np.ndarray[np.float64_t, ndim=2] gy, + int cx, int cy, #Pixels per cell + int sx, int sy, #Image size + int n_cellsx, int n_cellsy, + int visualise, int orientations, + np.ndarray[np.float64_t, ndim=3] orientation_histogram): - cdef np.ndarray[np.float64_t, ndim=2] magnitude = np.sqrt(gx**2 + gy**2) - cdef np.ndarray[np.float64_t, ndim=2] orientation = arctan2(gy, gx) * (180 / pi) % 180 - cdef int i, x, y, o, yi, xi, cy1, cy2, cx1, cx2 - cdef float ori1, ori2 + cdef np.ndarray[np.float64_t, ndim=2] magnitude = np.sqrt(gx**2 + gy**2) + cdef np.ndarray[np.float64_t, ndim=2] orientation = arctan2(gy, gx) * (180 / pi) % 180 + cdef int i, x, y, o, yi, xi, cy1, cy2, cx1, cx2 + cdef float ori1, ori2 - # compute orientations integral images + # compute orientations integral images - for i in range(orientations): - # isolate orientations in this range + for i in range(orientations): + # isolate orientations in this range - ori1 = 180. / orientations * (i + 1) - ori2 = 180. / orientations * i + ori1 = 180. / orientations * (i + 1) + ori2 = 180. / orientations * i - y = cy / 2 - cy2 = cy * n_cellsy - x = cx / 2 - cx2 = cx * n_cellsx - yi = 0 - xi = 0 + y = cy / 2 + cy2 = cy * n_cellsy + x = cx / 2 + cx2 = cx * n_cellsx + yi = 0 + xi = 0 - while y < cy2: - xi = 0 - x = cx / 2 + while y < cy2: + xi = 0 + x = cx / 2 - while x < cx2: - orientation_histogram[yi, xi, i] = CellHog(magnitude, orientation, ori1, ori2, cx, cy, x, y, sx, sy) - xi += 1 - x += cx + while x < cx2: + orientation_histogram[yi, xi, i] = CellHog(magnitude, orientation, ori1, ori2, cx, cy, x, y, sx, sy) + xi += 1 + x += cx - yi += 1 - y += cy + yi += 1 + y += cy