annotate labelimage2points.py @ 0:fbf98697084e 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:36:14 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
1 import argparse
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
2 import sys
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
3 import pandas as pd
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
4 import skimage.io
fbf98697084e 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
fbf98697084e 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
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
7 import numpy as np
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
8
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
9
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
10
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
11 def labelimage2points(input_file):
fbf98697084e 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)
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
13
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
14 #amount of regions
fbf98697084e 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)
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
16
fbf98697084e 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
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
18 center_mass = []
fbf98697084e 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):
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
20 #get coordinates of region
fbf98697084e 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)
fbf98697084e 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
fbf98697084e 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])])
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
24
fbf98697084e 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
fbf98697084e 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)
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
27
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
28
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
29 #return
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
30 return(out_dataFrame)
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
31
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
32
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
33
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
34
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
35 if __name__ == "__main__":
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
36 parser = argparse.ArgumentParser()
fbf98697084e 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')
fbf98697084e 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)')
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
39
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
40 args = parser.parse_args()
fbf98697084e 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
fbf98697084e 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
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
43
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
44 #TOOL
fbf98697084e 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)
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
46
fbf98697084e planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit a0ba841e8b3aee770a3243155bedfac0adf9a5a6
thomaswollmann
parents:
diff changeset
47 #Print to csv file
fbf98697084e 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)