Пример #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)
Пример #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))
Пример #3
0
def test_synthesizeLoop():
    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) 

    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)
    frames1 = (2,3)
    frames2 = (1,1)

    out1 = [np.array([[[ 2,  2,  2],
                       [ 2,  2,  2]]], dtype = np.uint8),
            np.array([[[ 3,  3,  3],
                       [ 3,  3,  3]]], dtype = np.uint8)]

    out2 = [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)]

    for video_volume, frames, true_out in zip((video_volume1, video_volume2), 
                                              (frames1, frames2),
                                              (out1, out2)):
        print "Input:\n{}\n".format(video_volume)
        print "Input Frame Loop:\n{}\n".format(frames)

        usr_out = assignment11.synthesizeLoop(video_volume,
                                              frames[0], frames[1])

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

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

        # Test each individual image.
        for usr_img, true_img in zip(usr_out, true_out):
            if type(usr_img) != type(true_img):
                print ("Error: A frame in synthesizeLoop has type {}. " + 
                       "Expected type is {}.").format(type(usr_img),
                                                      type(true_img))
                return False

            if usr_img.shape != true_img.shape:
                print ("Error: A frame in synthesizeLoop has shape {}. " + 
                       "Expected shape is {}.").format(usr_img.shape,
                                                       true_img.shape)
                return False

            if usr_img.dtype != true_img.dtype:
                print ("Error: A frame in synthesizeLoop has dtype {}. " + 
                       "Expected dtype is {}.").format(usr_img.dtype,
                                                       true_img.dtype)
                return False

            if np.all(usr_img != true_img):
                print ("Error: synthesizeLoop has value:\n{}\n" +
                       "Expected value:\n{}").format(usr_img, true_img)
                return False
        print "Current input passed."
    print "synthesizeLoop passed."
    return True