annotate coordinates_of_roi.py @ 4:00175f4a2bbb draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
author imgteam
date Mon, 13 Nov 2023 22:10:52 +0000
parents 02a686fc1654
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
1 import argparse
4
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
2
0
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
3 import pandas as pd
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
4 import skimage.color
4
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
5 import skimage.io
0
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
6
4
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
7
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
8 def get_pixel_values(im, pixel_table, white_obj, threshold, offset=[0, 0]):
0
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
9 data = skimage.io.imread(im)
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
10 if len(data.shape) == 3 and data.shape[-1] > 1:
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
11 data = skimage.color.rgb2grey(data)
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
12 x = []
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
13 y = []
1
ee045a6bbdef planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit 4efef27bbe105490fc125e3586024ebb51fa929f
imgteam
parents: 0
diff changeset
14 img_height = data.shape[0]
ee045a6bbdef planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit 4efef27bbe105490fc125e3586024ebb51fa929f
imgteam
parents: 0
diff changeset
15 img_width = data.shape[1]
ee045a6bbdef planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit 4efef27bbe105490fc125e3586024ebb51fa929f
imgteam
parents: 0
diff changeset
16 for j in range(img_width):
ee045a6bbdef planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit 4efef27bbe105490fc125e3586024ebb51fa929f
imgteam
parents: 0
diff changeset
17 for i in range(img_height):
4
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
18 if not white_obj:
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
19 if data[i, j] <= threshold:
2
24d9bd16c953 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit bfae746780819634a014388ea4671a49fc5c178d
imgteam
parents: 1
diff changeset
20 x.append(i + offset[0])
24d9bd16c953 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit bfae746780819634a014388ea4671a49fc5c178d
imgteam
parents: 1
diff changeset
21 y.append(j + offset[1])
4
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
22 elif data[i, j] >= threshold:
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
23 x.append(i + offset[0])
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
24 y.append(j + offset[1])
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
25
0
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
26 df = pd.DataFrame()
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
27 df['x'] = x
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
28 df['y'] = y
4
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
29 df.to_csv(pixel_table, sep="\t", index=False)
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
30
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
31
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
32 if __name__ == "__main__":
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
33 parser = argparse.ArgumentParser(description="Create a csv table with Coordinates of the ROI")
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
34 parser.add_argument("im", help="Paste path to out.png (output created by transformation)")
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
35 parser.add_argument("pixel_table", help="Paste path to file in which list with all pixles > threshold should be saved")
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
36 parser.add_argument("--white_obj", dest="white_obj", default=False, help="If set objects in image are white otherwise black", action="store_true")
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
37 parser.add_argument("--threshold", dest="threshold", default=0.5, help="Enter desired threshold value", type=float)
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
38
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
39 args = parser.parse_args()
00175f4a2bbb planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/coordinates_of_roi/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents: 3
diff changeset
40 get_pixel_values(args.im, args.pixel_table, args.white_obj, args.threshold)