comparison binaryimage2points.py @ 1:f38f42d55813 draft default tip

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