Mercurial > repos > imgteam > projective_transformation
comparison projective_transformation.py @ 3:be9a815e2240 draft
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/projective_transformation/ commit ee372547082b693ef1bbe10b5b7ea8660b9779df"
author | imgteam |
---|---|
date | Thu, 20 Jan 2022 17:14:55 +0000 |
parents | 1ffdb07020ee |
children | 37b079c98c38 |
comparison
equal
deleted
inserted
replaced
2:1ffdb07020ee | 3:be9a815e2240 |
---|---|
5 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT | 5 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
6 | 6 |
7 """ | 7 """ |
8 | 8 |
9 import argparse | 9 import argparse |
10 import imghdr | |
11 import warnings | 10 import warnings |
12 | 11 |
13 import numpy as np | 12 import numpy as np |
14 import pandas as pd | 13 import pandas as pd |
15 import skimage.color | 14 import skimage.color |
48 | 47 |
49 | 48 |
50 def transform(moving_fn, fixed_fn, warp_mat, output_fn): | 49 def transform(moving_fn, fixed_fn, warp_mat, output_fn): |
51 | 50 |
52 moving = skimage.io.imread(moving_fn) | 51 moving = skimage.io.imread(moving_fn) |
53 extension = imghdr.what(moving_fn) | |
54 nDims = len(moving.shape) | 52 nDims = len(moving.shape) |
55 assert nDims in [2, 3, 4, 5, 6], 'this tool only supports up to 6 dimensions' | 53 assert nDims in [2, 3, 4, 5, 6], 'this tool only supports up to 6 dimensions' |
56 | 54 |
57 if moving.shape[-1] in [3, 4] and nDims > 2: | 55 if moving.shape[-1] in [3, 4] and nDims > 2: |
58 isRGB = True | 56 isRGB = True |
94 warped_moving = map_coordinates(moving, warped_coords, cval=0) | 92 warped_moving = map_coordinates(moving, warped_coords, cval=0) |
95 | 93 |
96 with warnings.catch_warnings(): | 94 with warnings.catch_warnings(): |
97 warnings.simplefilter("ignore") | 95 warnings.simplefilter("ignore") |
98 if isMulCh: | 96 if isMulCh: |
99 tifffile.imwrite(output_fn + '.tif', warped_moving, imagej=True, metadata={'mode': 'composite'}) | 97 tifffile.imwrite(output_fn, warped_moving, imagej=True, metadata={'mode': 'composite'}) |
100 else: | 98 else: |
101 skimage.io.imsave(output_fn + '.' + extension, warped_moving) | 99 skimage.io.imsave(output_fn, warped_moving) |
102 | 100 |
103 | 101 |
104 if __name__ == "__main__": | 102 if __name__ == "__main__": |
105 parser = argparse.ArgumentParser(description="Transform the image") | 103 parser = argparse.ArgumentParser(description="Transform the image") |
106 parser.add_argument("fixed_image", help="Path to the fixed image") | 104 parser.add_argument("fixed_image", help="Path to the fixed image") |