# HG changeset patch # User imgteam # Date 1563786003 14400 # Node ID e576b73a2e2fbad01ae5c2c3f72a5dc7f3667a7b planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/2d_filter_segmentation_by_features/ commit b2acc1845a25828181597fe5b6982fe116a7796d diff -r 000000000000 -r e576b73a2e2f 2d_filter_segmentation_by_features.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/2d_filter_segmentation_by_features.py Mon Jul 22 05:00:03 2019 -0400 @@ -0,0 +1,29 @@ +import argparse +import sys +import skimage.io +import skimage.util +import pandas as pd + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='Filter segmentation by features') + parser.add_argument('input_file', type=argparse.FileType('r'), default=sys.stdin, help='input file') + parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file (TIFF)') + parser.add_argument('feature_file', type=argparse.FileType('r'), default=sys.stdin, help='feature file (cols: label, f1, f2)') + 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)') + args = parser.parse_args() + + img_in = skimage.io.imread(args.input_file.name) + features = pd.read_csv(args.feature_file, delimiter="\t") + rules = pd.read_csv(args.rule_file, delimiter="\t") + + cols = [a for a in rules.columns if not 'Unnamed' in a] + for a_c in cols: + a_min = rules[rules.ix[:, 0] == 'min'][a_c] + a_max = rules[rules.ix[:, 0] == 'max'][a_c] + for a_l in features.label: + a_val = float(features[features['label'] == a_l][a_c]) + if a_val < float(a_min) or a_val > float(a_max): + img_in[img_in == int(a_l)] = 0 + + res = skimage.util.img_as_uint(img_in) + skimage.io.imsave(args.out_file.name, res, plugin="tifffile") diff -r 000000000000 -r e576b73a2e2f 2d_filter_segmentation_by_features.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/2d_filter_segmentation_by_features.xml Mon Jul 22 05:00:03 2019 -0400 @@ -0,0 +1,37 @@ + + Filter segmentation by rules + + scikit-image + pillow + pandas + tifffile + + + + + + + + + + + + + + + + + + + + + + Filter label image by rules (e.g., remove large or deformed objects). + Rules file has a specific format (cols: ,f1,2, rows: feature_name, min, max). The features have to be also profived in a specific format (cols: label, f1, f2). + + + 10.1016/j.jbiotec.2017.07.019 + + diff -r 000000000000 -r e576b73a2e2f test-data/features.tabular --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/features.tabular Mon Jul 22 05:00:03 2019 -0400 @@ -0,0 +1,5 @@ +label area eccentricity +1 344 0.42521053699241596 +2 434 0.47679001553231926 +3 907 0.9973539531125177 +4 14320 0.17131009631035327 diff -r 000000000000 -r e576b73a2e2f test-data/in.tif Binary file test-data/in.tif has changed diff -r 000000000000 -r e576b73a2e2f test-data/out.tif Binary file test-data/out.tif has changed diff -r 000000000000 -r e576b73a2e2f test-data/rules.tabular --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/rules.tabular Mon Jul 22 05:00:03 2019 -0400 @@ -0,0 +1,3 @@ + area eccentricity +min 500 0. +max 100000 0.5