Mercurial > repos > thomaswollmann > binaryimage2points
comparison binaryimage2points.py @ 0:c983b2d2cdd7 draft default tip
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit 27a6350188f687411bdd6bfe0d569c0803389ca0
author | thomaswollmann |
---|---|
date | Wed, 12 Dec 2018 04:49:24 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c983b2d2cdd7 |
---|---|
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 import warnings | |
9 | |
10 | |
11 | |
12 def binaryimage2points(input_file): | |
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 | |
14 warnings.filterwarnings("ignore") | |
15 | |
16 img_in = skimage.io.imread(input_file, plugin='tifffile') | |
17 | |
18 #make label image | |
19 label = skimage.measure.label(img_in) | |
20 | |
21 #amount of regions | |
22 amount_label = np.max(label) | |
23 | |
24 # iterate over all regions in order to calc center of mass | |
25 center_mass = [] | |
26 for i in range(1,amount_label+1): | |
27 #get coordinates of region | |
28 coord = np.where(label==i) | |
29 # be carefull with x,y coordinates | |
30 center_mass.append([np.mean(coord[1]),np.mean(coord[0])]) | |
31 | |
32 #make data frame of detections | |
33 out_dataFrame = pd.DataFrame(center_mass) | |
34 | |
35 | |
36 #return | |
37 return(out_dataFrame) | |
38 | |
39 | |
40 | |
41 | |
42 if __name__ == "__main__": | |
43 parser = argparse.ArgumentParser() | |
44 parser.add_argument('input_file', help='input file') | |
45 parser.add_argument('out_file', help='out file (CSV)') | |
46 | |
47 args = parser.parse_args() | |
48 input_file = args.input_file | |
49 out_file = args.out_file | |
50 | |
51 #TOOL | |
52 out_dataFrame = binaryimage2points(input_file) | |
53 | |
54 #Print to csv file | |
55 out_dataFrame.to_csv(out_file,index=False,header=False) |