annotate projective_transformation_points.py @ 7:499ad4d9aa13 draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/projective_transformation_points/ commit c045f067a57e8308308cf6329060c7ccd3fc372f
author imgteam
date Thu, 04 Apr 2024 15:26:12 +0000
parents 3a686b6aa7fc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
1 """
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
2 Copyright 2019-2022 Biomedical Computer Vision Group, Heidelberg University.
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
3
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
4 Distributed under the MIT license.
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
5 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
6
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
7 """
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
8
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
9 import argparse
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
10
0
ed8a71e13f7b planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
11 import numpy as np
ed8a71e13f7b planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
12 import pandas as pd
5
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
13 from scipy.ndimage import map_coordinates
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
14 from skimage.transform import ProjectiveTransform
0
ed8a71e13f7b planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
15
ed8a71e13f7b planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
16
2
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
17 def _stackcopy(a, b):
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
18 if a.ndim == 3:
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
19 a[:] = b[:, :, np.newaxis]
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
20 else:
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
21 a[:] = b
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
22
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
23
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
24 def warp_img_coords_batch(coord_map, shape, dtype=np.float64, batch_size=1000000):
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
25 rows, cols = shape[0], shape[1]
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
26 coords_shape = [len(shape), rows, cols]
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
27 if len(shape) == 3:
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
28 coords_shape.append(shape[2])
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
29 coords = np.empty(coords_shape, dtype=dtype)
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
30
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
31 tf_coords = np.indices((cols, rows), dtype=dtype).reshape(2, -1).T
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
32
5
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
33 for i in range(0, (tf_coords.shape[0] // batch_size + 1)):
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
34 tf_coords[batch_size * i:batch_size * (i + 1)] = coord_map(tf_coords[batch_size * i:batch_size * (i + 1)])
2
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
35 tf_coords = tf_coords.T.reshape((-1, cols, rows)).swapaxes(1, 2)
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
36
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
37 _stackcopy(coords[1, ...], tf_coords[0, ...])
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
38 _stackcopy(coords[0, ...], tf_coords[1, ...])
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
39 if len(shape) == 3:
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
40 coords[2, ...] = range(shape[2])
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
41
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
42 return coords
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
43
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
44
0
ed8a71e13f7b planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
45 def warp_coords_batch(coord_map, coords, dtype=np.float64, batch_size=1000000):
1
f1744c5654b9 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit 201f4231192bc368b14e72bb1314b9a97b8db8d0
imgteam
parents: 0
diff changeset
46 tf_coords = coords.astype(np.float32)[:, ::-1]
0
ed8a71e13f7b planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
47
5
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
48 for i in range(0, (tf_coords.shape[0] // batch_size) + 1):
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
49 tf_coords[batch_size * i:batch_size * (i + 1)] = coord_map(tf_coords[batch_size * i:batch_size * (i + 1)])
0
ed8a71e13f7b planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
50
2
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
51 return tf_coords[:, ::-1]
5
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
52
0
ed8a71e13f7b planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
53
4
aaac58d83043 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit 7391bb4256f49ec30cf38d9438f97e11ec25a115"
imgteam
parents: 2
diff changeset
54 def transform(fn_roi_coords, fn_warp_matrix, fn_out):
aaac58d83043 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit 7391bb4256f49ec30cf38d9438f97e11ec25a115"
imgteam
parents: 2
diff changeset
55 data = pd.read_csv(fn_roi_coords, delimiter="\t")
aaac58d83043 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit 7391bb4256f49ec30cf38d9438f97e11ec25a115"
imgteam
parents: 2
diff changeset
56 all_data = np.array(data)
5
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
57
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
58 nrows, ncols = all_data.shape[0:2]
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
59 roi_coords = all_data.take([0, 1], axis=1).astype('int64')
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
60
2
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
61 tol = 10
5
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
62 moving = np.zeros(np.max(roi_coords, axis=0) + tol, dtype=np.uint32)
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
63 idx_roi_coords = (roi_coords[:, 0] - 1) * moving.shape[1] + roi_coords[:, 1] - 1
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
64 moving.flat[idx_roi_coords] = np.transpose(np.arange(nrows) + 1)
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
65
4
aaac58d83043 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit 7391bb4256f49ec30cf38d9438f97e11ec25a115"
imgteam
parents: 2
diff changeset
66 trans_matrix = np.array(pd.read_csv(fn_warp_matrix, delimiter="\t", header=None))
2
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
67 transP = ProjectiveTransform(matrix=trans_matrix)
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
68 roi_coords_warped_direct = warp_coords_batch(transP, roi_coords)
5
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
69 shape_fixed = np.round(np.max(roi_coords_warped_direct, axis=0)).astype(roi_coords.dtype) + tol
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
70
2
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
71 transI = ProjectiveTransform(matrix=np.linalg.inv(trans_matrix))
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
72 img_coords_warped = warp_img_coords_batch(transI, shape_fixed)
5
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
73
4
aaac58d83043 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit 7391bb4256f49ec30cf38d9438f97e11ec25a115"
imgteam
parents: 2
diff changeset
74 moving_warped = map_coordinates(moving, img_coords_warped, order=0, mode='constant', cval=0)
5
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
75 idx_roi_coords_warped = np.where(moving_warped > 0)
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
76 roi_annots_warped = moving_warped.compress((moving_warped > 0).flat)
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
77
0
ed8a71e13f7b planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
78 df = pd.DataFrame()
4
aaac58d83043 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit 7391bb4256f49ec30cf38d9438f97e11ec25a115"
imgteam
parents: 2
diff changeset
79 col_names = data.columns.tolist()
2
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
80 df['x'] = idx_roi_coords_warped[0] + 1
0d2707c82d29 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit f1298dca5a7f5be3acbb5e3d80c98b1cd6d2795b"
imgteam
parents: 1
diff changeset
81 df['y'] = idx_roi_coords_warped[1] + 1
5
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
82 if ncols > 2:
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
83 for i in range(2, ncols):
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
84 df[col_names[i]] = all_data[:, i].take(roi_annots_warped - 1)
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
85 df.to_csv(fn_out, index=False, sep="\t")
0
ed8a71e13f7b planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
86
ed8a71e13f7b planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
87
ed8a71e13f7b planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
88 if __name__ == "__main__":
5
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
89 parser = argparse.ArgumentParser(description="Transform ROIs defined by pixel (point) coordinates")
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
90 parser.add_argument("coords", help="Path to the TSV file of the coordinates (and labels) to be transformed")
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
91 parser.add_argument("tmat", help="Path to the TSV file of the transformation matrix")
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
92 parser.add_argument("out", help="Path to the TSV file of the transformed coordinates (and labels)")
0
ed8a71e13f7b planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
93 args = parser.parse_args()
5
3a686b6aa7fc "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c4424f5dd4110c92ae39815ebfe2ea8c1010be9c"
imgteam
parents: 4
diff changeset
94 transform(args.coords, args.tmat, args.out)