From 9c141eadf8759bc503c3c22f6b2e354d3f28a2f7 Mon Sep 17 00:00:00 2001 From: Ivo Flipse Date: Thu, 18 Jun 2015 18:45:29 +0200 Subject: [PATCH] Extracted row_index and cell_row from the inner loop Defined constants that don't have to be recomputed several times --- skimage/feature/_hoghistogram.pyx | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/skimage/feature/_hoghistogram.pyx b/skimage/feature/_hoghistogram.pyx index fde149dd..5f9fa2c1 100644 --- a/skimage/feature/_hoghistogram.pyx +++ b/skimage/feature/_hoghistogram.pyx @@ -45,17 +45,19 @@ cdef float cell_hog(cnp.float64_t[:, :] magnitude, cdef float total = 0. for cell_row in range(-cell_rows/2, cell_rows/2): + cell_row_index = row_index + cell_row + if (cell_row_index < 0 or cell_row_index >= size_rows): + continue + 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] + cell_column_index = column_index + cell_column + if (cell_column_index < 0 or cell_column_index >= size_columns + or orientation[cell_row_index, cell_column_index] >= orientation_start - or orientation[row_index + cell_row, column_index + cell_column] + or orientation[cell_row_index, cell_column_index] < orientation_end): continue - total += magnitude[row_index + cell_row, column_index + cell_column] + total += magnitude[cell_row_index, cell_column_index] return total