Last active
December 17, 2015 11:49
-
-
Save nat-n/5605121 to your computer and use it in GitHub Desktop.
Takes a *stamp* volume file (such as a single label image of an oil capsule on the left side of the temple) and adds it to each image in the input directory and writes the resulting images to the output directory. The stamp file must match the dimensions of all the image files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# created on 18/5/13 by Nat Noordanus [email protected] | |
import os, argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument("input_dir") | |
parser.add_argument("stamp_file") | |
parser.add_argument("output_dir") | |
args = parser.parse_args() | |
input_dir = args.input_dir | |
stamp_file = args.stamp_file | |
output_dir = args.output_dir | |
while input_dir[-1] == "/": | |
input_dir = input_dir[0:-1] | |
while stamp_file[-1] == "/": | |
stamp_file = stamp_file[0:-1] | |
while output_dir[-1] == "/": | |
output_dir = output_dir[0:-1] | |
# to convert nrrd file from seg3d to nifit run `c3d <inputfile.nrrd> -o <outputfile.nii>` | |
valid_extensions = [".nii", ".nii.gz", ".nrrd"] | |
input_images = [item for item in os.listdir(input_dir) if any(item.endswith(ext) for ext in valid_extensions)] | |
for input_file in input_images: | |
input_file_path = input_dir+'/'+input_file | |
output_file_path = output_dir+'/'+input_file.split('.')[0] + '.nii' | |
# use option like -flip x if neccessary | |
command = 'c3d ' + stamp_file +' -scale 250 '+ input_file_path + ' -add -o ' + output_file_path | |
os.system(command) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment