-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathreplace_labels_img.py
More file actions
34 lines (23 loc) · 1019 Bytes
/
replace_labels_img.py
File metadata and controls
34 lines (23 loc) · 1019 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import nrrd
import pandas as pd
import numpy as np
def apply_label_mapping(img, df, args):
# Read the nrrd file
# Convert the DataFrame to a dictionary for faster access
labels = np.array(df[args.target].values)
return labels[img]
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--img', type=str, help='Path to the nrrd file')
parser.add_argument('--csv', type=str, help='CSV files with columns label and label_10')
parser.add_argument('--target', type=str, help='label target column', default='label_11')
parser.add_argument('--out', type=str, help='Path to the output file')
args = parser.parse_args()
df = pd.read_csv(args.csv)
img, header = nrrd.read(args.img)
out_img = apply_label_mapping(img, df, args)
print("Writing: ", args.out)
nrrd.write(args.out, out_img, header)
# Save the modified image
# nrrd.write(args.out, out_img, header)