comparison labelimage2points.py @ 0:732d95b2b030 draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
author thomaswollmann
date Wed, 12 Dec 2018 04:38:34 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:732d95b2b030
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
34
35 if __name__ == "__main__":
36 parser = argparse.ArgumentParser()
37 parser.add_argument('input_file', help='input file')
38 parser.add_argument('out_file', help='out file (CSV)')
39
40 args = parser.parse_args()
41 input_file = args.input_file
42 out_file = args.out_file
43
44 #TOOL
45 out_dataFrame = labelimage2points(input_file)
46
47 #Print to csv file
48 out_dataFrame.to_csv(out_file,index=False,header=False)