Using isct_ functions

For me it prints File0 and the help and that’s it. So no File1 to File3 and help again. That is really mysterious.

About the path: on my laptop the path is defined in my environment variable but if I work on our servers that is somehow different. I don’t remember exactely because it has been a while but I think that was not possible and I had to come up with that solution. Or at least that was suggested by our IT person. I can ask again…

That loop quits early because the script has set -e set, and passing no arguments is considered an error (isct_antsRegistration is returning 1, not 0)

The first version of the code

is missing \s at the end of each line, so each line appears to be a separate command; and because of set -e that first isct_antsRegistration terminates the whole process.

In the full script, you have

	isct_antsRegistration 
	#~ \
        #~ --dimensionality 3 \
        #~ --float 0 \
        #~ --metric 'MeanSquares[fmri_moco_norm_T0000.nii,fmri_moco_norm_T`printf %04d ${files}`.nii,1,32,Regular,0.2]' \
        #~ --output '[X_${files}_,X_${files}_Warped.nii.gz]' \
        #~ --interpolation 'BSpline' \
        #~ --winsorize-image-intensities '[0.005,0.995]' \
        #~ --use-histogram-matching 0 \
        #~ --transform 'Rigid[1]' \
        #~ --shrink-factors 1 \
        #~ --smoothing-sigmas 0 \
        #~ -x mask_fmri_65mm.nii

so I can tell you tackled that, but there’s an small but crucial oversight: the missing \ on the first line.

So is this what you actually want?

	isct_antsRegistration \
        --dimensionality 3 \
        --float 0 \
        --metric 'MeanSquares[fmri_moco_norm_T0000.nii,fmri_moco_norm_T`printf %04d ${files}`.nii,1,32,Regular,0.2]' \
        --output '[X_${files}_,X_${files}_Warped.nii.gz]' \
        --interpolation 'BSpline' \
        --winsorize-image-intensities '[0.005,0.995]' \
        --use-histogram-matching 0 \
        --transform 'Rigid[1]' \
        --shrink-factors 1 \
        --smoothing-sigmas 0 \
        -x mask_fmri_65mm.nii

Thanks for giving SCT a shakedown cruise. Let us know how it goes.

If it helps you out in the future, I always start my bash scripts with

set -e -o pipefail
#set -x

-o pipefail means that a pipeline (e.g. cat something | grep something_else | sort) will fail if any of the pieces fail; without it the failure code is just taken from the right-most piece.

set -x traces my code; I uncomment that line when debugging to see the exact bash commands being run.

Thank you very much for your detailed response! With the set -e that makes a lot of sense to me now and if I comment that line Julien’s test code does what I thought it should do.

Now the but… I tried your code with all the \ s (weird that my first posted code and my script differ in that sense because I thought I copied the same code but well apparently I didn’t) and with set -e commented, it runs through all the loops and echos what it should echo without executing antsRegistration but if I uncomment that line the script breaks in the first loop interation without any error message. I assume that some of the arguments are wrong?? Or the files are not found? But shouldn’t I get an error message in that case?

Try adding ; echo "RESULT = $?" after the isct_antsRegistration call. That will show you the return code. If its not 0, it’s an error. I would also turn on set -x so you can see exactly what line is dying.

These are C programs so they don’t have as much obvious error handling as python or bash programs. It’s possible your combination of data is hitting some weird corner case that is killing them without being caught.

I’ve made the edits here:
test_isct.sh (1012 Bytes)

We’re debugging somewhat blindly over here since we don’t have your dataset and your script is tuned to your particular folders. But if you could start a fresh terminal, run that, and copy the entire backlog in to here that would help. You can use the Code quote button like this to make it clear to us:

This is some sample code, written using triple backticks: ``` ... ```

That is the output I get:

+ PATH=/home/tinnermann/sct/bin:/home/tinnermann/bin:/home/tinnermann/bin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/local/bin
+ basedir=/projects/crunchie/remi3/
+ export TMPDIR=/projects/crunchie/remi3/tmp
+ TMPDIR=/projects/crunchie/remi3/tmp
+ listofSubs=(4)
+ for subject in ${listofSubs[@]}
++ printf %02d 4
+ subdir=/projects/crunchie/remi3/Sub04_test
+ echo Sub4
Sub4
+ for run in {1..8}
+ rundir=/projects/crunchie/remi3/Sub04_test/Run1/sct/
+ echo Run1
Run1
+ cd /projects/crunchie/remi3/Sub04_test/Run1/sct/
+ for files in {0..152}
+ echo File0
File0
+ isct_antsRegistration --dimensionality 3 --float 0 --metric 'MeanSquares[fmri_moco_norm_T0000.nii,fmri_moco_norm_T`printf %04d ${files}`.nii,1,32,Regular,0.2]' --output '[X_${files}_,X_${files}_Warped.nii.gz]' --interpolation BSpline --winsorize-image-intensities '[0.005,0.995]' --use-histogram-matching 0 --transform 'Rigid[1]' --shrink-factors 1 --smoothing-sigmas 0 -x mask_fmri_65mm.nii

That is about what I’m seeing too. I assumed the reason it stops is that I don’t have the data, but maybe it doesn’t like the arguments.

cd /projects/crunchie/remi3/Sub04_test/Run1/sct/
files=0

Then experiment with changing

isct_antsRegistration --dimensionality 3 --float 0 --metric 'MeanSquares[fmri_moco_norm_T0000.nii,fmri_moco_norm_T`printf %04d ${files}`.nii,1,32,Regular,0.2]' --output '[X_${files}_,X_${files}_Warped.nii.gz]' --interpolation BSpline --winsorize-image-intensities '[0.005,0.995]' --use-histogram-matching 0 --transform 'Rigid[1]' --shrink-factors 1 --smoothing-sigmas 0 -x mask_fmri_65mm.nii

until you discover what is wrong.

What is -x mask_fmri_65mm.nii about? Possibly the cd made that filename is invalid. I’ll try to experiment with my copy as best I can.

Oh I see one problem: there are single quotes where you want double quotes. You have to write

isct_antsRegistration \
  --dimensionality 3 \
  --float 0 \
  --metric "MeanSquares[fmri_moco_norm_T0000.nii,fmri_moco_norm_T`printf %04d ${files}`.nii,1,32,Regular,0.2]" \
  --output "[X_${files}_,X_${files}_Warped.nii.gz]" \
  --interpolation BSpline \
  --winsorize-image-intensities '[0.005,0.995]' \
  --use-histogram-matching 0 \
  --transform 'Rigid[1]' \
  --shrink-factors 1 \
  --smoothing-sigmas 0 \
  -x mask_fmri_65mm.nii

for the string interpolations (the $s and the backticks) to work. Single quotes mean a literal string in shell.

You can also use the fact that strings run together like egg yolk and instead write:

isct_antsRegistration \
  --dimensionality 3 \
  --float 0 \
  --metric 'MeanSquares[fmri_moco_norm_T0000.nii,fmri_moco_norm_T'`printf %04d ${files}`'.nii,1,32,Regular,0.2]' \
  --output '[X_'${files}'_,X_'${files}'_Warped.nii.gz]' \
  --interpolation BSpline \
  --winsorize-image-intensities '[0.005,0.995]' \
  --use-histogram-matching 0 \
  --transform 'Rigid[1]' \
  --shrink-factors 1 \
  --smoothing-sigmas 0 \
  -x mask_fmri_65mm.nii

which is a little bit more reliable because it avoids potentially deeply nesting quotes.

In addition, shell is a fragile language, so I would add a layer of quoting around the interpolations to prevent accidental whitespace (or worse, shell code) in their values from getting interpreted, and prefer $(..) to `` because it’s more readable:

isct_antsRegistration \
  --dimensionality 3 \
  --float 0 \
  --metric 'MeanSquares[fmri_moco_norm_T0000.nii,fmri_moco_norm_T'"$(printf %04d "${files}")"`'.nii,1,32,Regular,0.2]' \
  --output '[X_'"${files}"'_,X_'"${files}"'_Warped.nii.gz]' \
  --interpolation BSpline \
  --winsorize-image-intensities '[0.005,0.995]' \
  --use-histogram-matching 0 \
  --transform 'Rigid[1]' \
  --shrink-factors 1 \
  --smoothing-sigmas 0 \
  -x mask_fmri_65mm.nii

Finally, fmri_moco_norm_T0000.nii sounds like a filename, just like mask_fmri_65mm.nii, so check that both of those exist in the folder the program is running from. It’s likely that the cd makes that untrue.

It’s often easier to build up pathnames than to try to cd to the right places. So, change

-  --output '[X_'"${files}"'_,X_'"${files}"'_Warped.nii.gz]' \
+  --output '['"${subdir}/"'X_'"${files}"'_,'"${subdir}/"'X_'"${files}"'_Warped.nii.gz]' \

and remove the cd.

Hi, to better test the function, I copied one single file to my home directory which is also my working directory :

tinnermann@isn0068ebea3a78:~$ pwd 
/home/tinnermann
tinnermann@isn0068ebea3a78:~$ ls
fmri_moco_mean.nii  scripts  sct

Then I tried to register this image to itself which of course doesn’t make sense but for testing purposes I thought it is ok and I eliminated argument by argument to end up with these two calls:

isct_antsRegistration --metric "MeanSquares[fmri_moco_mean.nii,fmri_moco_mean.nii]"

isct_antsRegistration --float 0

None of that gave any error message or any output at all. So I misspelled the filename:

 isct_antsRegistration --metric "MeanSquares[fmri_moco_mean.nii,fmri_moco_meann.nii]"

Also no error message.

To clarify some arguments: the mask is of course optional and in previous testings I already deleted that argument but it didn’t change anything. The script I provided is a script that I used for my sct preprocessing. So this paticular script was used to smooth my epi images. Instead of the sct funtion within the loop that loops over all files, I replaced it by the isct function but kept the file names (again, doesn’t make sense here but it was just for testing purposes).

I checked into isct_antsRegistration -h and noticed there’s a --verbose option. If I run what you ran I also get nothing:

$ isct_antsRegistration --metric "MeanSquares[fmri_moco_mean.nii,fmri_moco_mean.nii]"

there is this hidden output in the return code:

$ isct_antsRegistration --metric "MeanSquares[fmri_moco_mean.nii,fmri_moco_mean.nii]"; echo $?
1

However if I add --verbose I see the error:

$ isct_antsRegistration --verbose --metric "MeanSquares[fmri_moco_mean.nii,fmri_moco_mean.nii]"; echo $?
All_Command_lines_OK
Image dimensionality not specified.  See command line option --dimensionality
1

If I try running your original command with this I see the immediate problem:

$   isct_antsRegistration \
>         --verbose \
>         --dimensionality 3 \
>         --float 0 \
>         --metric 'MeanSquares[fmri_moco_norm_T0000.nii,fmri_moco_norm_T`printf %04d ${files}`.nii,1,32,Regular,0.2]' \
>         --output '[X_${files}_,X_${files}_Warped.nii.gz]' \
>         --interpolation 'BSpline' \
>         --winsorize-image-intensities '[0.005,0.995]' \
>         --use-histogram-matching 0 \
>         --transform 'Rigid[1]' \
>         --shrink-factors 1 \
>         --smoothing-sigmas 0 \
>         -x mask_fmri_65mm.nii
All_Command_lines_OK
Using double precision for computations.
ERROR: the convergence option ('-c') must be specified.  See help menu.

Ahhh, thank you very much! That should solve all problems at least in the sense that I know what is wrong with my code!

If I add that argument with some value it gets further but there’s more problems, because it doesn’t have access to the right files:

$ files=0
$ isct_antsRegistration \
>         --verbose \
>         --dimensionality 3 \
>         --float 0 \
>         --metric 'MeanSquares[fmri_moco_norm_T0000.nii,fmri_moco_norm_T`printf %04d ${files}`.nii,1,32,Regular,0.2]' \
>         --output '[X_${files}_,X_${files}_Warped.nii.gz]' \
>         --interpolation 'BSpline' \
>         --winsorize-image-intensities '[0.005,0.995]' \
>         --use-histogram-matching 0 \
>         --transform 'Rigid[1]' \
>         --shrink-factors 1 \
>         --smoothing-sigmas 0 \
>         -c 10 \
>         -x mask_fmri_65mm.nii
All_Command_lines_OK
Using double precision for computations.
  Reading mask(s).
    Registration stage 0
 file mask_fmri_65mm.nii does not exist . 
      No fixed mask
  number of levels = 1
  fixed image: fmri_moco_norm_T0000.nii
  moving image: fmri_moco_norm_T`printf %04d ${files}`.nii
 file fmri_moco_norm_T0000.nii does not exist . 
 file fmri_moco_norm_T`printf %04d ${files}`.nii does not exist . 
Segmentation fault (core dumped)

This particular error is demonstrating Using isct_ functions because it’s complaining about a file with “%04d” in the filename. We can fix that first:

$   files=0
(venv_sct) [kousu@requiem spinalcordtoolbox]$   isct_antsRegistration \
>         --verbose \
>         --dimensionality 3 \
>         --float 0 \
>         --metric 'MeanSquares[fmri_moco_norm_T0000.nii,fmri_moco_norm_T'$(printf %04d ${files})'.nii,1,32,Regular,0.2]' \
>         --output '[X_'${files}'_,X_'${files}'_Warped.nii.gz]' \
>         --interpolation 'BSpline' \
>         --winsorize-image-intensities '[0.005,0.995]' \
>         --use-histogram-matching 0 \
>         --transform 'Rigid[1]' \
>         --shrink-factors 1 \
>         --smoothing-sigmas 0 \
>         -c 10 \
>         -x mask_fmri_65mm.nii
All_Command_lines_OK
Using double precision for computations.
  Reading mask(s).
    Registration stage 0
 file mask_fmri_65mm.nii does not exist . 
      No fixed mask
  number of levels = 1
  fixed image: fmri_moco_norm_T0000.nii
  moving image: fmri_moco_norm_T0000.nii
 file fmri_moco_norm_T0000.nii does not exist . 
 file fmri_moco_norm_T0000.nii does not exist . 
Segmentation fault (core dumped)

Now I need to find some real files to test with. When I ran ./install_sct I ended up with sct_testing_data/ with a bunch of sample files.
I’ll pick some files out to try to analyse. I don’t know if these files make any sense for the task but they should be enough to get the program to run.
I’ll also do this in a fresh working directory to avoid confusion.

$ mkdir issue346
$ cd issue346/
$ cp ../sct_testing_data/fmri/fmri_r_T0000.nii.gz .
$ ls -l
total 48
-rw-r--r-- 1 kousu kousu 17410 Mar 23 11:32 fmri_r_T0000.nii.gz
$ sha256sum *.nii.gz  # just in case you want to verify this work precisely
53693deeecd15ceab11b210c9de10516a186291a18bc3da3cbfa37b2b16bfbff  fmri_r_T0000.nii.gz

Now let’s try that command again:


$ files=0
$ isct_antsRegistration \
>         --verbose \
>         --dimensionality 3 \
>         --float 0 \
>         --metric 'MeanSquares[fmri_r_T0000.nii.gz,fmri_r_T0000.nii.gz,1,32,Regular,0.2]' \
>         --output '[output_issue346,output_issue346_Warped.nii.gz]' \
>         --interpolation 'BSpline' \
>         --winsorize-image-intensities '[0.005,0.995]' \
>         --use-histogram-matching 0 \
>         --transform 'Rigid[1]' \
>         --shrink-factors 1 \
>         --smoothing-sigmas 0 \
>         -c 10 \
>         -x mask_fmri_65mm.nii
All_Command_lines_OK
Using double precision for computations.
  Reading mask(s).
    Registration stage 0
 file mask_fmri_65mm.nii does not exist . 
      No fixed mask
  number of levels = 1
  fixed image: fmri_r_T0000.nii.gz
  moving image: fmri_r_T0000.nii.gz
Dimension = 3
Number of stages = 1
Use Histogram Matching false
Winsorize image intensities true
Lower quantile = 0.005
Upper quantile = 0.995
Stage 1 State
   Image metric = MeanSquares
     Fixed image = Image (0x4f4cbd0)
  RTTI typeinfo:   itk::Image<double, 3u>
  Reference Count: 2
  Modified Time: 644
  Debug: Off
  Object Name: 
  Observers: 
    none
  Source: (none)
  Source output name: (none)
  Release Data: Off
  Data Released: False
  Global Release Data: Off
  PipelineMTime: 0
  UpdateMTime: 466
  RealTimeStamp: 0 seconds 
  LargestPossibleRegion: 
    Dimension: 3
    Index: [0, 0, 0]
    Size: [34, 34, 6]
  BufferedRegion: 
    Dimension: 3
    Index: [0, 0, 0]
    Size: [34, 34, 6]
  RequestedRegion: 
    Dimension: 3
    Index: [0, 0, 0]
    Size: [34, 34, 6]
  Spacing: [1.91176, 1.91176, 16.8]
  Origin: [-29.9549, 34.5494, -23.8665]
  Direction: 
0.999561 8.49015e-08 0.0296327
0.00222132 -0.997187 -0.0749259
-0.0295494 -0.0749588 0.996749

  IndexToPointMatrix: 
1.91093 1.62312e-07 0.49783
0.00424664 -1.90639 -1.25876
-0.0564915 -0.143304 16.7454

  PointToIndexMatrix: 
0.522847 0.00116192 -0.0154566
4.44724e-08 -0.521605 -0.0392092
0.00176385 -0.00445988 0.0593303

  Inverse Direction: 
0.999561 0.00222132 -0.0295494
8.50207e-08 -0.997187 -0.0749588
0.0296327 -0.0749259 0.996749

  PixelContainer: 
    ImportImageContainer (0x4f42c10)
      RTTI typeinfo:   itk::ImportImageContainer<unsigned long, double>
      Reference Count: 1
      Modified Time: 463
      Debug: Off
      Object Name: 
      Observers: 
        none
      Pointer: 0x4f55230
      Container manages memory: true
      Size: 6936
      Capacity: 6936

     Moving image = Image (0x4f50be0)
  RTTI typeinfo:   itk::Image<double, 3u>
  Reference Count: 2
  Modified Time: 645
  Debug: Off
  Object Name: 
  Observers: 
    none
  Source: (none)
  Source output name: (none)
  Release Data: Off
  Data Released: False
  Global Release Data: Off
  PipelineMTime: 0
  UpdateMTime: 642
  RealTimeStamp: 0 seconds 
  LargestPossibleRegion: 
    Dimension: 3
    Index: [0, 0, 0]
    Size: [34, 34, 6]
  BufferedRegion: 
    Dimension: 3
    Index: [0, 0, 0]
    Size: [34, 34, 6]
  RequestedRegion: 
    Dimension: 3
    Index: [0, 0, 0]
    Size: [34, 34, 6]
  Spacing: [1.91176, 1.91176, 16.8]
  Origin: [-29.9549, 34.5494, -23.8665]
  Direction: 
0.999561 8.49015e-08 0.0296327
0.00222132 -0.997187 -0.0749259
-0.0295494 -0.0749588 0.996749

  IndexToPointMatrix: 
1.91093 1.62312e-07 0.49783
0.00424664 -1.90639 -1.25876
-0.0564915 -0.143304 16.7454

  PointToIndexMatrix: 
0.522847 0.00116192 -0.0154566
4.44724e-08 -0.521605 -0.0392092
0.00176385 -0.00445988 0.0593303

  Inverse Direction: 
0.999561 0.00222132 -0.0295494
8.50207e-08 -0.997187 -0.0749588
0.0296327 -0.0749259 0.996749

  PixelContainer: 
    ImportImageContainer (0x4f3ecd0)
      RTTI typeinfo:   itk::ImportImageContainer<unsigned long, double>
      Reference Count: 1
      Modified Time: 639
      Debug: Off
      Object Name: 
      Observers: 
        none
      Pointer: 0x4f65d00
      Container manages memory: true
      Size: 6936
      Capacity: 6936

     Weighting = 1
     Sampling strategy = regular
     Number of bins = 32
     Radius = 4
     Sampling percentage  = 0.2
   Transform = Rigid
     Gradient step = 1
     Update field sigma (voxel space) = 0
     Total field sigma (voxel space) = 0
     Update field time sigma = 0
     Total field time sigma  = 0
     Number of time indices = 0
     Number of time point samples = 0
Registration using 1 total stages.

Stage 0
  iterations = 10
  convergence threshold = 1e-06
  convergence window size = 10
  number of levels = 1
  using the MeanSquares metric (weight = 1)
  preprocessing:  winsorizing the image intensities
  Shrink factors (level 1 out of 1): [1, 1, 1]
  smoothing sigmas per level: [0]
  regular sampling (percentage = 0.2)

*** Running Euler3DTransform registration ***

DIAGNOSTIC,Iteration,metricValue,convergenceValue,ITERATION_TIME_INDEX,SINCE_LAST
 2DIAGNOSTIC,     1, 0.000000000000e+00, 1.797693134862e+308, 6.6512e-03, 6.6512e-03, 
 2DIAGNOSTIC,     2, 0.000000000000e+00, 1.797693134862e+308, 8.3532e-03, 1.7021e-03, 
 2DIAGNOSTIC,     3, 0.000000000000e+00, 1.797693134862e+308, 1.0092e-02, 1.7390e-03, 
 2DIAGNOSTIC,     4, 0.000000000000e+00, 1.797693134862e+308, 1.1875e-02, 1.7829e-03, 
 2DIAGNOSTIC,     5, 0.000000000000e+00, 1.797693134862e+308, 1.3513e-02, 1.6379e-03, 
 2DIAGNOSTIC,     6, 0.000000000000e+00, 1.797693134862e+308, 1.5179e-02, 1.6661e-03, 
 2DIAGNOSTIC,     7, 0.000000000000e+00, 1.797693134862e+308, 1.6851e-02, 1.6720e-03, 
 2DIAGNOSTIC,     8, 0.000000000000e+00, 1.797693134862e+308, 1.8378e-02, 1.5271e-03, 
 2DIAGNOSTIC,     9, 0.000000000000e+00, 1.797693134862e+308, 1.9923e-02, 1.5450e-03, 
  Elapsed time (stage 0): 2.2582e-02


Total elapsed time: 2.3342e-02

This produced two new files:

$ ls -l
total 80
-rw-r--r-- 1 kousu kousu 17410 Mar 23 11:32 fmri_r_T0000.nii.gz
-rw-r--r-- 1 kousu kousu   193 Mar 23 11:35 output_issue3460GenericAffine.mat
-rw-r--r-- 1 kousu kousu 27998 Mar 23 11:35 output_issue346_Warped.nii.gz

It seems to have ignored the mask, like you suggested.

Right now I am thinking the lessons here are:

  1. Several of the errors cases are currently hidden by verbose = 0, and that’s a mistake on our end
  2. The -x mask option is non-mandatory, which is confusing.
  3. It’s important to pay attention to single vs double quotes and your working directory when in shell, and to double check each subpiece of a command or a script, which you can do with set -x and by using echo ....

Let me know if that solves your problem and if I can help any more, and thanks for using SCT :slight_smile:

Just to let you know, with the following code it still breaks with an error message but that seems to be an ANTs problem and is not related to SCT and I thought I still share it because syntax-wise it seems to be fine right now:

isct_antsRegistration \
	--verbose \
        --dimensionality 3 \
        --float 0 \
        --metric "MeanSquares[fmri_moco_norm_T0000.nii,fmri_moco_norm_T`printf %04d ${files}`.nii,1,32,Regular,0.2]" \
        --output "[X_,Warped.nii.gz]" \
        --interpolation "BSpline" \
        --winsorize-image-intensities "[0.005,0.995]" \
        --use-histogram-matching 0 \
        --transform "Rigid[1]" \
        --smoothing-sigmas "[0]" \
	--shrink-factors "[1]" \
	--convergence "[1.e-8]" \ 
	echo "RESULT = $?"

The error message says “Segmentation fault” and in the ANTs helpline a similar error was discussed in relation to image size which shouldn’t be any problem with spinal data. I will play around with parameters to see if that they are problematic.

Thanks a lot for your help!

Hey Alexandra,

I get a different error with that command than you:

$ isct_antsRegistration \
> --verbose \
>         --dimensionality 3 \
>         --float 0 \
>         --metric "MeanSquares[fmri_moco_norm_T0000.nii,fmri_moco_norm_T`printf %04d ${files}`.nii,1,32,Regular,0.2]" \
>         --output "[X_,Warped.nii.gz]" \
>         --interpolation "BSpline" \
>         --winsorize-image-intensities "[0.005,0.995]" \
>         --use-histogram-matching 0 \
>         --transform "Rigid[1]" \
>         --smoothing-sigmas "[0]" \
> --shrink-factors "[1]" \
> --convergence "[1.e-8]" \
> echo "RESULT = $?"
All_Command_lines_OK
Using double precision for computations.
Exception Object caught: 

itk::ExceptionObject (0x3e71670)
Location: "unknown" 
File: /home/brain/ANTs/Utilities/antsCommandLineParser.h
Line: 126
Description: itk::ERROR: CommandLineParser(0x3e52960): ERROR: Parse error occured during command line argument processing
ERROR: Unable to convert 'RESULT = 0' to type 'j' as unsigned int

You need a ; or a newline on that second-last line, not a \ because \ means continue the current command but echo .. is a separate command.

If I fix that I get

$ isct_antsRegistration \
> --verbose \
>         --dimensionality 3 \
>         --float 0 \
>         --metric "MeanSquares[fmri_moco_norm_T0000.nii,fmri_moco_norm_T`printf %04d ${files}`.nii,1,32,Regular,0.2]" \
>         --output "[X_,Warped.nii.gz]" \
>         --interpolation "BSpline" \
>         --winsorize-image-intensities "[0.005,0.995]" \
>         --use-histogram-matching 0 \
>         --transform "Rigid[1]" \
>         --smoothing-sigmas "[0]" \
> --shrink-factors "[1]" \
> --convergence "[1.e-8]"
All_Command_lines_OK
Using double precision for computations.
Exception Object caught: 

itk::ExceptionObject (0x48eff20)
Location: "unknown" 
File: /home/brain/ANTs/Utilities/antsCommandLineParser.h
Line: 126
Description: itk::ERROR: CommandLineParser(0x48d1870): ERROR: Parse error occured during command line argument processing
ERROR: Unable to convert '1.e-8' to type 'j' as unsigned int



$ echo "RESULT = $?"
RESULT = 1

The help for -c says

$ isct_antsRegistration -h
...
     -c, --convergence MxNxO
                       [MxNxO,<convergenceThreshold=1e-6>,<convergenceWindowSize=10>]
...

so you need to give two arguments if you want to set a threshold. For example, I got this to run for me, using the sample file from before:

isct_antsRegistration \
	--verbose \
        --dimensionality 3 \
        --float 0 \
        --metric "MeanSquares[fmri_r_T0000.nii.gz,fmri_r_T0000.nii.gz,1,32,Regular,0.2]" \
        --output "[X_,Warped.nii.gz]" \
        --interpolation "BSpline" \
        --winsorize-image-intensities "[0.005,0.995]" \
        --use-histogram-matching 0 \
        --transform "Rigid[1]" \
        --smoothing-sigmas "[0]" \
	--shrink-factors "[1]" \
	--convergence "[30x40x9,1.e-8]";
	echo "RESULT = $?"

By the way I have noticed that this program will segfault for lots of reasons: for not being able to find a file, for misparsing some arguments, etc. Sometimes there’s a clean error message and sometimes it’s the environment.

Also, the -c arguments seem to be, in order, iterations, convergence, and window size, for example I saw in the --verbose output:

  iterations = 30x40x9
  convergence threshold = 1e-08
  convergence window size = 10

I used Ants once in python and there arguments are a little easier to understand because as in your example it would be three seperate arguments and not several ones in one. So thanks for pointing that out. If you say 30x40x9, several other arguments such as smoothing sigmas also need three numbers. This code finally runs:

isct_antsRegistration \
	--verbose \
        --dimensionality 3 \
        --float 0 \
        --metric "MeanSquares[fmri_moco_norm_T0000.nii,fmri_moco_norm_T`printf %04d ${files}`.nii,1,32,Regular,0.2]" \
        --output "[X_,Warped.nii.gz]" \
        --interpolation "BSpline" \
        --winsorize-image-intensities "[0.005,0.995]" \
        --use-histogram-matching 0 \
        --transform "Rigid[1]" \
        --smoothing-sigmas 0 \
	--shrink-factors 1 \
	--convergence "[10,1.e-8]"
1 Like