elastix icon indicating copy to clipboard operation
elastix copied to clipboard

Feature request: specify output name for file in transformix/elastix

Open Svdvoort opened this issue 2 years ago • 1 comments

Currently, when running elastix/transformix it is only possible to specify the output directory, and not specifically the output name. For example, from elastix the output files will always be named TransformParameters.0.txt and from transformix result.nii.gz.

Especially for transformix it would be nice to be able to specify the output file name. I often have the situation where I need to apply the same transformation to multiple images (for example different MR modalities). In this case, I either have to create a new directory per image just to save the transformed image or have to write a wrapper around transformix to rename the output file before a new run.

Could a flag be added to elastix/transformix to specify the output filename directly?

For example:

transformix -tp TransformParameters.0.txt -out /home/user/ -filename T1 original_scan.nii.gz

If the filename flag is not provided, elastix/transformix can use the current default behavior (in this case, writing the file as result.nii.gz), not breaking any existing functionality.

Svdvoort avatar Jun 27 '22 08:06 Svdvoort

Interesting suggestion, thanks!

Note that in Python you can already achieve this, when using ITKElastix https://github.com/InsightSoftwareConsortium/ITKElastix

N-Dekker avatar Jul 04 '22 11:07 N-Dekker

As far as I can see, the default is "output-directory/result.mhd", looking at:

https://github.com/SuperElastix/elastix/blob/0a1e90f6222c3bb7ba4891dc8bfc6c8774a1fc7c/Core/Kernel/elxElastixTemplate.hxx#L385-L389

I guess the proposal is to allow specifying a path relative to the output directory, right? Or would it be relative to the current working directory?

Of course, it should then also allow specifying an absolute path, either starting with a (back) slash, or a drive letter, followed by colon and (back) slash. Right?

But then, would it entirely ignore the "ResultImageFormat" parameter from the parameter file?

If the directory of the specified file path would be non-existing, would it be OK for transformix to just fail? Or should it try to create the directory?

N-Dekker avatar Dec 16 '22 18:12 N-Dekker

In my opinion it can be much simpler than this. Although specifying additional paths would be nice, in principle I think it's fine to store everything just in the output directory. However, the file will always be called result. <ResultImageFormat>, and it would be nice to change the "result" part since the image format can already be changed. It could be a flag, but also just a parameter in the parameter file, just like the ResultImageFormat is.

That way instead of always saving a file as result.<ResultImageFormat> it can be something like <ResultImageName>.<ResultImageFormat>

This allows for a bit more flexibility and clarity when saving transformed images.

Svdvoort avatar Dec 19 '22 09:12 Svdvoort

@Svdvoort Can you please check if the "ResultImageName" parameter implemented with pull request #776 commit b581b9242157cabc3e029bd9eeeef987479ed195 works the way you had in mind?

N-Dekker avatar Dec 22 '22 20:12 N-Dekker