Mercurial > repos > imgteam > binaryimage2points
comparison binaryimage2points.py @ 0:cb1eaebdb4c4 draft
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
author | imgteam |
---|---|
date | Sat, 09 Feb 2019 14:31:13 -0500 |
parents | |
children | f38f42d55813 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cb1eaebdb4c4 |
---|---|
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 if __name__ == "__main__": | |
41 parser = argparse.ArgumentParser() | |
42 parser.add_argument('input_file', help='input file') | |
43 parser.add_argument('out_file', help='out file (TSV)') | |
44 | |
45 args = parser.parse_args() | |
46 input_file = args.input_file | |
47 out_file = args.out_file | |
48 | |
49 #TOOL | |
50 out_dataFrame = binaryimage2points(input_file) | |
51 | |
52 #Print to csv file | |
53 out_dataFrame.to_csv(out_file, index=False, header=False, sep="\t") |