diff --git a/gist.py b/gist.py index 7ddedd1..cff4c4d 100644 --- a/gist.py +++ b/gist.py @@ -41,8 +41,8 @@ def create_gabor(ori, img_size): param = numpy.delete(param, 0, 0) #remove the first empty row #Frequencies - rng_x = range(-img_size[1]/2, img_size[1]/2) - rng_y = range(-img_size[0]/2, img_size[0]/2) + rng_x = range(-int(img_size[1]/2), int(img_size[1]/2)) + rng_y = range(-int(img_size[0]/2), int(img_size[0]/2)) f_x, f_y = numpy.meshgrid(rng_x, rng_y) f_r = numpy.fft.fftshift(numpy.sqrt(numpy.power(f_x, 2) + numpy.power(f_y, 2))) f_t = numpy.fft.fftshift(numpy.angle(f_x + complex(0, 1) * f_y)) @@ -241,16 +241,19 @@ def gist(image_path, orientations = (8,8,8,8), num_blocks = 4, fc_prefilt = 4, img = Image.open(image_path) img = numpy.asarray(img, dtype = float) - img = img.mean(axis = 2) - + if img.ndim > 2: + img = img.mean(axis = 2) + if image_size == None: image_size = numpy.asarray(img.shape) if numpy.ndim(image_size) == 0: image_size = numpy.asarray((image_size, image_size)) - # prepare image - img = _im_resize_crop(img, image_size, 'bilinear') + # prepare image - Make 256x256 + if img.shape[0] != 256 and img.shape[1] != 256: + img = _im_resize_crop(img, image_size, 'bilinear') + img = img - img.min() img = 255. * img / img.max() @@ -284,7 +287,11 @@ def test(img_path): img = trim(img, 256) img.save('_temp.jpg') - print gist('_temp.jpg') + import time + ts = time.time() + g = gist('_temp.jpg',orientations,number_blocks,fc_prefilt,boundary_extension) + print ("processing time:",time.time() - ts) + print (g) if __name__ == '__main__':