Mercurial > repos > imgteam > landmark_registration
annotate landmark_registration.py @ 0:a71239f3543a draft
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
author | imgteam |
---|---|
date | Tue, 12 Feb 2019 08:35:45 -0500 |
parents | |
children | b0503eec7bd6 |
rev | line source |
---|---|
0
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
1 from skimage.measure import ransac |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
2 from skimage.transform import AffineTransform |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
3 import pandas as pd |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
4 import numpy as np |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
5 import argparse |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
6 |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
7 def landmark_registration(points_file1, points_file2, out_file, residual_threshold=2, max_trials=100, delimiter="\t"): |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
8 points1 = pd.read_csv(points_file1, delimiter=delimiter) |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
9 points2 = pd.read_csv(points_file2, delimiter=delimiter) |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
10 |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
11 src = np.concatenate([np.array(points1['x']).reshape([-1,1]), np.array(points1['y']).reshape([-1,1])], axis=-1) |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
12 dst = np.concatenate([np.array(points2['x']).reshape([-1,1]), np.array(points2['y']).reshape([-1,1])], axis=-1) |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
13 |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
14 model = AffineTransform() |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
15 model_robust, inliers = ransac((src, dst), AffineTransform, min_samples=3, |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
16 residual_threshold=residual_threshold, max_trials=max_trials) |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
17 pd.DataFrame(model_robust.params).to_csv(out_file, header = None, index = False) |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
18 |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
19 if __name__ == "__main__": |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
20 parser = argparse.ArgumentParser(description="Estimate transformation from points") |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
21 parser.add_argument("points_file1", help="Paste path to src points") |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
22 parser.add_argument("points_file2", help="Paste path to dst points") |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
23 parser.add_argument("warp_matrix", help="Paste path to warp_matrix.csv that should be used for transformation") |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
24 parser.add_argument("--residual_threshold", dest="residual_threshold", help="Maximum distance for a data point to be classified as an inlier.", type=float, default=2) |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
25 parser.add_argument("--max_trials", dest="max_trials", help="Maximum number of iterations for random sample selection.", type=int, default=100) |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
26 args = parser.parse_args() |
a71239f3543a
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/landmark_registration/ commit d5df0e2f37920d09b5d942a7b128041ee1f0b6f5
imgteam
parents:
diff
changeset
|
27 landmark_registration(args.points_file1, args.points_file2, args.warp_matrix, residual_threshold=args.residual_threshold, max_trials=args.max_trials) |