Renamed to use row/column naming convention.

This commit is contained in:
Korijn van Golen
2015-06-16 09:54:54 +02:00
parent 78cf5a0f9a
commit 605eac2e8c
+51 -51
View File
@@ -7,10 +7,10 @@ cimport numpy as cnp
cdef float cell_hog(cnp.float64_t[:, :] magnitude,
cnp.float64_t[:, :] orientation,
float ori1, float ori2,
int cx, int cy,
int xi, int yi,
int sx, int sy):
float orientation_start, float orientation_end,
int cell_columns, int cell_rows,
int column_index, int row_index,
int size_columns, int size_rows):
"""Calculation of the cell's HOG value
Parameters
@@ -19,21 +19,21 @@ cdef float cell_hog(cnp.float64_t[:, :] magnitude,
The gradient magnitudes of the pixels.
orientation : ndarray
Lookup table for orientations.
ori1 : float
orientation_start : float
Orientation range start.
ori2 : float
orientation_end : float
Orientation range end.
cx : int
cell_columns : int
Pixels per cell (x).
cy : int
cell_rows : int
Pixels per cell (y).
xi : int
column_index : int
Block column index.
yi : int
row_index : int
Block row index.
sx : int
size_columns : int
Number of columns.
sy : int
size_rows : int
Number of rows.
Returns
@@ -41,85 +41,85 @@ cdef float cell_hog(cnp.float64_t[:, :] magnitude,
total : float
The total HOG value.
"""
cdef int cx1, cy1
cdef int cell_column, cell_row
cdef float total = 0.
for cy1 in range(-cy/2, cy/2):
for cx1 in range(-cx/2, cx/2):
if (yi + cy1 < 0
or yi + cy1 >= sy
or xi + cx1 < 0
or xi + cx1 >= sx
or orientation[yi + cy1, xi + cx1] >= ori1
or orientation[yi + cy1, xi + cx1] < ori2): continue
for cell_row in range(-cell_rows/2, cell_rows/2):
for cell_column in range(-cell_columns/2, cell_columns/2):
if (row_index + cell_row < 0
or row_index + cell_row >= size_rows
or column_index + cell_column < 0
or column_index + cell_column >= size_columns
or orientation[row_index + cell_row, column_index + cell_column] >= orientation_start
or orientation[row_index + cell_row, column_index + cell_column] < orientation_end): continue
total += magnitude[yi + cy1, xi + cx1]
total += magnitude[row_index + cell_row, column_index + cell_column]
return total
def hog_histograms(cnp.float64_t[:, :] gx,
cnp.float64_t[:, :] gy,
int cx, int cy,
int sx, int sy,
int n_cellsx, int n_cellsy,
int orientations,
def hog_histograms(cnp.float64_t[:, :] gradient_columns,
cnp.float64_t[:, :] gradient_rows,
int cell_columns, int cell_rows,
int size_columns, int size_rows,
int number_of_cells_columns, int number_of_cells_rows,
int number_of_orientations,
cnp.float64_t[:, :, :] orientation_histogram):
"""Extract Histogram of Oriented Gradients (HOG) for a given image.
Parameters
----------
gx : ndarray
gradient_columns : ndarray
First order image gradients (x).
gy : ndarray
gradient_rows : ndarray
First order image gradients (y).
cx : int
cell_columns : int
Pixels per cell (x).
cy : int
cell_rows : int
Pixels per cell (y).
sx : int
size_columns : int
Number of columns.
sy : int
size_rows : int
Number of rows.
n_cellsx : int
number_of_cells_columns : int
Number of cells (x).
n_cellsy : int
number_of_cells_rows : int
Number of cells (y).
orientations : int
number_of_orientations : int
Number of orientation bins.
orientation_histogram : ndarray
The histogram to fill.
"""
cdef cnp.float64_t[:, :] magnitude = np.hypot(gx, gy)
cdef cnp.float64_t[:, :] orientation = np.arctan2(gy, gx) * (180 / np.pi) % 180
cdef cnp.float64_t[:, :] magnitude = np.hypot(gradient_columns, gradient_rows)
cdef cnp.float64_t[:, :] orientation = np.arctan2(gradient_rows, gradient_columns) * (180 / np.pi) % 180
cdef int i, x, y, o, yi, xi, cy1, cy2, cx1, cx2
cdef float ori1, ori2
cdef float orientation_start, orientation_end
# compute orientations integral images
for i in range(orientations):
for i in range(number_of_orientations):
# isolate orientations in this range
ori1 = 180. / orientations * (i + 1)
ori2 = 180. / orientations * i
orientation_start = 180. / number_of_orientations * (i + 1)
orientation_end = 180. / number_of_orientations * i
y = cy / 2
cy2 = cy * n_cellsy
x = cx / 2
cx2 = cx * n_cellsx
y = cell_rows / 2
cy2 = cell_rows * number_of_cells_rows
x = cell_columns / 2
cx2 = cell_columns * number_of_cells_columns
yi = 0
xi = 0
while y < cy2:
xi = 0
x = cx / 2
x = cell_columns / 2
while x < cx2:
orientation_histogram[yi, xi, i] = cell_hog(magnitude,
orientation, ori1, ori2, cx, cy, x, y, sx, sy)
orientation, orientation_start, orientation_end, cell_columns, cell_rows, x, y, size_columns, size_rows)
xi += 1
x += cx
x += cell_columns
yi += 1
y += cy
y += cell_rows