SuperElastix / SimpleElastix

Multi-lingual medical image registration library
http://simpleelastix.github.io
Apache License 2.0
509 stars 149 forks source link

Write TransformParameter.txt files into a different folder from working directory #444

Closed phillipmuza closed 2 years ago

phillipmuza commented 2 years ago

After running elastix, is there a way to write the TransformParameter.txt files into a specific folder using python? It currently saves the TransformParameter.txt files into my working directory but I want to write it to a different folder without manually moving it.

I've tried these lines but with no luck:

transformParameter = elastixImageFilter.GetInitialTransformParameterFileName()
sitk.WriteParameterFile(transformParameter, "path/to/folder/transformParameter.txt")

Many thanks!

phillipmuza commented 2 years ago

I've managed to solve this issue by moving the files post-hoc running elastix. This is the code I'm using following running elastix:

import os
import glob
import shutil

#Search and retrieve files with .txt extension in source directory
## Source directory is the current working directory
source_files = "*.txt"
target_folder = elastix_folder
filelist=glob.glob(source_files)

#Move individual .txt files into the target directory
for file in filelist:
    shutil.move(file, target_folder)