# How to call
# python .\plot_hog.py <image_file>
# e.g: python .\plot_hog.py .\test_2.jpg
import matplotlib.pyplot as plt
import cv2
import sys
from PIL import Image
import numpy as np
from skimage.feature import hog
from skimage import data, exposure
# image = data.astronaut()
f = sys.argv[1]
print('Processing {}'.format(f))
original = cv2.imread(f)
image = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY)
# Multichannel
# fd, hog_image = hog(image, orientations=8, pixels_per_cell=(16, 16),cells_per_block=(1, 1), visualize=True, multichannel=True)
# Black-White
fd, hog_image = hog(image, orientations=8, pixels_per_cell=(16, 16), cells_per_block=(1, 1), visualize=True, multichannel=False)
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(8, 4), sharex=True, sharey=True)
ax1.axis('off')
ax1.imshow(image, cmap=plt.cm.gray)
ax1.set_title('Black and White image')
# Rescale histogram for better display
hog_image_rescaled = exposure.rescale_intensity(hog_image, in_range=(0, 10))
ax2.axis('off')
ax2.imshow(hog_image_rescaled, cmap=plt.cm.gray)
ax2.set_title('Histogram of Oriented Gradients')
plt.show()
HOG Image Representation
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.