comparison points2label.py @ 2:30ca5d5d03ec draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/points2labelimage/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
author imgteam
date Mon, 13 Nov 2023 22:11:46 +0000
parents 9bd039f46843
children de611b3b5ae8
comparison
equal deleted inserted replaced
1:9bd039f46843 2:30ca5d5d03ec
1 import argparse 1 import argparse
2 import sys 2 import sys
3 import warnings
4
3 import numpy as np 5 import numpy as np
6 import pandas as pd
4 import skimage.io 7 import skimage.io
5 import pandas as pd 8
6 import warnings
7 9
8 def points2label(labels, shape, output_file=None, has_header=False, is_TSV=True): 10 def points2label(labels, shape, output_file=None, has_header=False, is_TSV=True):
9 labelimg = np.zeros([shape[0], shape[1]], dtype=np.int32) 11 labelimg = np.zeros([shape[0], shape[1]], dtype=np.int32)
10 12
11 if is_TSV: 13 if is_TSV:
19 else: 21 else:
20 df = pd.read_csv(labels, header=None) 22 df = pd.read_csv(labels, header=None)
21 23
22 for i in range(0, len(df)): 24 for i in range(0, len(df)):
23 a_row = df.iloc[i] 25 a_row = df.iloc[i]
24 labelimg[a_row[0], a_row[1]] = i+1 26 labelimg[a_row[0], a_row[1]] = i + 1
25 27
26 if output_file is not None: 28 if output_file is not None:
27 with warnings.catch_warnings(): 29 with warnings.catch_warnings():
28 warnings.simplefilter("ignore") 30 warnings.simplefilter("ignore")
29 skimage.io.imsave(output_file, labelimg, plugin='tifffile') 31 skimage.io.imsave(output_file, labelimg, plugin='tifffile')
30 else: 32 else:
31 return labelimg 33 return labelimg
34
32 35
33 if __name__ == "__main__": 36 if __name__ == "__main__":
34 parser = argparse.ArgumentParser() 37 parser = argparse.ArgumentParser()
35 parser.add_argument('label_file', type=argparse.FileType('r'), default=sys.stdin, help='label file') 38 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') 39 parser.add_argument('out_file', type=argparse.FileType('w'), default=sys.stdin, help='out file')