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