# HG changeset patch # User imgteam # Date 1549741450 18000 # Node ID dcc8c1d6af484707c3473289d353e3dbf518d5f6 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/points2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581 diff -r 000000000000 -r dcc8c1d6af48 points2label.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/points2label.py Sat Feb 09 14:44:10 2019 -0500 @@ -0,0 +1,44 @@ +import argparse +import sys +import numpy as np +import skimage.io +import pandas as pd +import warnings + +def points2label(labels, shape, output_file=None, has_header=False, is_TSV=True): + labelimg = np.zeros([shape[0], shape[1]], dtype=np.int32) + + if is_TSV: + if has_header: + df = pd.read_csv(labels, sep='\t', skiprows=1, header=None) + else: + df = pd.read_csv(labels, sep='\t', header=None) + else: + if has_header: + df = pd.read_csv(labels, skiprows=1, header=None) + else: + df = pd.read_csv(labels, header=None) + + for i in range(0, len(df)): + a_row = df.iloc[i] + labelimg[a_row[0], a_row[1]] = i+1 + + if output_file is not None: + with warnings.catch_warnings(): + warnings.simplefilter("ignore") + skimage.io.imsave(output_file, labelimg, plugin='tifffile') + else: + return labelimg + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument('label_file', type=argparse.FileType('r'), default=sys.stdin, help='label file') + parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file') + parser.add_argument('org_file', type=argparse.FileType('r'), default=sys.stdin, help='input original file') + parser.add_argument('--has_header', dest='has_header', type=bool, default=False, help='label file has header') + parser.add_argument('--is_tsv', dest='is_tsv', type=bool, default=True, help='label file is TSV') + args = parser.parse_args() + + original_shape = skimage.io.imread(args.org_file.name, plugin='tifffile').shape + + points2label(args.label_file.name, original_shape, args.out_file.name, args.has_header, args.is_tsv) diff -r 000000000000 -r dcc8c1d6af48 points2label.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/points2label.xml Sat Feb 09 14:44:10 2019 -0500 @@ -0,0 +1,36 @@ + + Points to Label Image + + numpy + scikit-image + pandas + + + + + + + + + + + + + + + + + + + + + **What it does** + + This tool converts points to a label image. + + + 10.1016/j.jbiotec.2017.07.019 + + diff -r 000000000000 -r dcc8c1d6af48 test-data/galaxyIcon_noText.tif Binary file test-data/galaxyIcon_noText.tif has changed diff -r 000000000000 -r dcc8c1d6af48 test-data/out.tif Binary file test-data/out.tif has changed diff -r 000000000000 -r dcc8c1d6af48 test-data/points.tsv --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/points.tsv Sat Feb 09 14:44:10 2019 -0500 @@ -0,0 +1,7 @@ +5 3 +10 2 +8 4 +15 15 +8 5 +8 6 +8 7