comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:39e6d6a84257
1 import argparse
2 import sys
3 import pandas as pd
4 import skimage.io
5 from skimage.measure import label
6 from skimage.data import checkerboard
7 import numpy as np
8
9
10
11 def labelimage2points(input_file):
12 img_in = skimage.io.imread(input_file)
13
14 #amount of regions
15 amount_label = np.max(img_in)
16
17 # iterate over all regions in order to calc center of mass
18 center_mass = []
19 for i in range(1,amount_label+1):
20 #get coordinates of region
21 coord = np.where(img_in==i)
22 # be carefull with x,y coordinates
23 center_mass.append([np.mean(coord[1]),np.mean(coord[0])])
24
25 #make data frame of detections
26 out_dataFrame = pd.DataFrame(center_mass)
27
28
29 #return
30 return(out_dataFrame)
31
32
33 if __name__ == "__main__":
34 parser = argparse.ArgumentParser()
35 parser.add_argument('input_file', help='input file')
36 parser.add_argument('out_file', help='out file (CSV)')
37
38 args = parser.parse_args()
39 input_file = args.input_file
40 out_file = args.out_file
41
42 #TOOL
43 out_dataFrame = labelimage2points(input_file)
44
45 #Print to csv file
46 out_dataFrame.to_csv(out_file, index=False, header=False, sep="\t")