annotate coordinates_of_roi.py @ 0:0d30ffea8874 draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
author imgteam
date Sat, 09 Feb 2019 14:33:43 -0500
parents
children ee045a6bbdef
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
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
2 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
3 import skimage.io
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
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
5 import warnings
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
6
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
7 def get_pixel_values(im, pixel_table, white_obj, threshold, offset=[0,0]):
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
8 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
9 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
10 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
11 x = []
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
12 y = []
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
13 for i in range(data.shape[0]):
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
14 for j in range(data.shape[1]):
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
15 if white_obj == False:
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
16 if data[i,j] <= threshold:
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
17 x.append(j + offset[0])
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
18 y.append(i + offset[1])
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
19 elif data[i,j] >= threshold:
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
20 x.append(j + offset[0])
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
21 y.append(i + offset[1])
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
22
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
23 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
24 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
25 df['y'] = y
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
26 df.to_csv(pixel_table, sep="\t", index = False)
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
27
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
28 if __name__=="__main__":
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
29 parser = argparse.ArgumentParser(description = "Create a csv table with Coordinates of the ROI")
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
30 parser.add_argument("im", help = "Paste path to out.png (output created by transformation)")
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
31 parser.add_argument("pixel_table", help = "Paste path to file in which list with all pixles > threshold should be saved")
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
32 parser.add_argument('offset_x', type=int, help='offset in x direction (width)', default=0)
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
33 parser.add_argument('offset_y', type=int, help='offset in y direction (height)', default=0)
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
34 parser.add_argument("--white_obj", dest = "white_obj", default=False, help = "If set objects in image are white otherwise black", action = "store_true")
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
35 parser.add_argument("--threshold", dest = "threshold", default = 0.5, help = "Enter desired threshold value", type = float)
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
36
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
37 args = parser.parse_args()
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
38 # with warnings.catch_warnings():
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
39 # warnings.simplefilter("ignore")
0d30ffea8874 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/coordinates_of_roi/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
imgteam
parents:
diff changeset
40 get_pixel_values(args.im, args.pixel_table, args.white_obj, args.threshold, [args.offset_x, args.offset_y])