|
a |
|
b/build_preset.py |
|
|
1 |
import os |
|
|
2 |
import pandas as pd |
|
|
3 |
import argparse |
|
|
4 |
|
|
|
5 |
|
|
|
6 |
parser = argparse.ArgumentParser(description='preset_builder') |
|
|
7 |
parser.add_argument('--preset_name', type=str, |
|
|
8 |
help='name of preset') |
|
|
9 |
parser.add_argument('--seg_level', type=int, default=-1, |
|
|
10 |
help='downsample level at which to segment') |
|
|
11 |
parser.add_argument('--sthresh', type=int, default=8, |
|
|
12 |
help='segmentation threshold') |
|
|
13 |
parser.add_argument('--mthresh', type=int, default=7, |
|
|
14 |
help='median filter threshold') |
|
|
15 |
parser.add_argument('--use_otsu', action='store_true', default=False) |
|
|
16 |
parser.add_argument('--close', type=int, default=4, |
|
|
17 |
help='additional morphological closing') |
|
|
18 |
parser.add_argument('--a_t', type=int, default=100, |
|
|
19 |
help='area filter for tissue') |
|
|
20 |
parser.add_argument('--a_h', type=int, default=16, |
|
|
21 |
help='area filter for holes') |
|
|
22 |
parser.add_argument('--max_n_holes', type=int, default=8, |
|
|
23 |
help='maximum number of holes to consider for each tissue contour') |
|
|
24 |
parser.add_argument('--vis_level', type=int, default=-1, |
|
|
25 |
help='downsample level at which to visualize') |
|
|
26 |
parser.add_argument('--line_thickness', type=int, default=250, |
|
|
27 |
help='line_thickness to visualize segmentation') |
|
|
28 |
parser.add_argument('--white_thresh', type=int, default=5, |
|
|
29 |
help='saturation threshold for whether to consider a patch as blank for exclusion') |
|
|
30 |
parser.add_argument('--black_thresh', type=int, default=50, |
|
|
31 |
help='mean rgb threshold for whether to consider a patch as black for exclusion') |
|
|
32 |
parser.add_argument('--no_padding', action='store_false', default=True) |
|
|
33 |
parser.add_argument('--contour_fn', type=str, choices=['four_pt', 'center', 'basic', 'four_pt_hard'], default='four_pt', |
|
|
34 |
help='contour checking function') |
|
|
35 |
|
|
|
36 |
|
|
|
37 |
if __name__ == '__main__': |
|
|
38 |
args = parser.parse_args() |
|
|
39 |
seg_params = {'seg_level': args.seg_level, 'sthresh': args.sthresh, 'mthresh': args.mthresh, |
|
|
40 |
'close': args.close, 'use_otsu': args.use_otsu, 'keep_ids': 'none', 'exclude_ids': 'none'} |
|
|
41 |
filter_params = {'a_t':args.a_t, 'a_h': args.a_h, 'max_n_holes': args.max_n_holes} |
|
|
42 |
vis_params = {'vis_level': args.vis_level, 'line_thickness': args.line_thickness} |
|
|
43 |
patch_params = {'white_thresh': args.white_thresh, 'black_thresh': args.black_thresh, |
|
|
44 |
'use_padding': args.no_padding, 'contour_fn': args.contour_fn} |
|
|
45 |
|
|
|
46 |
all_params = {} |
|
|
47 |
all_params.update(seg_params) |
|
|
48 |
all_params.update(filter_params) |
|
|
49 |
all_params.update(vis_params) |
|
|
50 |
all_params.update(patch_params) |
|
|
51 |
params_df = pd.DataFrame(all_params, index=[0]) |
|
|
52 |
params_df.to_csv('presets/{}'.format(args.preset_name), index=False) |
|
|
53 |
|