annotate labelimage2points.py @ 0:39e6d6a84257 draft

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