annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
1 import argparse
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
2 import sys
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
3 import pandas as pd
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
4 import skimage.io
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
5 from skimage.measure import label
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
6 from skimage.data import checkerboard
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
7 import numpy as np
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
8 import warnings
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
9
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
10
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
11
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
12 def binaryimage2points(input_file):
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
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
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
14 warnings.filterwarnings("ignore")
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
15
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
16 img_in = skimage.io.imread(input_file, plugin='tifffile')
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
17
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
18 #make label image
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
19 label = skimage.measure.label(img_in)
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
20
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
21 #amount of regions
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
22 amount_label = np.max(label)
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
23
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
24 # iterate over all regions in order to calc center of mass
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
25 center_mass = []
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
26 for i in range(1,amount_label+1):
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
27 #get coordinates of region
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
28 coord = np.where(label==i)
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
29 # be carefull with x,y coordinates
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
30 center_mass.append([np.mean(coord[1]),np.mean(coord[0])])
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
31
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
32 #make data frame of detections
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
33 out_dataFrame = pd.DataFrame(center_mass)
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
34
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
35
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
36 #return
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
37 return(out_dataFrame)
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
38
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
39
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
40 if __name__ == "__main__":
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
41 parser = argparse.ArgumentParser()
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
42 parser.add_argument('input_file', help='input file')
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
43 parser.add_argument('out_file', help='out file (TSV)')
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
44
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
45 args = parser.parse_args()
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
46 input_file = args.input_file
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
47 out_file = args.out_file
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
48
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
49 #TOOL
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
50 out_dataFrame = binaryimage2points(input_file)
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
51
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
52 #Print to csv file
cb1eaebdb4c4 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/binaryimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
53 out_dataFrame.to_csv(out_file, index=False, header=False, sep="\t")