コード例 #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 test_sumSquaredDifferences():
    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]],
                               [[255, 255, 255],
                                [255, 255, 255],
                                [255, 255, 255],
                                [255, 255, 255]]]], dtype = np.uint8)

    diff1 = np.array([[  0.,   6.,  24.,  54.],
                      [  6.,   0.,   6.,  24.],
                      [ 24.,   6.,   0.,   6.],
                      [ 54.,  24.,   6.,   0.]], dtype = np.float)

    diff2 = np.array([[      0.,     24.,  768156.],
                      [     24.,      0.,  774204.],
                      [ 768156., 774204.,       0.]], dtype = np.float)

    for vid_volume, true_out in zip((video_volume1, video_volume2),
                                    (diff1, diff2)):
        print "Input:\n{}\n".format(vid_volume)
        usr_out = assignment11.sumSquaredDifferences(vid_volume)

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

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

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

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