comparison points2label.py @ 0:dcc8c1d6af48 draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/points2labelimage/ commit c3f4b766f03770f094fda6bda0a5882c0ebd4581
author imgteam
date Sat, 09 Feb 2019 14:44:10 -0500
parents
children 9bd039f46843
comparison
equal deleted inserted replaced
-1:000000000000 0:dcc8c1d6af48
1 import argparse
2 import sys
3 import numpy as np
4 import skimage.io
5 import pandas as pd
6 import warnings
7
8 def points2label(labels, shape, output_file=None, has_header=False, is_TSV=True):
9 labelimg = np.zeros([shape[0], shape[1]], dtype=np.int32)
10
11 if is_TSV:
12 if has_header:
13 df = pd.read_csv(labels, sep='\t', skiprows=1, header=None)
14 else:
15 df = pd.read_csv(labels, sep='\t', header=None)
16 else:
17 if has_header:
18 df = pd.read_csv(labels, skiprows=1, header=None)
19 else:
20 df = pd.read_csv(labels, header=None)
21
22 for i in range(0, len(df)):
23 a_row = df.iloc[i]
24 labelimg[a_row[0], a_row[1]] = i+1
25
26 if output_file is not None:
27 with warnings.catch_warnings():
28 warnings.simplefilter("ignore")
29 skimage.io.imsave(output_file, labelimg, plugin='tifffile')
30 else:
31 return labelimg
32
33 if __name__ == "__main__":
34 parser = argparse.ArgumentParser()
35 parser.add_argument('label_file', type=argparse.FileType('r'), default=sys.stdin, help='label file')
36 parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file')
37 parser.add_argument('org_file', type=argparse.FileType('r'), default=sys.stdin, help='input original file')
38 parser.add_argument('--has_header', dest='has_header', type=bool, default=False, help='label file has header')
39 parser.add_argument('--is_tsv', dest='is_tsv', type=bool, default=True, help='label file is TSV')
40 args = parser.parse_args()
41
42 original_shape = skimage.io.imread(args.org_file.name, plugin='tifffile').shape
43
44 points2label(args.label_file.name, original_shape, args.out_file.name, args.has_header, args.is_tsv)