annotate binaryimage2points.py @ 0:055f88f0315a draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
author imgteam
date Sat, 09 Feb 2019 14:13:38 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
1 import argparse
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
2 import sys
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
3 import pandas as pd
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
4 import skimage.io
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
5 from skimage.measure import label
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
6 from skimage.data import checkerboard
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
7 import numpy as np
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
8 import warnings
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
9
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
10
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
11
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
12 def binaryimage2points(input_file):
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
13 # ignore warnings that arise when importing a package that was compiled against an older version of numpy than installed; https://github.com/numpy/numpy/pull/432
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
14 warnings.filterwarnings("ignore")
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
15
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
16 img_in = skimage.io.imread(input_file, plugin='tifffile')
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
17
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
18 #make label image
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
19 label = skimage.measure.label(img_in)
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
20
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
21 #amount of regions
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
22 amount_label = np.max(label)
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
23
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
24 # iterate over all regions in order to calc center of mass
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
25 center_mass = []
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
26 for i in range(1,amount_label+1):
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
27 #get coordinates of region
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
28 coord = np.where(label==i)
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
29 # be carefull with x,y coordinates
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
30 center_mass.append([np.mean(coord[1]),np.mean(coord[0])])
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
31
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
32 #make data frame of detections
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
33 out_dataFrame = pd.DataFrame(center_mass)
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
34
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
35
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
36 #return
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
37 return(out_dataFrame)
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
38
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
39
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
40 if __name__ == "__main__":
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
41 parser = argparse.ArgumentParser()
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
42 parser.add_argument('input_file', help='input file')
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
43 parser.add_argument('out_file', help='out file (TSV)')
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
44
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
45 args = parser.parse_args()
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
46 input_file = args.input_file
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
47 out_file = args.out_file
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
48
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
49 #TOOL
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
50 out_dataFrame = binaryimage2points(input_file)
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
51
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
52 #Print to csv file
055f88f0315a planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
53 out_dataFrame.to_csv(out_file, index=False, header=False, sep="\t")