Exemplo n.º 1
0
    def test_good_image_features_rgb(self):
        test_image = np.random.rand(64, 64, 3).tolist()
        response = image_features(test_image)

        self.assertTrue(isinstance(response, list))
        self.assertEqual(len(response), 2048)
        self.check_range(response)
Exemplo n.º 2
0
def get_indicoio_features(data_dir, local_path):
    if (local_path == 'slides'):
        pathin = data_dir + 'new' + local_path + '/'
    else:
        pathin = data_dir + local_path + '/'
    names = os.listdir(pathin)
    l = len(names)
    new_names = []
    for i in range(l):
        new_names += [local_path[:-1] + str(i) + '.jpg']
    names = new_names

    paths = []
    i = 0
    for f in names:
        i = i + 1
        paths += [pathin + f]
        if (i % 100) == 0:
            print(i)

    features = []
    for i in range(0, len(paths), 20):
        features += indicoio.image_features(paths[i:(i + 20)])
        print((i + 20), " done")
    print("reading " + str(local_path) + " done")
    #write to files
    pathout = data_dir + local_path + '_features.npy'
    np.save(pathout, np.asarray(features))
Exemplo n.º 3
0
    def test_good_image_features_rgb(self):
        test_image = np.random.rand(64, 64, 3).tolist()
        response = image_features(test_image)

        self.assertTrue(isinstance(response, list))
        self.assertEqual(len(response), 2048)
        self.check_range(response)
Exemplo n.º 4
0
    def test_good_image_features_rgb(self):
        test_image = os.path.normpath(os.path.join(DIR, "data/48by48rgb.png"))
        response = image_features(test_image)

        self.assertTrue(isinstance(response, list))
        self.assertEqual(len(response), 2048)
        self.check_range(response)
Exemplo n.º 5
0
    def test_int_RGBA_numpy_arrays(self):
        test_image = np.random.randint(0, 255, size=(48,48, 3))
        response = image_features(test_image)

        self.assertTrue(isinstance(response, list))
        self.assertEqual(len(response), 2048)
        self.check_range(response)
Exemplo n.º 6
0
    def test_float_RGBA_numpy_arrays(self):
        test_image = np.random.random(size=(48,48,4))
        response = image_features(test_image)

        self.assertTrue(isinstance(response, list))
        self.assertEqual(len(response), 4096)
        self.check_range(response)
Exemplo n.º 7
0
    def test_float_RGBA_numpy_arrays(self):
        test_image = np.random.random(size=(48, 48, 4))
        response = image_features(test_image)

        self.assertTrue(isinstance(response, list))
        self.assertEqual(len(response), 4096)
        self.check_range(response)
    def test_image_features_greyscale(self):
        np = self._require_numpy()
        test_image = os.path.normpath(os.path.join(DIR, "data/48by48.png"))
        response = image_features(test_image)

        self.assertTrue(isinstance(response, list))
        self.assertEqual(len(response), 4096)
        self.check_range(response)
    def test_image_features_greyscale(self):
        np = self._require_numpy()
        test_image = os.path.normpath(os.path.join(DIR, "data/48by48.png"))
        response = image_features(test_image)

        self.assertTrue(isinstance(response, list))
        self.assertEqual(len(response), 4096)
        self.check_range(response)
    def test_int_numpy_arrays(self):
        np = self._require_numpy()
        test_image = np.random.randint(0, 255, size=(48, 48))
        response = image_features(test_image)

        self.assertTrue(isinstance(response, list))
        self.assertEqual(len(response), 4096)
        self.check_range(response)
    def test_int_numpy_arrays(self):
        np = self._require_numpy()
        test_image = np.random.randint(0, 255, size=(48,48))
        response = image_features(test_image)

        self.assertTrue(isinstance(response, list))
        self.assertEqual(len(response), 4096)
        self.check_range(response)
Exemplo n.º 12
0
    def _send(self):
        """
        Does a get on the computed link
        Will set storage fields to returned values
        """
        assert self.request and isinstance(self.request, dict), \
            "Trying to make request before having a valid request dictionary."

        response = None
        indicoio.config.api_key = self.config.api_key
        try:
            response = indicoio.image_features(self.request["url"])
        except Exception as exc:
            log.exception(exc)
            self.set_error(-1, connection_error=True)

        self._update_from_response(response)
Exemplo n.º 13
0
    def _send(self):
        """
        Does a get on the computed link
        Will set storage fields to returned values
        """
        assert self.request and isinstance(self.request, dict), \
            "Trying to make request before having a valid request dictionary."

        response = None
        indicoio.config.api_key = self.config.api_key
        try:
            response = indicoio.image_features(self.request["url"])
        except Exception as exc:
            log.exception(exc)
            self.set_error(-1, connection_error=True)

        self._update_from_response(response)
 def test_batch_image_features_rgb(self):
     test_data = [os.path.normpath(os.path.join(DIR, "data/48by48rgb.png"))]
     response = image_features(test_data)
     self.assertTrue(isinstance(response, list))
     self.assertTrue(isinstance(response[0], list))
     self.assertEqual(len(response[0]), 4096)
Exemplo n.º 15
0
def map_frame_to_slide(data_dir):
    slidespath = data_dir + 'slides/'
    framespath = data_dir + 'frames/'
    slidenames = os.listdir(slidespath)
    framenames = os.listdir(framespath)
    l = len(framenames)
    new_framenames = []
    for i in range(l):
        new_framenames += ['frame' + str(i) + '.jpg']
    framenames = new_framenames
    l = len(slidenames)
    new_slidenames = []
    for i in range(l):
        new_slidenames += ['slide' + str(i) + '.jpg']
    slidenames = new_slidenames
    print(slidenames)

    #print (srt_parse)

    slides = []
    for s in slidenames:
        slides += [Image.open(slidespath + s)]

    slides = indicoio.image_features(slides)
    slides = zip(slidenames, slides)
    print("reading slides done")

    frames = []
    i = 0
    for f in framenames:
        i = i + 1
        frames += [(framespath + f)]
        if (i % 100) == 0:
            print(i)

    frame_features = []
    for i in range(0, len(frames), 20):
        frame_features += indicoio.image_features(frames[i:(i + 20)])
        print((i + 20), " done")
    frames = zip(framenames, frame_features)
    print("reading frames done")

    prev_mapping = 'slide0.jpg'
    prev_max = 0
    max_index = 0
    #map each frame to a slide:
    output = []
    for f in frames:
        max_sim = 0
        mapping = 'slide0.jpg'
        for s in slides[max((max_index - 2), 0):]:
            s1 = 1 - spatial.distance.cosine(f[1], s[1])
            print(s[0], s1)
            if (s1 > max_sim):
                max_sim = s1
                mapping = s[0]
        if (max_sim < 0.50):
            mapping = prev_mapping
            max_sim = prev_max
        print(f[0], mapping, max_sim)
        output += [(f[0], mapping, max_sim)]
        max_index = int(mapping.split('slide')[1].split('.jpg')[0])
        prev_mapping = mapping
        prev_max = max_sim

    #write output
    target = open(data_dir + 'frame_mappings.txt', 'w')
    for o in output:
        target.write(str(o) + '\n')
    target.flush()
    target.close()
Exemplo n.º 16
0
def make_feats(paths):
    chunks = [paths[x:x + 100] for x in xrange(0, len(paths), 100)]
    feats = []
    for chunk in chunks:
        feats.extend(indicoio.image_features(chunk, batch=True, version=3))
    return feats
Exemplo n.º 17
0
 def test_batch_image_features_rgb(self):
     test_data = [os.path.normpath(os.path.join(DIR, "data/48by48rgb.png"))]
     response = image_features(test_data, api_key=self.api_key)
     self.assertTrue(isinstance(response, list))
     self.assertTrue(isinstance(response[0], list))
     self.assertEqual(len(response[0]), 2048)
Exemplo n.º 18
0
 def test_batch_image_features_greyscale(self):
     test_data = [os.path.normpath(os.path.join(DIR, "data/48by48.png"))]
     response = image_features(test_data, api_key=self.api_key)
     self.assertTrue(isinstance(response, list))
     self.assertTrue(isinstance(response[0], list))
     self.assertEqual(len(response[0]), 2048)
Exemplo n.º 19
0
def make_feats(paths):
    chunks=[paths[x:x+100] for x in xrange(0, len(paths), 100)]
    feats = []
    for chunk in chunks:
        feats.extend(indicoio.image_features(chunk, batch=True, version=3))
    return feats
 def test_batch_image_features_greyscale(self):
     test_data = [os.path.normpath(os.path.join(DIR, "data/48by48.png"))]
     response = image_features(test_data)
     self.assertTrue(isinstance(response, list))
     self.assertTrue(isinstance(response[0], list))
     self.assertEqual(len(response[0]), 4096)
Exemplo n.º 21
0
 def test_image_features_v2(self):
     test_data = os.path.normpath(os.path.join(DIR, "data", "fear.png"))
     response = image_features(test_data, api_key = self.api_key, version="2")
     self.assertIsInstance(response, list)
     self.assertEqual(len(response), 4096)
Exemplo n.º 22
0
import indicoio
indicoio.config.api_key = 'b8cfad3e06d63c45f6d45f63f4bb9981'
from scipy.misc import imsave, imread
from indicoio import image_features
import json
import os

# Compute image features for all images and save to json.
features = []
i = 0

path = 'image/'
for home, dirs, files in os.walk(path):
    for f in files:
        print i
        if(i>0):
            s = 'image/%s' %f
            filename = '%s' %f
            print(s)
            print(filename)
            img = imread(s)
            new = [filename,image_features(img)]
            features.append(new)
        i = i + 1

json.dump(features, open('features.json', 'wb'))
Exemplo n.º 23
0
 def test_image_features_v2(self):
     test_data = os.path.normpath(os.path.join(DIR, "data", "fear.png"))
     response = image_features(test_data, version="2")
     self.assertIsInstance(response, list)
     self.assertEqual(len(response), 4096)
# -*- coding: utf-8 -*-
from scipy.misc import imsave, imread
from indicoio import image_features
import numpy, os, json

root = 'bcn'
data = []

for f in os.listdir('bcn'):
	import time
	start = time.time()
	img = imread(root + '/' + f)
	features = image_features(img)
	data.append({'file':f,'features':features})
	end = time.time()
	print end - start 

json.dump(data, open('features.json', 'wb'))
Exemplo n.º 25
0
from scipy.misc import imsave, imread
from indicoio import image_features
import json

# Compute image features for all images and save to json.
features = []
for i in range(250):
	img = imread('imgs/%s.png'%i)
	features.append(image_features(img))

json.dump(features, open('features.json', 'wb'))
Exemplo n.º 26
0
import indicoio
indicoio.config.api_key = 'b8cfad3e06d63c45f6d45f63f4bb9981'
from scipy.misc import imsave, imread
from indicoio import image_features
import json
import os

#read image
imagein = imread('input.jpg')
feature = image_features(imagein)

#initial
text = open('features.json').read()
dict = json.loads(text)
t = 0
maxnum = 5
maxnumdot = maxnum - 1

imagenumber = 10
max = []
minname = []
mindistance = []

#compare to find the similarity
for i in range(0, maxnumdot + 1):
    max.append(i)
    minname.append(dict[i][0])
    mindistance.append(0)
    for j in range(0, 2047 + 1):
        mindistance[i] = mindistance[i] + (dict[i][1][j] - feature[j]) * (dict[i][1][j] - feature[j])
Exemplo n.º 27
0
from scipy.misc import imsave, imread
from indicoio import image_features
import json

# Compute image features for all images and save to json.
features = []
for i in range(250):
    img = imread('imgs/%s.png' % i)
    features.append(image_features(img))

json.dump(features, open('features.json', 'wb'))