Skip to content

Instantly share code, notes, and snippets.

@amineHorseman
Created August 14, 2018 21:38
Show Gist options
  • Save amineHorseman/50fdcfbbee0d72b4083e369c631e1709 to your computer and use it in GitHub Desktop.
Save amineHorseman/50fdcfbbee0d72b4083e369c631e1709 to your computer and use it in GitHub Desktop.
Apply a sliding window to an image to extract hog features (python)
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
Copy link

ndetos commented Sep 21, 2024

python 2 required?

@amineHorseman
Copy link
Author

@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