Mercurial > repos > galaxyp > qupath_roi_splitter
comparison qupath_roi_splitter.py @ 3:24ccdcfbabac draft
planemo upload for repository hhttps://github.com/npinter/ROIsplitter commit 00029e8a3ee400f69a6dbe9e556ec9c27c6979cb
author | galaxyp |
---|---|
date | Thu, 25 Apr 2024 15:13:22 +0000 |
parents | 7bee859bbd11 |
children | 9f136ebf73ac |
comparison
equal
deleted
inserted
replaced
2:7bee859bbd11 | 3:24ccdcfbabac |
---|---|
23 first_roi = True | 23 first_roi = True |
24 for sub_roi in input_roi["geometry"]["coordinates"]: | 24 for sub_roi in input_roi["geometry"]["coordinates"]: |
25 # Polygon with holes | 25 # Polygon with holes |
26 if not isinstance(sub_roi[0][0], list): | 26 if not isinstance(sub_roi[0][0], list): |
27 if first_roi: | 27 if first_roi: |
28 input_img = draw_poly(sub_roi, input_img, fill=fill) | |
29 first_roi = False | 28 first_roi = False |
29 col = (0, 0, 0) | |
30 else: | 30 else: |
31 # holes in ROI | 31 # holes in ROI |
32 input_img = draw_poly(sub_roi, input_img, col=(255, 255, 255), fill=fill) | 32 col = (255, 255, 255) if not fill else (0, 0, 0) |
33 input_img = draw_poly(sub_roi, input_img, col=col, fill=fill) | |
33 else: | 34 else: |
34 # MultiPolygon with holes | 35 # MultiPolygon with holes |
35 for sub_coord in sub_roi: | 36 for sub_coord in sub_roi: |
36 if first_roi: | 37 if first_roi: |
37 input_img = draw_poly(sub_coord, input_img, fill=fill) | |
38 first_roi = False | 38 first_roi = False |
39 col = (0, 0, 0) | |
39 else: | 40 else: |
40 # holes in ROI | 41 # holes in ROI |
41 input_img = draw_poly(sub_coord, input_img, col=(255, 255, 255), fill=fill) | 42 col = (255, 255, 255) if not fill else (0, 0, 0) |
43 input_img = draw_poly(sub_coord, input_img, col=col, fill=fill) | |
42 | 44 |
43 return input_img | 45 return input_img |
44 | 46 |
45 | 47 |
46 def split_qupath_roi(in_roi): | 48 def split_qupath_roi(in_roi): |
87 subset=['x', 'y'], | 89 subset=['x', 'y'], |
88 keep='last').reset_index(drop=True) | 90 keep='last').reset_index(drop=True) |
89 | 91 |
90 coords_df.to_csv("{}_{}.txt".format(tma_name, cell_type), sep='\t', index=False) | 92 coords_df.to_csv("{}_{}.txt".format(tma_name, cell_type), sep='\t', index=False) |
91 | 93 |
94 # img save | |
95 if args.img: | |
96 cv2.imwrite("{}_{}.png".format(tma_name, cell_type), img) | |
97 | |
92 | 98 |
93 if __name__ == "__main__": | 99 if __name__ == "__main__": |
94 parser = argparse.ArgumentParser(description="Split ROI coordinates of QuPath TMA annotation by cell type (classfication)") | 100 parser = argparse.ArgumentParser(description="Split ROI coordinates of QuPath TMA annotation by cell type (classfication)") |
95 parser.add_argument("--qupath_roi", default=False, help="Input QuPath annotation (GeoJSON file)") | 101 parser.add_argument("--qupath_roi", default=False, help="Input QuPath annotation (GeoJSON file)") |
96 parser.add_argument("--fill", action="store_true", required=False, help="Fill pixels in ROIs") | 102 parser.add_argument("--fill", action="store_true", required=False, help="Fill pixels in ROIs") |
97 parser.add_argument('--version', action='version', version='%(prog)s 0.1.0') | 103 parser.add_argument('--version', action='version', version='%(prog)s 0.1.0') |
98 parser.add_argument("--all", action="store_true", required=False, help="Extracts all ROIs") | 104 parser.add_argument("--all", action="store_true", required=False, help="Extracts all ROIs") |
105 parser.add_argument("--img", action="store_true", required=False, help="Generates image of ROIs") | |
99 args = parser.parse_args() | 106 args = parser.parse_args() |
100 | 107 |
101 if args.qupath_roi: | 108 if args.qupath_roi: |
102 split_qupath_roi(args.qupath_roi) | 109 split_qupath_roi(args.qupath_roi) |