Mercurial > repos > imgteam > coordinates_of_roi
comparison 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 |
comparison
equal
deleted
inserted
replaced
3:02a686fc1654 | 4:00175f4a2bbb |
---|---|
1 import argparse | 1 import argparse |
2 | |
2 import pandas as pd | 3 import pandas as pd |
4 import skimage.color | |
3 import skimage.io | 5 import skimage.io |
4 import skimage.color | |
5 import warnings | |
6 | 6 |
7 def get_pixel_values(im, pixel_table, white_obj, threshold, offset=[0,0]): | 7 |
8 def get_pixel_values(im, pixel_table, white_obj, threshold, offset=[0, 0]): | |
8 data = skimage.io.imread(im) | 9 data = skimage.io.imread(im) |
9 if len(data.shape) == 3 and data.shape[-1] > 1: | 10 if len(data.shape) == 3 and data.shape[-1] > 1: |
10 data = skimage.color.rgb2grey(data) | 11 data = skimage.color.rgb2grey(data) |
11 x = [] | 12 x = [] |
12 y = [] | 13 y = [] |
13 img_height = data.shape[0] | 14 img_height = data.shape[0] |
14 img_width = data.shape[1] | 15 img_width = data.shape[1] |
15 for j in range(img_width): | 16 for j in range(img_width): |
16 for i in range(img_height): | 17 for i in range(img_height): |
17 if white_obj == False: | 18 if not white_obj: |
18 if data[i,j] <= threshold: | 19 if data[i, j] <= threshold: |
19 x.append(i + offset[0]) | 20 x.append(i + offset[0]) |
20 y.append(j + offset[1]) | 21 y.append(j + offset[1]) |
21 elif data[i,j] >= threshold: | 22 elif data[i, j] >= threshold: |
22 x.append(i + offset[0]) | 23 x.append(i + offset[0]) |
23 y.append(j + offset[1]) | 24 y.append(j + offset[1]) |
24 | 25 |
25 df = pd.DataFrame() | 26 df = pd.DataFrame() |
26 df['x'] = x | 27 df['x'] = x |
27 df['y'] = y | 28 df['y'] = y |
28 df.to_csv(pixel_table, sep="\t", index = False) | 29 df.to_csv(pixel_table, sep="\t", index=False) |
29 | 30 |
30 if __name__=="__main__": | 31 |
31 parser = argparse.ArgumentParser(description = "Create a csv table with Coordinates of the ROI") | 32 if __name__ == "__main__": |
32 parser.add_argument("im", help = "Paste path to out.png (output created by transformation)") | 33 parser = argparse.ArgumentParser(description="Create a csv table with Coordinates of the ROI") |
33 parser.add_argument("pixel_table", help = "Paste path to file in which list with all pixles > threshold should be saved") | 34 parser.add_argument("im", help="Paste path to out.png (output created by transformation)") |
34 parser.add_argument("--white_obj", dest = "white_obj", default=False, help = "If set objects in image are white otherwise black", action = "store_true") | 35 parser.add_argument("pixel_table", help="Paste path to file in which list with all pixles > threshold should be saved") |
35 parser.add_argument("--threshold", dest = "threshold", default = 0.5, help = "Enter desired threshold value", type = float) | 36 parser.add_argument("--white_obj", dest="white_obj", default=False, help="If set objects in image are white otherwise black", action="store_true") |
36 | 37 parser.add_argument("--threshold", dest="threshold", default=0.5, help="Enter desired threshold value", type=float) |
37 args = parser.parse_args() | 38 |
38 # with warnings.catch_warnings(): | 39 args = parser.parse_args() |
39 # warnings.simplefilter("ignore") | 40 get_pixel_values(args.im, args.pixel_table, args.white_obj, args.threshold) |
40 get_pixel_values(args.im, args.pixel_table, args.white_obj, args.threshold) |