Example #1
0
def get_image_matrix(image_id):
    # make sure not an ObjectId
    image_id = str(image_id)

    # check if have already calculated the image matrix for it
    if image_id in image_matrices:
        return image_matrices[image_id]
    # calculate the matrix for it, store it, and return it
    else:
        image_file = db.get_image_file(image_id)
        image_matrices[image_id] = array(imageGen.loadImage(image_file))
        return image_matrices[image_id]
Example #2
0
def sort_and_print_set(set_id=None):
    if set_id == None:
        # choose a set
        image_sets = db.get_all_image_sets()
        set_id = image_sets[0]['_id']

    print "Sorting image set with id " + str(set_id)

    # partition it
    (probs, partition) = sort_image_set(set_id)
    print "Image set sorted"

    # save the results to disk
    base = "./sort"
    name = base
    number = 0
    while os.path.exists(name) or os.path.exists(name + ".txt"):
        name = base + str(number)
        number += 1

    # print the results
    os.makedirs(name + "/")
    f = open(name + ".txt", 'w')
    f.write("SORT\n")
    groups = groups_in_partition(partition)
    for group in groups:
        print "Group " + str(group) + ":"
        f.write("Group " + str(group) + ":\n")
        group_images = images_in_group(partition, group)
        i = 0

        for image in group_images:
            fileName = name + "/" + str(group) + "-" + str(i) + ".png"
            imageObj = Image.open(db.get_image_file(image))
            imageObj.save(fileName, "PNG")
            print "\t" + fileName
            f.write("\t" + fileName + "\n")
            i += 1
    print "DONE"
    f.write("DONE\n")
    f.close()
Example #3
0
def image(image_id):
    # get the image
    image = db.get_image_file(image_id)

    return send_file(image, mimetype=image.content_type, cache_timeout=0)