import hogpy
import numpy as np

def extract(im, nb_bins=9, cwidth=8., block_size=2, unsigned_dirs=True, clip_val=.2):
	if(nb_bins <= 0):
		raise ValueError("Parameter nb_bins has to be larger than 0.")
	if(cwidth <= 0):
		raise ValueError("Parameter cwidth has to be larger than 0.")
	# make sure im is an array
	im = np.array(im)
	# make sure im is a two dimensional array, in each row is one image
	if(im.ndim == 1):
		im = np.array([im])
	# get HoG features of first image so we have the dimensions of the return data
	first = np.array(hogpy.hog(im[0], nb_bins, cwidth, block_size, unsigned_dirs, clip_val))
	# create an empty array for the HoG features for each image
	rest = np.empty((im.shape[0], first.size))
	rest[0] = first
	# from image two onwards get the HoG features and add them to the return array
	for i, image in enumerate(im[1:]):
    		rest[i+1] = np.array(hogpy.hog(image, nb_bins, cwidth, block_size, unsigned_dirs, clip_val))
	return rest
