mirror of
https://github.com/wassname/scikit-image.git
synced 2026-06-28 16:46:53 +08:00
Moved more computations out of loops and added division from future
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
from __future__ import division
|
||||
import numpy as np
|
||||
from .._shared.utils import assert_nD
|
||||
from . import _hoghistogram
|
||||
@@ -123,13 +124,16 @@ def hog(image, orientations=9, pixels_per_cell=(8, 8),
|
||||
from .. import draw
|
||||
|
||||
radius = min(cx, cy) // 2 - 1
|
||||
orientations_arr = np.array(orientations)
|
||||
dx_arr = radius * np.cos(orientations_arr / orientations_arr * np.pi)
|
||||
dy_arr = radius * np.sin(orientations_arr / orientations_arr * np.pi)
|
||||
|
||||
hog_image = np.zeros((sy, sx), dtype=float)
|
||||
for x in range(n_cellsx):
|
||||
for y in range(n_cellsy):
|
||||
for o in range(orientations):
|
||||
for o, dx, dy in zip(orientations_arr, dx_arr, dy_arr):
|
||||
centre = tuple([y * cy + cy // 2, x * cx + cx // 2])
|
||||
dx = radius * np.cos(float(o) / orientations * np.pi)
|
||||
dy = radius * np.sin(float(o) / orientations * np.pi)
|
||||
|
||||
rr, cc = draw.line(int(centre[0] - dx),
|
||||
int(centre[1] + dy),
|
||||
int(centre[0] + dx),
|
||||
|
||||
@@ -106,11 +106,13 @@ def hog_histograms(cnp.float64_t[:, :] gradient_columns,
|
||||
cy2 = cell_rows * number_of_cells_rows
|
||||
cx2 = cell_columns * number_of_cells_columns
|
||||
|
||||
number_of_orientations_per_180 = 180. / number_of_orientations
|
||||
|
||||
# compute orientations integral images
|
||||
for i in range(number_of_orientations):
|
||||
# isolate orientations in this range
|
||||
orientation_start = 180. / number_of_orientations * (i + 1)
|
||||
orientation_end = 180. / number_of_orientations * i
|
||||
orientation_start = number_of_orientations_per_180 * (i + 1)
|
||||
orientation_end = number_of_orientations_per_180 * i
|
||||
|
||||
x = x0
|
||||
y = y0
|
||||
|
||||
Reference in New Issue
Block a user