Histogram of Gradients in Python from scratch
Project description
HOG_python
Histogram of Gradients in Python from scratch
import sys
from skimage import color, data
import matplotlib.pyplot as plt
from hogpylib.hog import HistogramOfGradients
def main(args=None):
from skimage.feature import hog
PIXELS_PER_CELL = (8, 8)
CELLS_PER_BLOCK = (2, 2)
NUMBER_OF_BINS = ORIENTATIONS = 9 # NUMBER_OF_BINS
VISUALISE = True
orig_img = color.rgb2gray(data.astronaut())
# orig_img = color.rgb2gray(skimage.io.imread("../data/people.jpg"))
custom_hog = HistogramOfGradients(pixels_per_cell=PIXELS_PER_CELL,
cells_per_block=CELLS_PER_BLOCK,
num_of_bins=NUMBER_OF_BINS,
visualise=VISUALISE)
hog_features, hog_image = custom_hog.compute_features(orig_img)
hog_features_check, hog_image_scikit = hog(orig_img,
orientations=ORIENTATIONS,
pixels_per_cell=PIXELS_PER_CELL,
cells_per_block=CELLS_PER_BLOCK,
block_norm='L2',
visualize=VISUALISE)
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(12, 4))
ax1.axis('off')
ax2.axis('off')
ax3.axis('off')
ax1.imshow(orig_img, cmap=plt.get_cmap('gray'))
ax1.set_title('Input Image')
ax2.imshow(hog_image, cmap=plt.get_cmap('gray'))
ax2.set_title('Custom HOG')
ax3.imshow(hog_image_scikit, cmap=plt.get_cmap('gray'))
ax3.set_title('Scikit HOG')
plt.show()
if __name__ == "__main__":
sys.exit(main())
Result
References
[1] http://lear.inrialpes.fr/people/triggs/pubs/Dalal-cvpr05.pdf
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
hogpylib-1.0.0.tar.gz
(1.4 MB
view hashes)
Built Distributions
Close
Hashes for hogpylib-1.0.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0e910d52c588a7fac4c80cd2e3159ed2d1fba5c860fa2370c7252c5ce6bd26e |
|
MD5 | dfeb1c4237c366d9825f656ba3ee3c52 |
|
BLAKE2b-256 | 12e13aa22c2da420f0a49c4c2a08cdab6e2ad6242dcaba8a507940eca8c59a8f |