annotate colocalization_viz.py @ 1:fc85eb253163 draft

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