Mercurial > repos > imgteam > overlay_moving_and_fixed_image
comparison overlay_moving_and_fixed_image.py @ 2:93533276bf1d draft default tip
"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/overlay_moving_and_fixed_image/ commit 0500f513ee291ae0f6fad32a0b4fad05cd59cb71"
author | imgteam |
---|---|
date | Sat, 26 Feb 2022 17:12:41 +0000 |
parents | f9df2b32b632 |
children |
comparison
equal
deleted
inserted
replaced
1:f9df2b32b632 | 2:93533276bf1d |
---|---|
1 import argparse | 1 import argparse |
2 from PIL import Image | 2 |
3 import skimage.io | |
4 import skimage.color | |
5 from skimage.transform import ProjectiveTransform | |
6 from scipy.ndimage import map_coordinates | |
7 import numpy as np | 3 import numpy as np |
8 import pandas as pd | 4 import pandas as pd |
5 import skimage.color | |
6 import skimage.io | |
7 from PIL import Image | |
8 from scipy.ndimage import map_coordinates | |
9 from skimage.transform import ProjectiveTransform | |
9 | 10 |
10 | 11 |
11 def _stackcopy(a, b): | 12 def _stackcopy(a, b): |
12 if a.ndim == 3: | 13 if a.ndim == 3: |
13 a[:] = b[:, :, np.newaxis] | 14 a[:] = b[:, :, np.newaxis] |
22 coords_shape.append(shape[2]) | 23 coords_shape.append(shape[2]) |
23 coords = np.empty(coords_shape, dtype=dtype) | 24 coords = np.empty(coords_shape, dtype=dtype) |
24 | 25 |
25 tf_coords = np.indices((cols, rows), dtype=dtype).reshape(2, -1).T | 26 tf_coords = np.indices((cols, rows), dtype=dtype).reshape(2, -1).T |
26 | 27 |
27 for i in range(0, (tf_coords.shape[0]//batch_size+1)): | 28 for i in range(0, (tf_coords.shape[0] // batch_size + 1)): |
28 tf_coords[batch_size*i:batch_size*(i+1)] = coord_map(tf_coords[batch_size*i:batch_size*(i+1)]) | 29 tf_coords[batch_size * i:batch_size * (i + 1)] = coord_map(tf_coords[batch_size * i:batch_size * (i + 1)]) |
29 tf_coords = tf_coords.T.reshape((-1, cols, rows)).swapaxes(1, 2) | 30 tf_coords = tf_coords.T.reshape((-1, cols, rows)).swapaxes(1, 2) |
30 | 31 |
31 _stackcopy(coords[1, ...], tf_coords[0, ...]) | 32 _stackcopy(coords[1, ...], tf_coords[0, ...]) |
32 _stackcopy(coords[0, ...], tf_coords[1, ...]) | 33 _stackcopy(coords[0, ...], tf_coords[1, ...]) |
33 if len(shape) == 3: | 34 if len(shape) == 3: |
34 coords[2, ...] = range(shape[2]) | 35 coords[2, ...] = range(shape[2]) |
35 | 36 |
36 return coords | 37 return coords |
37 | 38 |
45 def overlay(moving_image, fixed_image, factor, overlay_out_path): | 46 def overlay(moving_image, fixed_image, factor, overlay_out_path): |
46 moving_image = Image.fromarray(moving_image).convert("RGBA") | 47 moving_image = Image.fromarray(moving_image).convert("RGBA") |
47 fixed_image = Image.fromarray(fixed_image).convert("RGBA") | 48 fixed_image = Image.fromarray(fixed_image).convert("RGBA") |
48 overlay_out = Image.blend(moving_image, fixed_image, factor) | 49 overlay_out = Image.blend(moving_image, fixed_image, factor) |
49 overlay_out.save(overlay_out_path, "PNG") | 50 overlay_out.save(overlay_out_path, "PNG") |
50 | |
51 | 51 |
52 if __name__=="__main__": | 52 |
53 parser = argparse.ArgumentParser(description = "Overlay two images") | 53 if __name__ == "__main__": |
54 parser.add_argument("fixed_image", help = "Path to fixed image") | 54 parser = argparse.ArgumentParser(description="Overlay two images") |
55 parser.add_argument("moving_image", help = "Path to moving image") | 55 parser.add_argument("fixed_image", help="Path to fixed image") |
56 parser.add_argument("moving_image", help="Path to moving image") | |
56 parser.add_argument("warp_matrix", help="Paste path to warp_matrix.csv that should be used for transformation") | 57 parser.add_argument("warp_matrix", help="Paste path to warp_matrix.csv that should be used for transformation") |
57 parser.add_argument("--inverse_transform", dest='inverse_transform', action='store_true', help="Set if inverse transform should be visualized") | 58 parser.add_argument("--inverse_transform", dest='inverse_transform', action='store_true', help="Set if inverse transform should be visualized") |
58 parser.add_argument("--factor", dest = "factor", help = "Enter the factor by which images should be blended, 1.0 returns a copy of second image", type = float, default = 0.5) | 59 parser.add_argument("--factor", dest="factor", help="Enter the factor by which images should be blended, 1.0 returns a copy of second image", type=float, default=0.5) |
59 parser.add_argument("overlay_out", help = "Overlay output path") | 60 parser.add_argument("overlay_out", help="Overlay output path") |
60 args = parser.parse_args() | 61 args = parser.parse_args() |
61 | 62 |
62 fixed_image = skimage.io.imread(args.fixed_image) | 63 fixed_image = skimage.io.imread(args.fixed_image) |
63 moving_image = skimage.io.imread(args.moving_image) | 64 moving_image = skimage.io.imread(args.moving_image) |
64 | 65 |