nndl course proj
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.0 KiB

from skimage.io import imread, imshow, imsave
3 years ago
from skimage.transform import resize
from skimage.feature import hog
from skimage import exposure
import matplotlib.pyplot as plt
import sys
import cv2
import numpy as np
3 years ago
import ntpath
3 years ago
def display_image(img):
plt.imshow(img)
plt.show()
3 years ago
def path_leaf(path):
head, tail = ntpath.split(path)
return tail or ntpath.basename(head)
3 years ago
if len(sys.argv) < 2:
print("no input image")
exit(1)
3 years ago
if len(sys.argv) < 3:
print("no output folder")
exit(1)
op_path = sys.argv[2]
3 years ago
img = imread(sys.argv[1], as_gray=True)
print(img.shape)
##resizing to 1:2 aspect ratio for easier calc
# resized_img = resize(img,(1024,512))
resized_img = img
3 years ago
print(resized_img.shape)
# display_image(resized_img)
3 years ago
# calc hog
3 years ago
fd, hog_img = hog(resized_img,
3 years ago
orientations=9,
pixels_per_cell=(2,2),
cells_per_block=(1,1),
3 years ago
visualize=True,
multichannel=False )
# display_image(hog_img)
hog_img = np.array(hog_img, dtype='uint8')
3 years ago
imsave( op_path + "/hog_of" + path_leaf(sys.argv[1]), hog_img)