annotate projective_transformation_points.py @ 0:296345779402 draft default tip

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