From 62bcaf722f8c1ebf9adc3d3cb6281155502bf25f Mon Sep 17 00:00:00 2001 From: wajihullahbaig Date: Fri, 14 Jun 2019 11:46:05 +0500 Subject: [PATCH 1/4] Fix for IndexError: tuple index out of range A gray scale image would not be accepted for processing. --- gist.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gist.py b/gist.py index 7ddedd1..67b5409 100644 --- a/gist.py +++ b/gist.py @@ -241,8 +241,9 @@ 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) From c8179449193ca77af641b98e7f6c7348f3e41511 Mon Sep 17 00:00:00 2001 From: wajihullahbaig Date: Fri, 14 Jun 2019 11:55:41 +0500 Subject: [PATCH 2/4] Exception on 256x256 TypeError: slice indices must be integers or None or have an __index__ method This happens when images are already 256x256 --- gist.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/gist.py b/gist.py index 67b5409..6a9410b 100644 --- a/gist.py +++ b/gist.py @@ -250,8 +250,10 @@ def gist(image_path, orientations = (8,8,8,8), num_blocks = 4, fc_prefilt = 4, 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() From a4cc5b958333861b164051b5550b8ab3e1b1c259 Mon Sep 17 00:00:00 2001 From: wajihullahbaig Date: Fri, 14 Jun 2019 12:00:27 +0500 Subject: [PATCH 3/4] TypeError: 'numpy.float64' Compatibility issue with python 3.5+ --- gist.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gist.py b/gist.py index 6a9410b..dff4560 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)) From 500879b86898770edab18a26ae465cdcb141fbde Mon Sep 17 00:00:00 2001 From: wajihullahbaig Date: Fri, 14 Jun 2019 12:23:11 +0500 Subject: [PATCH 4/4] timing function added python3 compatibility --- gist.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gist.py b/gist.py index dff4560..cff4c4d 100644 --- a/gist.py +++ b/gist.py @@ -287,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__':