Unverified Commit 8472e51f authored by RishalAggarwal's avatar RishalAggarwal Committed by GitHub
Browse files

Add files via upload

parent 464beacb
Loading
Loading
Loading
Loading
+5 −31
Original line number Diff line number Diff line
@@ -536,46 +536,20 @@ class TestTransformers(unittest.TestCase):
    w = 150
    scale = scipy.misc.imresize(self.d, (h, w))
    check_scale = dt.scale(h, w)
    np.allclose(scale, check_scale)
    assert np.allclose(scale, check_scale)

  def test_shift(self):
    # Check shift
    dt = DataTransforms(self.d)
    height = 5
    width = 5
    if len(self.d.shape) == 2:
      shift = scipy.ndimage.shift(self.d, [height, width])
    if len(self.d.shape) == 3:
      shift = scipy.ndimage.shift(self.d, [height, width, 0])
    check_shift = dt.shift(width, height)
    assert np.allclose(shift, check_shift)

  def test_zoom(self):
    # Check zoom
    dt = DataTransforms(self.d)
    zx = 2
    zy = 2
    h, w = self.d.shape[0], self.d.shape[1]
    o_x = float(h) / 2 + 0.5
    o_y = float(w) / 2 + 0.5
    transform_matrix = np.array([[zx, 0, 0], [0, zy, 0], [0, 0, 1]])
    offset_matrix = np.array([[1, 0, o_x], [0, 1, o_y], [0, 0, 1]])
    reset_matrix = np.array([[1, 0, -o_x], [0, 1, -o_y], [0, 0, 1]])
    transform_matrix = np.dot(
        np.dot(offset_matrix, transform_matrix), reset_matrix)
    final_affine_matrix = np.linalg.inv(transform_matrix[:2, :2])
    final_offset = transform_matrix[:2, 2]
    x = np.rollaxis(self.d, 2, 0)
    channel_images = [
        scipy.ndimage.interpolation.affine_transform(
            x_channel,
            final_affine_matrix,
            final_offset,
            order=3,
            mode='constant') for x_channel in x
    ]
    x = np.stack(channel_images, axis=0)
    zoom = np.rollaxis(x, 0, 3)
    check_zoom = dt.zoom(zx, zy)
    assert np.allclose(zoom, check_zoom)

  def test_gaussian_noise(self):
    # check gaussian noise
    dt = DataTransforms(self.d)