Skip to content

Instantly share code, notes, and snippets.

@mattiaspaul
Created July 10, 2018 17:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattiaspaul/56a49fa792ef6f143e56699a06067712 to your computer and use it in GitHub Desktop.
Save mattiaspaul/56a49fa792ef6f143e56699a06067712 to your computer and use it in GitHub Desktop.
convert MINC landmark tag file into two txt-files readable for c3d landmark-to-spheres
import numpy as np
import argparse
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--inputtag", dest="inputtag", help="input tag file from (MINC)", default=None, required=True)
parser.add_argument("--savetxt", dest="savetxt", help="output landmark file to (txt)", default=None, required=True)
options = parser.parse_args()
d_options = vars(options)
landmarks = []
with open(d_options['inputtag']) as f:
lines=f.readlines()
for line in lines:
myarray = np.fromstring(line, dtype=float, sep=' ')
if(len(myarray)==6):
landmarks.append(myarray)
landmarks = np.asarray(landmarks)
#print(landmarks)
with open(d_options['savetxt']+"_mri.txt", "w") as text_file:
for i in range(landmarks.shape[0]):
text_file.write("%f %f %f %d \n" % (landmarks[i,0],landmarks[i,1],landmarks[i,2],i))
with open(d_options['savetxt']+"_us.txt", "w") as text_file:
for i in range(landmarks.shape[0]):
text_file.write("%f %f %f %d \n" % (landmarks[i,3],landmarks[i,4],landmarks[i,5],i))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment