annotate colocalization_viz.py @ 3:9ccf11c11d85 draft default tip

"planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 0500f513ee291ae0f6fad32a0b4fad05cd59cb71"
author imgteam
date Sat, 26 Feb 2022 17:11:36 +0000
parents 808111e56957
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
9d740d639013 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 1453917dfaf4c0922aec82c400015ff7e13ab737
imgteam
parents: 0
diff changeset
1 import argparse
0
dd3ffe3141ae planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
2 import sys
dd3ffe3141ae planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
3
3
9ccf11c11d85 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 0500f513ee291ae0f6fad32a0b4fad05cd59cb71"
imgteam
parents: 2
diff changeset
4 import numpy as np
9ccf11c11d85 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 0500f513ee291ae0f6fad32a0b4fad05cd59cb71"
imgteam
parents: 2
diff changeset
5 import skimage.color
9ccf11c11d85 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 0500f513ee291ae0f6fad32a0b4fad05cd59cb71"
imgteam
parents: 2
diff changeset
6 import skimage.io
9ccf11c11d85 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 0500f513ee291ae0f6fad32a0b4fad05cd59cb71"
imgteam
parents: 2
diff changeset
7 from skimage import img_as_uint
9ccf11c11d85 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 0500f513ee291ae0f6fad32a0b4fad05cd59cb71"
imgteam
parents: 2
diff changeset
8 from skimage.exposure import equalize_adapthist
0
dd3ffe3141ae planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
9
3
9ccf11c11d85 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 0500f513ee291ae0f6fad32a0b4fad05cd59cb71"
imgteam
parents: 2
diff changeset
10
9ccf11c11d85 "planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 0500f513ee291ae0f6fad32a0b4fad05cd59cb71"
imgteam
parents: 2
diff changeset
11 # TODO make importable by python script
0
dd3ffe3141ae planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
12 def readImg(path):
dd3ffe3141ae planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
13 img = skimage.io.imread(path)
1
9d740d639013 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 1453917dfaf4c0922aec82c400015ff7e13ab737
imgteam
parents: 0
diff changeset
14
0
dd3ffe3141ae planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
15 if len(img.shape) > 2:
dd3ffe3141ae planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
16 img = skimage.color.rgb2gray(img)
1
9d740d639013 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 1453917dfaf4c0922aec82c400015ff7e13ab737
imgteam
parents: 0
diff changeset
17 img = equalize_adapthist(img, clip_limit=0.03)
9d740d639013 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 1453917dfaf4c0922aec82c400015ff7e13ab737
imgteam
parents: 0
diff changeset
18 img = img_as_uint(img)
9d740d639013 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 1453917dfaf4c0922aec82c400015ff7e13ab737
imgteam
parents: 0
diff changeset
19 img = np.reshape(img, [img.shape[0], img.shape[1], 1])
0
dd3ffe3141ae planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
20 return img
dd3ffe3141ae planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
21
dd3ffe3141ae planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
22
1
9d740d639013 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 1453917dfaf4c0922aec82c400015ff7e13ab737
imgteam
parents: 0
diff changeset
23 parser = argparse.ArgumentParser()
9d740d639013 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 1453917dfaf4c0922aec82c400015ff7e13ab737
imgteam
parents: 0
diff changeset
24 parser.add_argument('input_file1', type=argparse.FileType('r'), default=sys.stdin, help='input file (red)')
9d740d639013 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 1453917dfaf4c0922aec82c400015ff7e13ab737
imgteam
parents: 0
diff changeset
25 parser.add_argument('input_file2', type=argparse.FileType('r'), default=sys.stdin, help='input file (green)')
9d740d639013 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 1453917dfaf4c0922aec82c400015ff7e13ab737
imgteam
parents: 0
diff changeset
26 parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)')
9d740d639013 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 1453917dfaf4c0922aec82c400015ff7e13ab737
imgteam
parents: 0
diff changeset
27 args = parser.parse_args()
9d740d639013 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 1453917dfaf4c0922aec82c400015ff7e13ab737
imgteam
parents: 0
diff changeset
28
9d740d639013 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 1453917dfaf4c0922aec82c400015ff7e13ab737
imgteam
parents: 0
diff changeset
29 im1 = readImg(args.input_file1.name)
9d740d639013 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 1453917dfaf4c0922aec82c400015ff7e13ab737
imgteam
parents: 0
diff changeset
30 im2 = readImg(args.input_file2.name)
9d740d639013 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 1453917dfaf4c0922aec82c400015ff7e13ab737
imgteam
parents: 0
diff changeset
31 res = np.concatenate((im1, im2, np.zeros_like(im1)), axis=-1)
9d740d639013 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/colocalization_viz/ commit 1453917dfaf4c0922aec82c400015ff7e13ab737
imgteam
parents: 0
diff changeset
32 skimage.io.imsave(args.out_file.name, res)