Esempio n. 1
0
def runTexture(img_list):
    """ This function administrates the extraction of a video texture from the
      given frames.
    """
    video_volume = assignment11.videoVolume(img_list)
    ssd_diff = assignment11.sumSquaredDifferences(video_volume)
    transition_diff = assignment11.transitionDifference(ssd_diff)
    alpha = 1.5*10**6
    idxs = assignment11.findBiggestLoop(transition_diff, alpha)

    diff3 = np.zeros(transition_diff.shape, float)

    for i in range(transition_diff.shape[0]): 
        for j in range(transition_diff.shape[1]): 
            diff3[i,j] = alpha*(i-j) - transition_diff[i,j] 

    return vizDifference(ssd_diff), \
           vizDifference(transition_diff), \
           vizDifference(diff3), \
           assignment11.synthesizeLoop(video_volume, idxs[0]+2, idxs[1]+2)
Esempio n. 2
0
def runTexture(img_list, alpha):
    """ This function administrates the extraction of a video texture from the
    given frames, and generates the three viewable difference matrices.
    """
    video_volume = a11.videoVolume(img_list)
    ssd_diff = a11.computeSimilarityMetric(video_volume)
    transition_diff = a11.transitionDifference(ssd_diff)

    print "Alpha is {}".format(alpha)
    idxs = a11.findBiggestLoop(transition_diff, alpha)

    diff3 = np.zeros(transition_diff.shape, float)

    for i in range(transition_diff.shape[0]):
        for j in range(transition_diff.shape[1]):
            diff3[i, j] = alpha * (i - j) - transition_diff[i, j]

    return (vizDifference(ssd_diff),
            vizDifference(transition_diff),
            vizDifference(diff3),
            a11.synthesizeLoop(video_volume, idxs[0] + 2, idxs[1] + 2))
Esempio n. 3
0
def test_videoVolume():
    image_list1 = [np.array([[[0,  0,  0], [0,  0,  0]]], dtype = np.uint8),
                   np.array([[[1,  1,  1], [1,  1,  1]]], dtype = np.uint8),
                   np.array([[[2,  2,  2], [2,  2,  2]]], dtype = np.uint8),
                   np.array([[[3,  3,  3], [3,  3,  3]]], dtype = np.uint8)]

    video_volume1 = np.array([[[[ 0,  0,  0], [ 0,  0,  0]]],
                              [[[ 1,  1,  1], [ 1,  1,  1]]],
                              [[[ 2,  2,  2], [ 2,  2,  2]]],
                              [[[ 3,  3,  3], [ 3,  3,  3]]]], dtype = np.uint8)

    image_list2 = [np.array([[[2, 2, 2],
                              [2, 2, 2],
                              [2, 2, 2],
                              [2, 2, 2]],
                             [[2, 2, 2],
                              [2, 2, 2],
                              [2, 2, 2],
                              [2, 2, 2]]], dtype = np.uint8),
                   np.array([[[1, 1, 1],
                              [1, 1, 1],
                              [1, 1, 1],
                              [1, 1, 1]],
                             [[1, 1, 1],
                              [1, 1, 1],
                              [1, 1, 1],
                              [1, 1, 1]]], dtype = np.uint8),
                   np.array([[[0, 0, 0],
                              [0, 0, 0],
                              [0, 0, 0],
                              [0, 0, 0]],
                             [[0, 0, 0],
                              [0, 0, 0],
                              [0, 0, 0],
                              [0, 0, 0]]], dtype = np.uint8)]

    video_volume2 = np.array([[[[2, 2, 2],
                                [2, 2, 2],
                                [2, 2, 2],
                                [2, 2, 2]],
                               [[2, 2, 2],
                                [2, 2, 2],
                                [2, 2, 2],
                                [2, 2, 2]]],
                              [[[1, 1, 1],
                                [1, 1, 1],
                                [1, 1, 1],
                                [1, 1, 1]],
                               [[1, 1, 1],
                                [1, 1, 1],
                                [1, 1, 1],
                                [1, 1, 1]]],
                              [[[0, 0, 0],
                                [0, 0, 0],
                                [0, 0, 0],
                                [0, 0, 0]],
                               [[0, 0, 0],
                                [0, 0, 0],
                                [0, 0, 0],
                                [0, 0, 0]]]], dtype = np.uint8)

    print "Evaluating videoVolume:"
    for img_list, true_out in zip((image_list1, image_list2),
                                  (video_volume1, video_volume2)):
        print "Input:\n{}\n".format(img_list)
        usr_out = assignment11.videoVolume(img_list)

        if type(usr_out) != type(true_out):
            print "Error: videoVolume has type {}. Expected type is {}.".format(
                type(usr_out), type(true_out))
            return False

        if usr_out.shape != true_out.shape:
            print ("Error: videoVolume has shape {}. " + 
                   "Expected shape is {}.").format(usr_out.shape,
                                                   true_out.shape)
            return False

        if usr_out.dtype != true_out.dtype:
            print ("Error: videoVolume has dtype {}." + 
                   " Expected dtype is {}.").format(usr_out.dtype,
                                                    true_out.dtype)
            return False

        if not np.all(usr_out == true_out):
            print ("Error: videoVolume has value:\n{}\n" +
                   "Expected value:\n{}").format(usr_out, true_out)
            return False
        print "Passed current input."
    print "videoVolume passed."
    return True