annotate labelimage2points.py @ 2:3b7460735223 draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
author imgteam
date Mon, 13 Nov 2023 22:11:16 +0000
parents 07525a7d9ea0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
1 import argparse
2
3b7460735223 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 1
diff changeset
2
3b7460735223 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 1
diff changeset
3 import numpy as np
0
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
4 import pandas as pd
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
5 import skimage.io
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
6
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
7
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
8 def labelimage2points(input_file):
2
3b7460735223 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 1
diff changeset
9 img_in = skimage.io.imread(input_file)
3b7460735223 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 1
diff changeset
10
3b7460735223 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 1
diff changeset
11 # amount of regions
0
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
12 amount_label = np.max(img_in)
2
3b7460735223 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 1
diff changeset
13
0
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
14 # iterate over all regions in order to calc center of mass
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
15 center_mass = []
2
3b7460735223 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 1
diff changeset
16 for i in range(1, amount_label + 1):
3b7460735223 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 1
diff changeset
17 # get coordinates of region
3b7460735223 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 1
diff changeset
18 coord = np.where(img_in == i)
0
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
19 # be carefull with x,y coordinates
2
3b7460735223 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 1
diff changeset
20 center_mass.append([np.mean(coord[1]), np.mean(coord[0])])
0
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
21
2
3b7460735223 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 1
diff changeset
22 # make data frame of detections
0
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
23 out_dataFrame = pd.DataFrame(center_mass)
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
24
2
3b7460735223 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 1
diff changeset
25 # return
3b7460735223 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 1
diff changeset
26 return out_dataFrame
0
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
27
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
28
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
29 if __name__ == "__main__":
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
30 parser = argparse.ArgumentParser()
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
31 parser.add_argument('input_file', help='input file')
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
32 parser.add_argument('out_file', help='out file (CSV)')
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
33
2
3b7460735223 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 1
diff changeset
34 args = parser.parse_args()
3b7460735223 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 1
diff changeset
35 input_file = args.input_file
3b7460735223 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 1
diff changeset
36 out_file = args.out_file
0
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
37
2
3b7460735223 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 1
diff changeset
38 # TOOL
0
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
39 out_dataFrame = labelimage2points(input_file)
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
40
2
3b7460735223 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/labelimage2points/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 1
diff changeset
41 # Print to csv file
0
39e6d6a84257 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/labelimage2points/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
42 out_dataFrame.to_csv(out_file, index=False, header=False, sep="\t")