Mercurial > repos > thomaswollmann > projective_transformation_points
annotate projective_transformation_points.py @ 0:470fd1c1c10c 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 05:39:27 -0500 (2019-01-07) |
parents | |
children |
rev | line source |
---|---|
0
470fd1c1c10c
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 |
470fd1c1c10c
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 |
470fd1c1c10c
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 |
470fd1c1c10c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit 787ebcc8daa1834214bc92c201c921c704ef2d1f
thomaswollmann
parents:
diff
changeset
|
4 import argparse |
470fd1c1c10c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit 787ebcc8daa1834214bc92c201c921c704ef2d1f
thomaswollmann
parents:
diff
changeset
|
5 |
470fd1c1c10c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit 787ebcc8daa1834214bc92c201c921c704ef2d1f
thomaswollmann
parents:
diff
changeset
|
6 |
470fd1c1c10c
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): |
470fd1c1c10c
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) |
470fd1c1c10c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit 787ebcc8daa1834214bc92c201c921c704ef2d1f
thomaswollmann
parents:
diff
changeset
|
9 |
470fd1c1c10c
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)): |
470fd1c1c10c
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)]) |
470fd1c1c10c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit 787ebcc8daa1834214bc92c201c921c704ef2d1f
thomaswollmann
parents:
diff
changeset
|
12 |
470fd1c1c10c
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) |
470fd1c1c10c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit 787ebcc8daa1834214bc92c201c921c704ef2d1f
thomaswollmann
parents:
diff
changeset
|
14 |
470fd1c1c10c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit 787ebcc8daa1834214bc92c201c921c704ef2d1f
thomaswollmann
parents:
diff
changeset
|
15 |
470fd1c1c10c
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): |
470fd1c1c10c
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")) |
470fd1c1c10c
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)) |
470fd1c1c10c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit 787ebcc8daa1834214bc92c201c921c704ef2d1f
thomaswollmann
parents:
diff
changeset
|
19 |
470fd1c1c10c
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) |
470fd1c1c10c
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) |
470fd1c1c10c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit 787ebcc8daa1834214bc92c201c921c704ef2d1f
thomaswollmann
parents:
diff
changeset
|
22 |
470fd1c1c10c
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() |
470fd1c1c10c
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] |
470fd1c1c10c
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] |
470fd1c1c10c
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") |
470fd1c1c10c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit 787ebcc8daa1834214bc92c201c921c704ef2d1f
thomaswollmann
parents:
diff
changeset
|
27 |
470fd1c1c10c
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation_points/ commit 787ebcc8daa1834214bc92c201c921c704ef2d1f
thomaswollmann
parents:
diff
changeset
|
28 |
470fd1c1c10c
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__": |
470fd1c1c10c
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") |
470fd1c1c10c
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)") |
470fd1c1c10c
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)") |
470fd1c1c10c
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)") |
470fd1c1c10c
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() |
470fd1c1c10c
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) |