Ejemplo n.º 1
0
def plotRecommend(removed, recommend, names, clusters, xFactor=10, yFactor=10, myDpi=96):

    """
    removed: the color that we removed from the image
    recommend: the color that was recommended from the modified image
    names: the name of the image we were making a recommendation about
    clusterNames: the names of the images in the cluster we assigned this image to
    """
    imagePath = data.getDataDir(config.amount, cut=True, big=False)
    fig = plt.figure(figsize=(1024 / myDpi, 1024 / myDpi), dpi=myDpi)
    ax = fig.add_subplot(111)
    plt.axis("off")
    ctr = 0
    for i in xrange(len(names)):
        if ctr > SAMPLE_SIZE:
            break
        rr, rg, rb = image.binToRGB(removed[i])
        cr, cg, cb = image.binToRGB(recommend[i])
        rem = "#%02x%02x%02x" % (rr, rg, rb)
        rec = "#%02x%02x%02x" % (cr, cg, cb)
        # print rem
        # print rec
        SQ_SIZE = 50
        SQ_OFFSET = 82
        BASE_OFFSET = 80
        ax.add_patch(patches.Rectangle((125, i * SQ_OFFSET), SQ_SIZE, SQ_SIZE, facecolor=rem))
        ax.add_patch(patches.Rectangle((175, i * SQ_OFFSET), SQ_SIZE, SQ_SIZE, facecolor=rec))
        try:
            imager = mpimg.imread(imagePath + names[i])
            fig.figimage(imager, 125, i * 50 + BASE_OFFSET)

            if len(clusters) > 0:
                plotCluster(clusters[i], 300, i * 50 + BASE_OFFSET, fig)
        except IOError:
            print "%s not found" % imagePath + names[i]
            pass
        ctr += 1
    ax.set_ylim([0, 1024])
    ax.set_xlim([0, 1024])
    plt.show()
Ejemplo n.º 2
0
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg

import time

# Hack to import ml_util from the parent directory
import os, sys
sys.path.insert(1, os.path.join(sys.path[0], '..'))
from ml_util import ml
from data import data

# gets Screenshots directory as string
BIG = True
amount='top-15k'
path = data.getDataDir(amount=amount, cut=True, big=BIG)

# gets all files
fileList = os.listdir(path)
fileExt = ".png"
imgs = filter(lambda File: File[-4:] == fileExt, fileList)
imgs.sort()
print "Found %d %s images" % (len(imgs), fileExt)

def imgToArray(filepath):
    try:
        img = np.array(Image.open(path + imgs[i]))
    except IOError as e:
        print e
    return img[:, :, :3].ravel()
Ejemplo n.º 3
0
def plotCluster(cluster, x, y, plotter):
    imagePath = data.getDataDir(amount=config.amount, cut=True, big=False)
    for i in xrange(len(cluster)):
        imager = mpimg.imread(imagePath + cluster[i])
        plotter.figimage(imager, i * 50 + x, y)
Ejemplo n.º 4
0
#from ml_util import ml
from data import data
from data import image
import config
import core
from ml_util import ml
from cluster_recommender import ClusterRecommender
from duckling_recommender import DucklingRecommender
from random_recommender import RandomRecommender
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import matplotlib.patches as patches

amount = config.amount

path = data.getDataDir(config.amount, config.cut, config.big)

# gets all files
fileList = os.listdir(path)
fileExt = ".png"
imgs = filter(lambda File: File[-4:] == fileExt, fileList)
imgs.sort()
print "Found %d %s images" % (len(imgs), fileExt)


ranks, names, histograms = data.getBinnedHistograms(amount, cut=True, big=False)

X = np.array([image.imgToArray(path+imgs[i]) for i in xrange(len(imgs))])
print X.shape, histograms.shape
website_names = imgs