annotate labelimage2points.py @ 0:87e7a5835f77 draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
author imgteam
date Sat, 09 Feb 2019 14:18:19 -0500
parents
children 398ca4f5e279
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
1 import argparse
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
2 import sys
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
3 import pandas as pd
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
4 import skimage.io
87e7a5835f77 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
87e7a5835f77 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
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
7 import numpy as np
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
8
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
9
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
10
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
11 def labelimage2points(input_file):
87e7a5835f77 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)
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
13
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
14 #amount of regions
87e7a5835f77 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)
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
16
87e7a5835f77 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
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
18 center_mass = []
87e7a5835f77 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):
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
20 #get coordinates of region
87e7a5835f77 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)
87e7a5835f77 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
87e7a5835f77 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])])
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
24
87e7a5835f77 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
87e7a5835f77 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)
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
27
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
28
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
29 #return
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
30 return(out_dataFrame)
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
31
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
32
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
33 if __name__ == "__main__":
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
34 parser = argparse.ArgumentParser()
87e7a5835f77 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')
87e7a5835f77 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)')
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
37
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
38 args = parser.parse_args()
87e7a5835f77 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
87e7a5835f77 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
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
41
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
42 #TOOL
87e7a5835f77 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)
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
44
87e7a5835f77 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
45 #Print to csv file
87e7a5835f77 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")