def get_lines(self): """ Get coordinates that beams are going through. """ max_x, max_y = self.img.shape # get transformations mat_t = translate(max_x / 2, max_y / 2) mat_r = rotate(np.deg2rad(self.angle)) transformations = [mat_r, mat_t] # transform emitters_t = transform_apply(self.emitters, transformations) detectors_t = transform_apply(self.detectors, transformations) # round emitters_t = array_round(emitters_t) detectors_t = array_round(detectors_t) # get lines lines = [] for emitter, detector in zip(emitters_t, detectors_t): new_line = np.column_stack(line(*emitter, *detector)) new_line = new_line[(new_line[:, 0] >= 0) & (new_line[:, 1] >= 0) & (new_line[:, 0] < max_x) & (new_line[:, 1] < max_y)] lines.append((new_line[:, 0], new_line[:, 1])) return lines
def test_transform_translate(): """ Test tomograph.transform.translate translation matrix. """ coords = np.array([100, 50, 1]) move = (150, 70) expected = np.array([250, 120, 1]) coords = translate(*move).dot(coords) assert np.alltrue(coords == expected)
def test_transform_join(): """ Test joining two transform matrices. """ coords = np.array([-100, 50, 1]) move = (-150, 125) angle = np.pi / 2 expected = np.array([-200.0, 25.0, 1.0]) coords = rotate(angle).dot(coords) coords = translate(*move).dot(coords) assert np.allclose(coords, expected)
def test_transform_list(): """ Test transforming a list of coordinates. """ coords = np.linspace(10, 100, num=10).reshape(5, 2) w = np.array([ [1], ] * 5) coords = np.append(coords, w, axis=1) t_mat = translate(100, 50) expected = coords + np.array([100, 50, 0]) coords = transform_list(coords, t_mat) assert np.allclose(coords, expected)
def test_transform_apply(): """ Test applying list of transformations to a list of coordinates. """ coords = np.linspace(10, 100, num=10).reshape(5, 2) expected = np.array([[-110, -70], [-130, -90], [-150, -110], [-170, -130], [-190, -150]]) t_mat = translate(100, 50) r_mat = rotate(np.pi) # rotate first, then translate transformations = [t_mat, r_mat] coords = transform_apply(coords, transformations) assert np.allclose(coords, expected)