HOG Image Representation

# 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 f = sys.argv[1] print('Processing {}'.format(f)) original = cv2.imread(f) imageRGB = cv2.cvtColor(original, cv2.COLOR_BGR2RGB) #to RGB imageBW = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY) #to Black-White # Multichannel fd, hog_image = hog(imageRGB, orientations=8, pixels_per_cell=(16, 16),cells_per_block=(1, 1), visualize=True, multichannel=True) # Black-White fd, hog_image = hog(imageBW, orientations=8, pixels_per_cell=(16, 16),cells_per_block=(1, 1), visualize=True, multichannel=False) fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(8, 4), sharex=True, sharey=True) ax1.axis('off') ax1.imshow(imageRGB, cmap=plt.cm.gray) ax1.set_title('RGB image') # RGB Title ax2.axis('off') ax2.imshow(imageBW, cmap=plt.cm.gray) ax2.set_title('Black and White image') # Black-White Title # Rescale histogram for better display hog_image_rescaled = exposure.rescale_intensity(hog_image, in_range=(0, 10)) ax3.axis('off') ax3.imshow(hog_image_rescaled, cmap=plt.cm.gray) ax3.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.