def _test_2d(self, matrix, out_file=None, sigma=None, **kwargs): from elf.transformation import transform_subvolume_affine shape = (512, 512) x = np.random.rand(*shape) exp = affine_transform(x, matrix, **kwargs) if out_file is not None: with open_file(out_file) as f: x = f.create_dataset('tmp', data=x, chunks=(64, 64)) f = open_file(out_file, 'r') x = f['tmp'] bbs = [ np.s_[:, :], np.s_[:256, :256], np.s_[37:115, 226:503], np.s_[:200, :], np.s_[:, 10:115] ] for bb in bbs: bb, _ = normalize_index(bb, shape) res = transform_subvolume_affine(x, matrix, bb, sigma=sigma, **kwargs) exp_bb = exp[bb] self.assertEqual(res.shape, exp_bb.shape) if sigma is None: self.assertTrue(np.allclose(res, exp_bb)) else: self.assertTrue(~np.allclose(res, 0)) if out_file is not None: f.close()
def _test_3d(self, matrix, out_file=None, **kwargs): from elf.transformation import transform_subvolume_affine shape = 3 * (64, ) x = np.random.rand(*shape) exp = affine_transform(x, matrix, **kwargs) if out_file is not None: with open_file(out_file) as f: x = f.create_dataset('tmp', data=x, chunks=3 * (16, )) f = open_file(out_file, 'r') x = f['tmp'] bbs = [ np.s_[:, :, :], np.s_[:32, :32, :32], np.s_[1:31, 5:27, 3:13], np.s_[4:19, :, 22:], np.s_[1:29], np.s_[:, 15:27, :], np.s_[:, 1:3, 4:14] ] for bb in bbs: bb, _ = normalize_index(bb, shape) res = transform_subvolume_affine(x, matrix, bb, **kwargs) exp_bb = exp[bb] self.assertEqual(res.shape, exp_bb.shape) self.assertTrue(np.allclose(res, exp_bb)) if out_file is not None: f.close()
def test_toy(self): from elf.transformation import compute_affine_matrix from elf.transformation import transform_subvolume_affine mat = compute_affine_matrix(scale=(2, 2), rotation=(45,), translation=(-1, 1)) x = np.random.rand(10, 10) bb = np.s_[0:3, 0:3] res = transform_subvolume_affine(x, mat, bb, order=1) exp = affine_transform(x, mat, order=1)[bb] self.assertTrue(np.allclose(res, exp))