Mercurial > repos > imgteam > 2d_filter_segmentation_by_features
comparison 2d_filter_segmentation_by_features.py @ 0:e576b73a2e2f draft
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_filter_segmentation_by_features/ commit b2acc1845a25828181597fe5b6982fe116a7796d
author | imgteam |
---|---|
date | Mon, 22 Jul 2019 05:00:03 -0400 |
parents | |
children | 6ad1d3cfdea1 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:e576b73a2e2f |
---|---|
1 import argparse | |
2 import sys | |
3 import skimage.io | |
4 import skimage.util | |
5 import pandas as pd | |
6 | |
7 if __name__ == "__main__": | |
8 parser = argparse.ArgumentParser(description='Filter segmentation by features') | |
9 parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file') | |
10 parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)') | |
11 parser.add_argument('feature_file', type=argparse.FileType('r'), default=sys.stdin, help='feature file (cols: label, f1, f2)') | |
12 parser.add_argument('rule_file', type=argparse.FileType('r'), default=sys.stdin, help='file with rules per feature (cols: ,f1,2, rows: feature_name, min, max)') | |
13 args = parser.parse_args() | |
14 | |
15 img_in = skimage.io.imread(args.input_file.name) | |
16 features = pd.read_csv(args.feature_file, delimiter="\t") | |
17 rules = pd.read_csv(args.rule_file, delimiter="\t") | |
18 | |
19 cols = [a for a in rules.columns if not 'Unnamed' in a] | |
20 for a_c in cols: | |
21 a_min = rules[rules.ix[:, 0] == 'min'][a_c] | |
22 a_max = rules[rules.ix[:, 0] == 'max'][a_c] | |
23 for a_l in features.label: | |
24 a_val = float(features[features['label'] == a_l][a_c]) | |
25 if a_val < float(a_min) or a_val > float(a_max): | |
26 img_in[img_in == int(a_l)] = 0 | |
27 | |
28 res = skimage.util.img_as_uint(img_in) | |
29 skimage.io.imsave(args.out_file.name, res, plugin="tifffile") |