Created
August 14, 2018 21:38
-
-
Save amineHorseman/50fdcfbbee0d72b4083e369c631e1709 to your computer and use it in GitHub Desktop.
Apply a sliding window to an image to extract hog features (python)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from skimage.feature import hog | |
import numpy as np | |
image_height = 48 | |
image_width = 48 | |
window_size = 24 | |
window_step = 6 | |
def sliding_hog_windows(image): | |
hog_vector = [] | |
for y in xrange(0, image_height, window_step): | |
for x in xrange(0, image_width, window_step): | |
window = image[y:y+window_size, x:x+window_size] | |
hog_vector.extend(hog(window, orientations=8, pixels_per_cell=(8, 8), | |
cells_per_block=(1, 1), visualise=False)) | |
return hog_vector | |
image = np.load('image.npy') | |
hog_vector = sliding_hog_windows(image) |
@ndetos yes sorry it's an old code from 6 years ago, I was using Python 2.7 at the time, but please do not hesitate to port it to Python 3 by using range() instead of xrange()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python 2 required?