From e14cc15eebb89916fc889de61a88b4314d57339f Mon Sep 17 00:00:00 2001 From: Matthijs van Eede Date: Fri, 6 Jan 2017 17:47:57 -0500 Subject: [PATCH] script to generate an xfm file for some input vector field --- perl/make_xfm_for_grid.pl | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 perl/make_xfm_for_grid.pl diff --git a/perl/make_xfm_for_grid.pl b/perl/make_xfm_for_grid.pl new file mode 100755 index 0000000..d777d55 --- /dev/null +++ b/perl/make_xfm_for_grid.pl @@ -0,0 +1,47 @@ +#!/usr/bin/perl + +# generates an xfm file for a provided grid file + +use strict; +use warnings; + +use File::Spec; +use MNI::Startup; +use Getopt::Tabular; +use MNI::Spawn; +use MNI::FileUtilities qw(test_file check_output_dirs); + +my $usage = " + +$0 [options] deformation_grid.mnc output_xfm_for_grid.xfm\n"; + + +# handle arguments +my @left_over_args; +my @arg_table = + ( @DefaultArgs, + ); + +GetOptions(\@arg_table, \@ARGV, \@left_over_args) or die "\n"; + + +my $deformation_grid = shift @left_over_args or die $usage; +my $output_xfm = shift @left_over_args or die $usage; + +if(-f $output_xfm and not $Clobber) { + die "Error: output xfm file already exists and -clobber not specified: $output_xfm.\n"; +} + +if(not -f $deformation_grid){ + die "Error: deformation grid does not exist: $deformation_grid.\n"; +} + +# save the realpath to the grid, otherwise it won't necessarily work +my $deformation_grid_abs_path = File::Spec->rel2abs( $deformation_grid ); + +# write to the output +open(OUTPUT, "> $output_xfm"); +print OUTPUT "MNI Transform File\n"; +print OUTPUT "% created by $0 with grid $deformation_grid\n"; +print OUTPUT "Transform_Type = Grid_Transform;\n"; +print OUTPUT "Displacement_Volume = $deformation_grid_abs_path;\n";