Skip to content

Instantly share code, notes, and snippets.

@moaminsharifi
Forked from aishwarya-singh25/hog.py
Created June 4, 2020 05:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moaminsharifi/6b24114f1c9f629ce9c308647e0c2135 to your computer and use it in GitHub Desktop.
Save moaminsharifi/6b24114f1c9f629ce9c308647e0c2135 to your computer and use it in GitHub Desktop.
HOG feature Descriptor
#creating hog features
fd, hog_image = hog(resized_img, orientations=9, pixels_per_cell=(8, 8),
cells_per_block=(2, 2), visualize=True, multichannel=True)
#importing required libraries
from skimage.io import imread, imshow
from skimage.transform import resize
from skimage.feature import hog
from skimage import exposure
import matplotlib.pyplot as plt
%matplotlib inline
#reading the image
img = imread('puppy.jpeg')
imshow(img)
print(img.shape)
#resizing image
resized_img = resize(img, (128,64))
imshow(resized_img)
print(resized_img.shape)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(16, 8), sharex=True, sharey=True)
ax1.imshow(resized_img, cmap=plt.cm.gray)
ax1.set_title('Input image')
# Rescale histogram for better display
hog_image_rescaled = exposure.rescale_intensity(hog_image, in_range=(0, 10))
ax2.imshow(hog_image_rescaled, cmap=plt.cm.gray)
ax2.set_title('Histogram of Oriented Gradients')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment