예제 #1
0
for fileName in sys.argv[1:]:
    try:
        image = Image.open(sourceDirectory + fileName) 
    except:
        print "Could not open the file " + sourceDirectory + fileName + ", skipping."
        continue
    
    try:    
        image = cropImage(image, 20)
    except:
        print "Error cropping " + fileName + ", skipping."
        continue
    #image.save('images/test.png')
    try:
        imgData = splitImage(image, 20).flatten()
    except:
        print "Error splitting " + filename + ", skipping."
        continue
    print fileName, "converted successfully."
    
    embed = imgData * u2 * eigenvalues.getI()
    imageSimilarities = []
    count = 0

    for row in v2:
        imageSimilarities.append(embed.transpose().dot(row.transpose()) / (row.norm() * embed.norm()))

    

예제 #2
0
for line in sourceFiles:
    fileName = line[0]
    try:
        image = Image.open(sourceDirectory + fileName) 
    except:
        print "Could not open the file " + sourceDirectory + fileName + ", skipping."
        continue
    
    try:    
        image = cropImage(image, 20)
    except:
        print "Error cropping " + fileName + ", skipping."
        continue
    #image.save('images/test.png')
    try:
        imgStr = splitImage(image, 20)
    except:
        print "Error splitting " + filename + ", skipping."
        continue
    combinedData = combinedData + convertSplitImageToString(imgStr) + ';'
    print line[0] , "converted successfully."
    #try:
    savedPatterns.writerow([line[0], line[1], convertSplitImageToString(imgStr)])
    #except (RuntimeError, TypeError, NameError):
    #    print 
    #    print "Error writing to .patterns.csv, skipping." 


print "\nAll images converted.\nGetting SVD..."
combinedData = combinedData[:-1]
combinedMatrix = matrix(combinedData)