Mercurial > repos > imgteam > projective_transformation
comparison projective_transformation.py @ 4:37b079c98c38 draft
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation/ commit ded1703bcd6e295b26201505edb58381991b265e"
author | imgteam |
---|---|
date | Mon, 28 Feb 2022 17:36:23 +0000 |
parents | be9a815e2240 |
children | 6a8ae8cd7167 |
comparison
equal
deleted
inserted
replaced
3:be9a815e2240 | 4:37b079c98c38 |
---|---|
45 | 45 |
46 return coords | 46 return coords |
47 | 47 |
48 | 48 |
49 def transform(moving_fn, fixed_fn, warp_mat, output_fn): | 49 def transform(moving_fn, fixed_fn, warp_mat, output_fn): |
50 | |
51 moving = skimage.io.imread(moving_fn) | 50 moving = skimage.io.imread(moving_fn) |
52 nDims = len(moving.shape) | 51 nDims = len(moving.shape) |
53 assert nDims in [2, 3, 4, 5, 6], 'this tool only supports up to 6 dimensions' | 52 assert nDims in [2, 3, 4, 5, 6], 'this tool only supports up to 6 dimensions' |
54 | 53 |
55 if moving.shape[-1] in [3, 4] and nDims > 2: | 54 if moving.shape[-1] in [3, 4] and nDims > 2: |
77 | 76 |
78 warp_mat = pd.read_csv(warp_mat, delimiter="\t", header=None) | 77 warp_mat = pd.read_csv(warp_mat, delimiter="\t", header=None) |
79 warp_mat = np.array(warp_mat) | 78 warp_mat = np.array(warp_mat) |
80 assert warp_mat.shape[0] in [3], 'only 2D image transformaton is supported' | 79 assert warp_mat.shape[0] in [3], 'only 2D image transformaton is supported' |
81 | 80 |
82 trans = ProjectiveTransform(matrix=warp_mat) | 81 transI = ProjectiveTransform(matrix=np.linalg.inv(warp_mat)) |
83 warped_coords = warp_coords_batch(trans, hw_fixed) | 82 warped_coords = warp_coords_batch(transI, hw_fixed) |
84 | 83 |
85 if isMulCh or isRGB: | 84 if isMulCh or isRGB: |
86 for i in range(nCh): | 85 for i in range(nCh): |
87 warped_moving[i, ...] = map_coordinates(moving[i, ...], warped_coords, cval=0) | 86 warped_moving[i, ...] = map_coordinates(moving[i, ...], warped_coords, cval=0) |
88 warped_moving = np.reshape(warped_moving, shapeCh + warped_moving.shape[-2:]) | 87 warped_moving = np.reshape(warped_moving, shapeCh + warped_moving.shape[-2:]) |