Пример #1
0
def offset_ncc_test():
    ncc_size = 5

    image1 = np.random.random((2 * ncc_size - 1, 2 * ncc_size - 1, 3))
    image2 = image1 + 2

    n1 = preprocess_ncc(image1, ncc_size)
    n2 = preprocess_ncc(image2, ncc_size)

    ncc = compute_ncc(n1, n2)

    assert ncc.shape == (2 * ncc_size - 1, 2 * ncc_size - 1)
    assert (np.abs(ncc[ncc_size, ncc_size] - 1) < 1e-6).all()
Пример #2
0
def zero_ncc_test():
    ncc_size = 5

    image1 = np.zeros(
        (2 * ncc_size - 1, 2 * ncc_size - 1, 3), dtype=np.float32)
    image2 = image1

    n1 = preprocess_ncc(image1, ncc_size)
    n2 = preprocess_ncc(image2, ncc_size)

    ncc = compute_ncc(n1, n2)

    assertNear(ncc, 0, 1e-6)
Пример #3
0
def zero_ncc_test():
    ncc_size = 5

    image1 = np.zeros(
        (2 * ncc_size - 1, 2 * ncc_size - 1, 3), dtype=np.float32)
    image2 = image1

    n1 = preprocess_ncc(image1, ncc_size)
    n2 = preprocess_ncc(image2, ncc_size)

    ncc = compute_ncc(n1, n2)

    assert (np.abs(ncc) < 1e-6).all()
Пример #4
0
def offset_ncc_test():
    ncc_size = 5

    image1 = np.random.random((2 * ncc_size - 1, 2 * ncc_size - 1, 3))
    image2 = image1 + 2

    n1 = preprocess_ncc(image1, ncc_size)
    n2 = preprocess_ncc(image2, ncc_size)

    ncc = compute_ncc(n1, n2)

    assert ncc.shape == (2 * ncc_size - 1, 2 * ncc_size - 1)
    assertNear(ncc[ncc_size, ncc_size], 1, 1e-6)
Пример #5
0
def preprocess_ncc_delta_test():
    ncc_size = 5
    ncc_half = int(ncc_size / 2)

    image = np.zeros((2 * ncc_size - 1, 2 * ncc_size - 1, 3), dtype=np.float32)
    image[ncc_size - 1, ncc_size - 1, :] = ncc_size ** 2
    n = preprocess_ncc(image, ncc_size)

    correct = np.zeros((2 * ncc_size - 1, 2 * ncc_size - 1,
                        3 * ncc_size ** 2), dtype=np.float32)
    correct[ncc_half:-ncc_half, ncc_half:-ncc_half, :] = - \
        1.0 / (ncc_size * math.sqrt(3 * ncc_size ** 2 - 3))
    x = (ncc_size ** 2 - 1.0) / (ncc_size * math.sqrt(3 * ncc_size ** 2 - 3))
    for i in range(ncc_size):
        for j in range(ncc_size):
            correct[-(i + ncc_half + 1), -(j + ncc_half + 1), ncc_size **
                    2 * 0 + ncc_size * i + j] = x
            correct[-(i + ncc_half + 1), -(j + ncc_half + 1), ncc_size **
                    2 * 1 + ncc_size * i + j] = x
            correct[-(i + ncc_half + 1), -(j + ncc_half + 1), ncc_size **
                    2 * 2 + ncc_size * i + j] = x
    # np.set_printoptions(threshold=np.nan)
    # print(n[np.nonzero(n)]-correct[np.nonzero(correct)])

    assert n.shape == (2 * ncc_size - 1, 2 * ncc_size -
                       1, 3 * ncc_size * ncc_size)
    assert (np.abs(n - correct) < 1e-6).all()
Пример #6
0
def preprocess_ncc_delta_test():
    ncc_size = 5
    ncc_half = ncc_size / 2

    image = np.zeros((2 * ncc_size - 1, 2 * ncc_size - 1, 3), dtype=np.float32)
    image[ncc_size - 1, ncc_size - 1, :] = ncc_size ** 2
    n = preprocess_ncc(image, ncc_size)

    correct = np.zeros((2 * ncc_size - 1, 2 * ncc_size - 1,
                        3 * ncc_size ** 2), dtype=np.float32)
    correct[ncc_half:-ncc_half, ncc_half:-ncc_half, :] = - \
        1.0 / (ncc_size * math.sqrt(3 * ncc_size ** 2 - 3))
    x = (ncc_size ** 2 - 1.0) / (ncc_size * math.sqrt(3 * ncc_size ** 2 - 3))
    for i in xrange(ncc_size):
        for j in xrange(ncc_size):
            correct[-(i + ncc_half + 1), -(j + ncc_half + 1), ncc_size **
                    2 * 0 + ncc_size * i + j] = x
            correct[-(i + ncc_half + 1), -(j + ncc_half + 1), ncc_size **
                    2 * 1 + ncc_size * i + j] = x
            correct[-(i + ncc_half + 1), -(j + ncc_half + 1), ncc_size **
                    2 * 2 + ncc_size * i + j] = x

    assert n.shape == (2 * ncc_size - 1, 2 * ncc_size -
                       1, 3 * ncc_size * ncc_size)
    assertNear(n, correct, 1e-6)
Пример #7
0
def ncc_full_shapes_test():
    ncc_size = 5

    image1 = imread('test_materials/ncc1.png')
    image2 = imread('test_materials/ncc2.png')

    n1 = preprocess_ncc(image1, ncc_size)
    n2 = preprocess_ncc(image2, ncc_size)

    result = compute_ncc(n1, n2)

    correct = np.load('test_materials/ncc.npy')

    assert result.shape == n1.shape[:2]
    assert result.shape == n2.shape[:2]
    assert (np.abs(result - correct) < 1e-5).all()
Пример #8
0
def preprocess_ncc_delta_test():
    ncc_size = 5
    ncc_half = ncc_size // 2

    image = np.zeros((2 * ncc_size - 1, 2 * ncc_size - 1, 3), dtype=np.float32)
    image[ncc_size - 1, ncc_size - 1, :] = ncc_size ** 2
    n = preprocess_ncc(image, ncc_size)

    correct = np.zeros((2 * ncc_size - 1, 2 * ncc_size - 1,
                        3 * ncc_size ** 2), dtype=np.float32)
    correct[ncc_half:-ncc_half, ncc_half:-ncc_half, :] = - \
        1.0 / (ncc_size * math.sqrt(3 * ncc_size ** 2 - 3))
    x = (ncc_size ** 2 - 1.0) / (ncc_size * math.sqrt(3 * ncc_size ** 2 - 3))
    for i in range(ncc_size):
        for j in range(ncc_size):
            correct[-(i + ncc_half + 1), -(j + ncc_half + 1), ncc_size **
                    2 * 0 + ncc_size * i + j] = x
            correct[-(i + ncc_half + 1), -(j + ncc_half + 1), ncc_size **
                    2 * 1 + ncc_size * i + j] = x
            correct[-(i + ncc_half + 1), -(j + ncc_half + 1), ncc_size **
                    2 * 2 + ncc_size * i + j] = x

    assert n.shape == (2 * ncc_size - 1, 2 * ncc_size -
                       1, 3 * ncc_size * ncc_size)
    assert (np.abs(n - correct) < 1e-6).all()
Пример #9
0
def correlated_ncc_test():
    ncc_size = 5
    ncc_half = ncc_size / 2

    image1 = np.random.random((2 * ncc_size - 1, 2 * ncc_size - 1, 3))
    image2 = image1

    n1 = preprocess_ncc(image1, ncc_size)
    n2 = preprocess_ncc(image2, ncc_size)

    ncc = compute_ncc(n1, n2)

    assertNear(ncc[:ncc_half, :], 0, 1e-5)
    assertNear(ncc[-ncc_half:, :], 0, 1e-5)
    assertNear(ncc[:, :ncc_half], 0, 1e-5)
    assertNear(ncc[:, -ncc_half:], 0, 1e-5)
    assertNear(ncc[ncc_half:-ncc_half, ncc_half:-ncc_half], 1, 1e-5)
Пример #10
0
def correlated_ncc_test():
    ncc_size = 5
    ncc_half = ncc_size / 2

    image1 = np.random.random((2 * ncc_size - 1, 2 * ncc_size - 1, 3))
    image2 = image1

    n1 = preprocess_ncc(image1, ncc_size)
    n2 = preprocess_ncc(image2, ncc_size)

    ncc = compute_ncc(n1, n2)

    assertNear(ncc[:ncc_half, :], 0, 1e-5)
    assertNear(ncc[-ncc_half:, :], 0, 1e-5)
    assertNear(ncc[:, :ncc_half], 0, 1e-5)
    assertNear(ncc[:, -ncc_half:], 0, 1e-5)
    assertNear(ncc[ncc_half:-ncc_half, ncc_half:-ncc_half], 1, 1e-5)
Пример #11
0
def preprocess_ncc_uniform_test():
    ncc_size = 5

    image = np.ones((2 * ncc_size - 1, 2 * ncc_size - 1, 3), dtype=np.float32)
    n = preprocess_ncc(image, ncc_size)

    assert n.shape == (2 * ncc_size - 1, 2 * ncc_size -
                       1, 3 * ncc_size * ncc_size)
    assert (np.abs(n[ncc_size - 1, ncc_size - 1, :]) < 1e-6).all()
Пример #12
0
def preprocess_ncc_zeros_test():
    ncc_size = 5

    image = np.zeros((2 * ncc_size - 1, 2 * ncc_size - 1, 3), dtype=np.float32)
    n = preprocess_ncc(image, ncc_size)

    assert n.shape == (2 * ncc_size - 1, 2 * ncc_size -
                       1, 3 * ncc_size * ncc_size)
    assertNear(n, 0, 1e-6)
Пример #13
0
def offset_and_scale_ncc_test():
    ncc_size = 5
    ncc_half = ncc_size / 2

    image1 = np.random.random((2 * ncc_size - 1, 2 * ncc_size - 1, 3))
    image2 = image1 * 2 + 3

    n1 = preprocess_ncc(image1, ncc_size)
    n2 = preprocess_ncc(image2, ncc_size)

    ncc = compute_ncc(n1, n2)

    assert ncc.shape == (2 * ncc_size - 1, 2 * ncc_size - 1)
    assertNear(ncc[:ncc_half, :], 0, 1e-6)
    assertNear(ncc[-ncc_half:, :], 0, 1e-6)
    assertNear(ncc[:, :ncc_half], 0, 1e-6)
    assertNear(ncc[:, -ncc_half:], 0, 1e-6)
    assertNear(ncc[ncc_half:-ncc_half, ncc_half:-ncc_half], 1, 1e-6)
Пример #14
0
def offset_and_scale_ncc_test():
    ncc_size = 5
    ncc_half = ncc_size / 2

    image1 = np.random.random((2 * ncc_size - 1, 2 * ncc_size - 1, 3))
    image2 = image1 * 2 + 3

    n1 = preprocess_ncc(image1, ncc_size)
    n2 = preprocess_ncc(image2, ncc_size)

    ncc = compute_ncc(n1, n2)

    assert ncc.shape == (2 * ncc_size - 1, 2 * ncc_size - 1)
    assertNear(ncc[:ncc_half, :], 0, 1e-6)
    assertNear(ncc[-ncc_half:, :], 0, 1e-6)
    assertNear(ncc[:, :ncc_half], 0, 1e-6)
    assertNear(ncc[:, -ncc_half:], 0, 1e-6)
    assertNear(ncc[ncc_half:-ncc_half, ncc_half:-ncc_half], 1, 1e-6)
Пример #15
0
def preprocess_ncc_uniform_test():
    ncc_size = 5

    image = np.ones((2 * ncc_size - 1, 2 * ncc_size - 1, 3), dtype=np.float32)
    n = preprocess_ncc(image, ncc_size)

    assert n.shape == (2 * ncc_size - 1, 2 * ncc_size -
                       1, 3 * ncc_size * ncc_size)
    assertNear(n[ncc_size - 1, ncc_size - 1, :], 0, 1e-6)
Пример #16
0
def anticorrelated_ncc_test():
    ncc_size = 5
    ncc_half = ncc_size / 2

    image1 = np.random.random((2 * ncc_size - 1, 2 * ncc_size - 1, 3))
    image2 = -image1

    n1 = preprocess_ncc(image1, ncc_size)
    n2 = preprocess_ncc(image2, ncc_size)

    ncc = compute_ncc(n1, n2)

    assert (np.abs(ncc[:ncc_half, :]) < 1e-5).all()
    assert (np.abs(ncc[-ncc_half:, :]) < 1e-5).all()
    assert (np.abs(ncc[:, :ncc_half]) < 1e-5).all()
    assert (np.abs(ncc[:, -ncc_half:]) < 1e-5).all()
    assert (
        np.abs(ncc[ncc_half:-ncc_half, ncc_half:-ncc_half] - -1) < 1e-5).all()
Пример #17
0
def preprocess_ncc_zeros_test():
    ncc_size = 5

    image = np.zeros((2 * ncc_size - 1, 2 * ncc_size - 1, 3), dtype=np.float32)
    n = preprocess_ncc(image, ncc_size)

    assert n.shape == (2 * ncc_size - 1, 2 * ncc_size -
                       1, 3 * ncc_size * ncc_size)
    assert (np.abs(n) < 1e-6).all()
Пример #18
0
def preprocess_ncc_zeros_test():
    ncc_size = 5

    image = np.zeros((2 * ncc_size - 1, 2 * ncc_size - 1, 3), dtype=np.float32)
    n = preprocess_ncc(image, ncc_size)

    assert n.shape == (2 * ncc_size - 1, 2 * ncc_size - 1,
                       3 * ncc_size * ncc_size)
    assertNear(n, 0, 1e-6)
Пример #19
0
def preprocess_ncc_full_test():
    ncc_size = 5

    image = imread('test_materials/fabrics.png')

    result = preprocess_ncc(image, ncc_size)

    correct = np.load('test_materials/fabrics_normalized.npy')

    assert (np.abs(result - correct) < 1e-5).all()
Пример #20
0
def ncc_full_offset_test():
    ncc_size = 5

    image = imread('test_materials/justinpic_c.png')

    split = image.shape[1] / 2
    left = image[:, :split, :]
    right = image[:, split:, :]

    n1 = preprocess_ncc(left, ncc_size)
    n2 = preprocess_ncc(right, ncc_size)

    result = compute_ncc(n1, n2)

    correct = np.load('test_materials/justin_ncc.npy')

    assert result.shape == n1.shape[:2]
    assert result.shape == n2.shape[:2]
    assert (np.abs(result - correct) < 1e-5).all()
Пример #21
0
def scale_ncc_test():
    ncc_size = 5
    ncc_half = ncc_size / 2

    image1 = np.random.random((2 * ncc_size - 1, 2 * ncc_size - 1, 3))
    image2 = image1 * 2

    n1 = preprocess_ncc(image1, ncc_size)
    n2 = preprocess_ncc(image2, ncc_size)

    ncc = compute_ncc(n1, n2)

    assert ncc.shape == (2 * ncc_size - 1, 2 * ncc_size - 1)
    assert (np.abs(ncc[:ncc_half, :]) < 1e-5).all()
    assert (np.abs(ncc[-ncc_half:, :]) < 1e-5).all()
    assert (np.abs(ncc[:, :ncc_half]) < 1e-5).all()
    assert (np.abs(ncc[:, -ncc_half:]) < 1e-5).all()
    assert (
        np.abs(ncc[ncc_half:-ncc_half, ncc_half:-ncc_half] - 1) < 1e-5).all()
Пример #22
0
def ncc_full_shapes_test():
    ncc_size = 5

    image1 = imread('test_materials/ncc1.png')
    image2 = imread('test_materials/ncc2.png')

    image1 = image1.astype(np.float32)
    image2 = image2.astype(np.float32)

    n1 = preprocess_ncc(image1, ncc_size)
    n2 = preprocess_ncc(image2, ncc_size)

    result = compute_ncc(n1, n2)

    correct = np.load('test_materials/ncc.npy')

    assert result.shape == n1.shape[:2]
    assert result.shape == n2.shape[:2]
    assertNear(result, correct, 1e-5)
Пример #23
0
def ncc_full_offset_test():
    ncc_size = 5

    image = imread('test_materials/justinpic_c.png')
    image = image.astype(np.float32)

    split = image.shape[1] / 2
    left = image[:, :split, :]
    right = image[:, split:, :]

    n1 = preprocess_ncc(left, ncc_size)
    n2 = preprocess_ncc(right, ncc_size)

    result = compute_ncc(n1, n2)

    correct = np.load('test_materials/justin_ncc.npy')

    assert result.shape == n1.shape[:2]
    assert result.shape == n2.shape[:2]
    assertNear(result, correct, 1e-5)
Пример #24
0
def preprocess_ncc_full_test():
    ncc_size = 5

    image = imread('test_materials/fabrics.png')
    image = image.astype(np.float32)

    result = preprocess_ncc(image, ncc_size)

    correct = np.load('test_materials/fabrics_normalized.npy')

    assertNear(result, correct, 1e-5)
Пример #25
0
    K_left[:2, :] /= 2
    K_right[:2, :] /= 2

"""
We'll give you the depth labels for this problem.
"""
depths = get_depths(data)

tic = time.time()

"""
The planes will be swept fronto-parallel to the right camera, so no
reprojection needs to be done for this image.  Simply compute the normalized
patches across the entire image.
"""
right_normalized = preprocess_ncc(right[:, :, :3], ncc_size)

"""
We'll sweep a series of planes that are fronto-parallel to the right camera.
The image from the left camera is to be projected onto each of these planes,
normalized, and then compared to the normalized right image.
"""
volume = []
for pos, depth in enumerate(depths):
    """
    Unproject the pixel coordinates from the right camera onto the virtual
    plane.
    """
    points = unproject_corners(K_right, width, height, depth, Rt_right)

    """
Пример #26
0
    left = pyrdown(left)
    height, width, _ = right.shape
    K_left[:2, :] /= 2
    K_right[:2, :] /= 2
"""
We'll give you the depth labels for this problem.
"""
depths = get_depths(data)

tic = time.time()
"""
The planes will be swept fronto-parallel to the right camera, so no
reprojection needs to be done for this image.  Simply compute the normalized
patches across the entire image.
"""
right_normalized = preprocess_ncc(right[:, :, :3], ncc_size)
"""
We'll sweep a series of planes that are fronto-parallel to the right camera.
The image from the left camera is to be projected onto each of these planes,
normalized, and then compared to the normalized right image.
"""
volume = []
for pos, depth in enumerate(depths):
    """
    Unproject the pixel coordinates from the right camera onto the virtual
    plane.
    """
    points = unproject_corners(K_right, width, height, depth, Rt_right)
    """
    Project those points onto the two cameras to generate correspondences.
    """
Пример #27
0
for i in range(data.stereo_downscale_factor):
    right = pyrdown(right)
    left = pyrdown(left)
    height, width, _ = right.shape
    K_left[:2, :] /= 2
    K_right[:2, :] /= 2

# We give you the depth labels for this problem.
depths = get_depths(data)

tic = time.time()

# The planes will be swept fronto-parallel to the right camera, so no
# reprojection needs to be done for this image.  Simply compute the normalized
# patches across the entire image.
right_normalized = preprocess_ncc(right[:, :, :3], ncc_size)

# We'll sweep a series of planes that are fronto-parallel to the right camera.
# The image from the left camera is to be projected onto each of these planes,
# normalized, and then compared to the normalized right image.
volume = []
for pos, depth in enumerate(depths):
    raise NotImplementedError()
    # Task 5: complete the plane sweep stereo loop body by filling in
    # the following TODO lines

    # (TODO) Unproject the pixel coordinates from the right camera onto the virtual plane.
    # points = ...

    # (TODO) Project the 3D corners into the two cameras to generate correspondences.
    # points_left = ...