Ejemplo n.º 1
0
def setTFList(imageList, centroids, K):
    """
    This method used to set tf list to each image. We use centroids and compare
    distance between sift descriptors in image, and assign these features to 
    visual words.
        [image, image,..], [[int, int,...],...] => [image, image,..]
    """
    
    processGap = len(imageList)/10.0
    processIndex = 0
    imageCount = 0
    
    print 'PROCESS Images ',
    for image in imageList:
        
        if imageCount == len(imageList) - 1:
            print '#'
        
        elif imageCount > processIndex*processGap:
            
            sys.stdout.write('#')
            processIndex = processIndex + 1
        
        imageCount = imageCount + 1
        
        siftDescriptor = image.SIFTdescr

        wordList = []
        
        # get distances between SIFT and centers
        distances = getDistances(centroids, siftDescriptor)
       
        for siftIndex in xrange(len(siftDescriptor)):

            minIndex = np.argmin(distances[siftIndex])
            wordList.append(minIndex)
        
        # save word list into test image
        image.setWordList(wordList)
        
        # get tf list
        tfList = getTFlist(wordList, K)
        
        image.settfList(tfList)

    return imageList
Ejemplo n.º 2
0
def setTFListTrainImageFast(trainImageList, labels, K):
    """
    This method used to use K-means labels result to set tf list to train images.
        [image, image,...], [[int, int,...]] => [image, image,..] 
    """
    start = 0
    
    for trainImage in trainImageList:

        descr = trainImage.SIFTdescr
        trainImage.setWordList(labels[start : start + len(descr)])
        
        wordList = trainImage.wordList
        
        tfList = getTFlist(wordList, K)
        trainImage.settfList(tfList)

        start = start + len(descr)
        
    return trainImageList