comparison projective_transformation_points.py @ 0:ed8a71e13f7b draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
author imgteam
date Sat, 09 Feb 2019 14:45:19 -0500
parents
children f1744c5654b9
comparison
equal deleted inserted replaced
-1:000000000000 0:ed8a71e13f7b
1 from skimage.transform import ProjectiveTransform
2 import numpy as np
3 import pandas as pd
4 import argparse
5
6
7 def warp_coords_batch(coord_map, coords, dtype=np.float64, batch_size=1000000):
8 tf_coords = coords.astype(np.float32)
9
10 for i in range(0, (tf_coords.shape[0]//batch_size+1)):
11 tf_coords[batch_size*i:batch_size*(i+1)] = coord_map(tf_coords[batch_size*i:batch_size*(i+1)])
12
13 return np.unique(np.round(tf_coords).astype(coords.dtype),axis=0)
14
15
16 def transform(coords, warp_matrix, out):
17 indices = np.array(pd.read_csv(coords, delimiter="\t"))
18 a_matrix = np.array(pd.read_csv(warp_matrix, delimiter="\t", header=None))
19
20 trans = ProjectiveTransform(matrix=a_matrix)
21 warped_coords = warp_coords_batch(trans, indices)
22
23 df = pd.DataFrame()
24 df['x'] = warped_coords[:,0]
25 df['y'] = warped_coords[:,1]
26 df.to_csv(out, index = False, sep="\t")
27
28
29 if __name__ == "__main__":
30 parser = argparse.ArgumentParser(description="Transform coordinates")
31 parser.add_argument("coords", help="Paste path to .csv with coordinates to transform (tab separated)")
32 parser.add_argument("warp_matrix", help="Paste path to .csv that should be used for transformation (, separated)")
33 parser.add_argument("out", help="Paste path to file in which transformed coords should be saved (tab separated)")
34 args = parser.parse_args()
35 transform(args.coords, args.warp_matrix, args.out)