def processTest(testImageNumList, K, idfList, centers):
    """
    This method used to process test images, and transform images to space vector model, and 
    return testImage list.
    """
    
    testImages = []
    
    processGap = len(testImageNumList)/10.0
    processIndex = 0
    
    for testImageIndex in xrange(len(testImageNumList)):
        
        if testImageIndex == len(testImageNumList) - 1:
            print ''
        
        elif testImageIndex > processIndex*processGap:
            
                sys.stdout.write('#')
                processIndex = processIndex + 1
        
        imageName = readImage.getImageName(testImageNumList[testImageIndex])
        SIFTdescr = processSIFT.getSIFT(imageName)
        
        # new train image object, with image name, testImageIndex and SIFT
        testImageObject = Image.Image(imageName, testImageIndex, SIFTdescr)
        testImages.append(testImageObject)
    
        wordList = []
        SIFTdescr = testImages[testImageIndex].SIFTdescr

        # get distances between SIFT and centers
        distances = getDistances(centers, SIFTdescr)
        
        for siftIndex in xrange(len(testImages[testImageIndex].SIFTdescr)):
            # minIndex, minValue = min(enumerate(distances[siftIndex], key = operator.itemgetter(1)))
            
            minIndex = np.argmin(distances[siftIndex])
            wordList.append(minIndex)
        
        # save word list into test image
        testImages[testImageIndex].setWordList(wordList)
        
        # get tf list
        tfList = getTFlist(wordList, K)
        
        svm = getVSM(tfList, idfList)
        testImages[testImageIndex].setVSM(svm)
        # print svm
    
    return testImages
Exemple #2
0
def processTest(testImageNumList, K, idfList, centers):
    """
    This method used to process test images, and transform images to space vector model, and 
    return testImage list.
    """

    testImages = []

    processGap = len(testImageNumList) / 10.0
    processIndex = 0

    for testImageIndex in xrange(len(testImageNumList)):

        if testImageIndex == len(testImageNumList) - 1:
            print ''

        elif testImageIndex > processIndex * processGap:

            sys.stdout.write('#')
            processIndex = processIndex + 1

        imageName = readImage.getImageName(testImageNumList[testImageIndex])
        SIFTdescr = processSIFT.getSIFT(imageName)

        # new train image object, with image name, testImageIndex and SIFT
        testImageObject = Image.Image(imageName, testImageIndex, SIFTdescr)
        testImages.append(testImageObject)

        wordList = []
        SIFTdescr = testImages[testImageIndex].SIFTdescr

        # get distances between SIFT and centers
        distances = getDistances(centers, SIFTdescr)

        for siftIndex in xrange(len(testImages[testImageIndex].SIFTdescr)):
            # minIndex, minValue = min(enumerate(distances[siftIndex], key = operator.itemgetter(1)))

            minIndex = np.argmin(distances[siftIndex])
            wordList.append(minIndex)

        # save word list into test image
        testImages[testImageIndex].setWordList(wordList)

        # get tf list
        tfList = getTFlist(wordList, K)

        svm = getVSM(tfList, idfList)
        testImages[testImageIndex].setVSM(svm)
        # print svm

    return testImages
Exemple #3
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