Beispiel #1
0
def test_disparity_random_stereogram():
  """
  Checks the disparity map for random stereogram 
  """
  H = 51
  W = 51
  disparity = 4
  im_left, im_right = generate_random_stereogram(
      im_size=(H, W, 3), disparity=4)

  block_size = 5
  disp_map = calculate_disparity_map(
      im_left, im_right, block_size, ssd_similarity_measure)

  # define the limits where we will encounter non-zero disparity maps
  x_lims = torch.tensor([H//2 - H//4 - block_size//2-1, H//2 + H//4 + block_size//2-1],
                        dtype=torch.long)
  y_lims = torch.tensor([W//2 - W//4 - block_size//2 - disparity-1, W//2 + W//4 + block_size//2-1],
                        dtype=torch.long)

  # get the points where disparity map is greater than zero
  nonzero_idx = torch.nonzero(disp_map)

  # we will see the effect of stereo outside this region too, depending on the block size
  falsevals = torch.nonzero(~(
      (nonzero_idx[:, 0] >= x_lims[0]) &
      (nonzero_idx[:, 0] <= x_lims[1]) &
      (nonzero_idx[:, 1] >= y_lims[0]) &
      (nonzero_idx[:, 1] <= y_lims[1])
  ))

  assert ~falsevals.shape[0]
Beispiel #2
0
def test_generate_random_stereogram():
    """
  Tests the generation of random dot stereogram
  """
    H, W = (51, 51)
    disparity_val = 4
    left_img, right_img = generate_random_stereogram(im_size=(H, W, 2),
                                                     disparity=disparity_val)

    print(left_img)
    print(right_img)
    print("left_img.shape {}".format(left_img.shape))
    print("right_img.shape {}".format(right_img.shape))
    # assert that they are same in all the channels
    for ch_idx in range(1, left_img.shape[2]):
        assert torch.nonzero(
            left_img[:, :, 0] != left_img[:, :, ch_idx]).shape[0] == 0
        assert torch.nonzero(
            right_img[:, :, 0] != right_img[:, :, ch_idx]).shape[0] == 0

    diff_img = torch.abs(left_img - right_img)

    # get the region where left and right images are different
    nonzero_idx = torch.nonzero(diff_img)
    falsevals = torch.nonzero(~(
        (nonzero_idx[:, 0] >= 13) & (nonzero_idx[:, 0] <= 37)
        & (nonzero_idx[:, 1] >= 9) & (nonzero_idx[:, 1] <= 37)))

    assert falsevals.shape[0] == 0