def test_inactive(self): """Create a wild transform without leaving the image space.""" random_state = 55 shape = (_, w) = (40, 30) n_pixels = np.prod(shape) np.random.seed(random_state) perm = np.random.permutation(n_pixels) delta_x = np.zeros(shape) delta_y = np.zeros(shape) for i, x in enumerate(perm): r_inp, c_inp = i // w, i % w r_out, c_out = x // w, x % w delta_x[r_inp, c_inp] = c_out - c_inp delta_y[r_inp, c_inp] = r_out - r_inp df = DisplacementField(delta_x, delta_y) assert df == df.adjust() delta_x_new = delta_x.copy() delta_x_new[0, 0] = -1 df_new = DisplacementField(delta_x_new, delta_y) assert df_new != df_new.adjust()
def test_correct_scale(self): """Create outsider pixels on purpose with clear shrunk vectors.""" shape = (h, w) = (40, 30) delta_x = np.zeros(shape) delta_y = np.zeros(shape) delta_x_correct = np.zeros(shape) delta_y_correct = np.zeros(shape) # Right delta_x[0, 0] = 100 delta_x_correct[0, 0] = w - 1 - 0 # Up delta_y[15, 10] = -100 delta_y_correct[15, 10] = -15 # Down delta_y[25, 11] = 100000 delta_y_correct[25, 11] = h - 1 - 25 # Left delta_x[1, 13] = -131231 delta_x_correct[1, 13] = -13 # random_1 delta_x[2, 4] = 10 delta_y[2, 4] = 100 c_1 = (h - 1 - 2) / 100 delta_x_correct[2, 4] = c_1 * 10 delta_y_correct[2, 4] = c_1 * 100 df = DisplacementField(delta_x, delta_y) df_correct = DisplacementField(delta_x_correct, delta_y_correct) assert TestAdjust.eps_equal(df.adjust(force_inside_border=True), df_correct)