raacampbell / matlab_elastix

MATLAB Elastix wrapper
http://www.mathworks.com/matlabcentral/fileexchange/52982-matlab-elastix
GNU Lesser General Public License v3.0
26 stars 12 forks source link

Output argument 'im' not assigned error with examples #23

Closed justbennet closed 4 years ago

justbennet commented 4 years ago

I am getting an error when I run the example_2D_affine_alpha and other examples.

Starting registration
Transform: AffineTransform
MaximumNumberOfIterations: 400
NumberOfSpatialSamples: 300
SP_alpha: 2.000000e-01
Writing parameter file to /tmp/elastixTMP_200707111201_81472369/elastixTMP_200707111201_81472369_parameters_1.txt
Running: elastix -f /tmp/elastixTMP_200707111201_81472369/elastixTMP_200707111201_81472369_target.mhd -m /tmp/elastixTMP_200707111201_81472369/elastixTMP_200707111201_81472369_moving.mhd -out /tmp/elastixTMP_200707111201_81472369 -p /tmp/elastixTMP_200707111201_81472369/elastixTMP_200707111201_81472369_parameters_1.txt 
Output argument "im" (and maybe others) not assigned during call to "elastix>getImage".

Error in elastix (line 375)
            registered = getImage(fullPath);

Error in example_2D_affine_alpha>runExampleLena (line 52)
    reg=elastix(lenaTrans,lena,[],'elastix_default.yml','paramstruct',p);

Error in example_2D_affine_alpha (line 40)
    runExampleLena(lenaTrans,lena,p,ind)

This is with a recently download version of elastix,

$ elastix --version
elastix version: 5.000

I don't think this is an error from elastix, as I can copy the command being run,

elastix -f /tmp/elastixTMP_200707111201_81472369/elastixTMP_200707111201_81472369_target.mhd -m /tmp/elastixTMP_200707111201_81472369/elastixTMP_200707111201_81472369_moving.mhd -out /tmp/elastixTMP_200707111201_81472369 -p /tmp/elastixTMP_200707111201_81472369/elastixTMP_200707111201_81472369_parameters_1.txt

from the output and run it from the command line with the following results.

elastix is started at Tue Jul  7 15:32:27 2020.

which elastix:   elastix
elastix runs at: gl-build.arc-ts.umich.edu
  Linux 3.10.0-1062.9.1.el7.x86_64 (x64), #1 SMP Fri Dec 6 15:49:49 UTC 2019
  with 191709 MB memory, and 36 cores @ 2999 MHz.
-------------------------------------------------------------------------

Running elastix with parameter file 0: "/tmp/elastixTMP_200707111201_81472369/elastixTMP_200707111201_81472369_parameters_1.txt".

Current time: Tue Jul  7 15:32:27 2020.
Reading the elastix parameters from file ...

Installing all components.
InstallingComponents was successful.

WARNING: The parameter "FixedImagePyramid", requested at entry number 0, does not exist at all.
  The default value "FixedSmoothingImagePyramid" is used instead.
WARNING: The parameter "MovingImagePyramid", requested at entry number 0, does not exist at all.
  The default value "MovingSmoothingImagePyramid" is used instead.
ELASTIX version: 5.000
Command line options from ElastixBase:
-f        /tmp/elastixTMP_200707111201_81472369/elastixTMP_200707111201_81472369_target.mhd
-m        /tmp/elastixTMP_200707111201_81472369/elastixTMP_200707111201_81472369_moving.mhd
-fMask    unspecified, so no fixed mask used
-mMask    unspecified, so no moving mask used
-out      /tmp/elastixTMP_200707111201_81472369/
-p        /tmp/elastixTMP_200707111201_81472369/elastixTMP_200707111201_81472369_parameters_1.txt
-threads  unspecified, so all available threads are used
Command line options from TransformBase:
-t0       unspecified, so no initial transform used

Reading images...
Reading images took 3 ms.

WARNING: the fixed pyramid schedule is not fully specified!
  A default pyramid schedule is used.
WARNING: the moving pyramid schedule is not fully specified!
  A default pyramid schedule is used.
WARNING: The parameter "CenterOfGravityUsesLowerThreshold", requested at entry number 0, does not exist at all.
  The default value "false" is used instead.
WARNING: The parameter "NumberOfSamplesForCenteredTransformInitialization", requested at entry number 0, does not exist at all.
  The default value "10000" is used instead.
Transform parameters are initialized as: [1, 0, 0, 1, 0, 0]
InitializeTransform took 0.01s
Scales are estimated automatically.
Scales for transform parameters are: [22224.514558053863, 22167.606767387682, 22224.514558053863, 22167.606767387682, 1, 1]
Initialization of all components (before registration) took: 10 ms.
Preparation of the image pyramids took: 35 ms.

Resolution: 0
WARNING: The parameter "CheckNumberOfSamples", requested at entry number 0, does not exist at all.
  The default value "true" is used instead.
WARNING: The parameter "UseMultiThreadingForMetrics", requested at entry number 0, does not exist at all.
  The default value "true" is used instead.
Setting the fixed masks took: 0 ms.
Setting the moving masks took: 0 ms.
WARNING: The parameter "NumberOfHistogramBins", requested at entry number 0, does not exist at all.
  The default value "32" is used instead.
WARNING: The parameter "FixedLimitRangeRatio", requested at entry number 0, does not exist at all.
  The default value "0.01" is used instead.
WARNING: The parameter "MovingLimitRangeRatio", requested at entry number 0, does not exist at all.
  The default value "0.01" is used instead.
WARNING: The parameter "FixedKernelBSplineOrder", requested at entry number 0, does not exist at all.
  The default value "0" is used instead.
WARNING: The parameter "MovingKernelBSplineOrder", requested at entry number 0, does not exist at all.
  The default value "3" is used instead.
WARNING: The parameter "UseFastAndLowMemoryVersion", requested at entry number 0, does not exist at all.
  The default value "true" is used instead.
WARNING: The parameter "UseJacobianPreconditioning", requested at entry number 0, does not exist at all.
  The default value "false" is used instead.
WARNING: The parameter "FiniteDifferenceDerivative", requested at entry number 0, does not exist at all.
  The default value "false" is used instead.
WARNING: The parameter "MaximumNumberOfSamplingAttempts", requested at entry number 0, does not exist at all.
  The default value "0" is used instead.
  The default value "0" is used instead.
Elastix initialization of all components (for this resolution) took: 1 ms.
  Computing the fixed image extrema took 0 ms.
  Computing the moving image extrema took 0 ms.
Initialization of AdvancedMattesMutualInformation metric took: 8 ms.
1:ItNr  2:Metric    3:StepSize  4:||Gradient||  Time[ms]
0   -0.664907   227.748733  0.008725    10.5
....  [ there are additional warnings at some intermediate steps ] ....
399 -0.709196   147.342319  0.086785    2.4
Time spent in resolution 4 (ITK initialization and iterating): 0.961 s.
Stopping condition: Maximum number of iterations has been reached.

Creating the TransformParameterFile took 0.00s

Registration result checksum: 1935034013

Applying final transform ...

  Writing image ...
  Applying final transform took 0.01s

Final metric value  = -0.709196
Time spent on saving the results, applying the final transform etc.: 14 ms.
Running elastix with parameter file 0: "/tmp/elastixTMP_200707111201_81472369/elastixTMP_200707111201_81472369_parameters_1.txt", has finished.

Current time: Tue Jul  7 15:32:32 2020.
Time used for running elastix with this parameter file:
  4.9s.

Is this perhaps something to do with a new version of elastix? Are the warnings benign?

Any help you might provide would be apprecitated.

-- bennet

raacampbell commented 4 years ago

I confirm I see the error too with v5 of Elastix. I'll look into it.

raacampbell commented 4 years ago

I think it's fixed (17e13fa8dd2b18fe26a63ad40ce9687ba2549b51). Please pull and try again.

justbennet commented 4 years ago

@raacampbell Tremendous respose! Pulled and it runs without errors now.

Should the correction for the CORRECTED: alpha=0.2 image be a set of diagonal lines? I get this as output.

image

justbennet commented 4 years ago

Hmm, yes looks like it should.

justbennet commented 4 years ago

Whoops. Running through all the examples now. Just got this

=====================
Running example_2D_affineThenWarping

  Shows the ability of elasix to chain together different transforms
  Here we do an affine followed by a non-rigid

Starting registration

 == Elastix parameters == 
Transform: AffineTransform
AutomaticTransformInitialization: 1
MaximumNumberOfIterations: 400
NumberOfSpatialSamples: 1000
Transform: BSplineTransform
MaximumNumberOfIterations: 1000
NumberOfSpatialSamples: 1000
SP_a: 4000
Error using validateElastixParam
Too many input arguments.

Error in elastix_parameter_write (line 82)
            if validateElastixParam(userParam.(thisKey),valid)

Error in elastix (line 233)
        elastix_parameter_write(paramFname{ii},paramFile,paramstruct{ii})

Error in example_2D_affineThenWarping (line 50)
[~,out]=elastix(lenaTrans,lena,[],'elastix_default.yml','paramstruct',p);

Error in RUN_ALL (line 15)
example_2D_affineThenWarping
justbennet commented 4 years ago

Sorry to be the bearer of sad tidings, but the examples in transformix also seem to be having a problem.

From applyLenaTransform2Dog

Error using endsWith
Unrecognized parameter name '.mhd'. Parameter name must be 'IgnoreCase'.

Error in transformix (line 328)
        if endsWith(d.name,'.mhd')

Error in applyLenaTransform2Dog (line 29)
reg=transformix(umaTform,params);

Error in RUN_ALL (line 4)
applyLenaTransform2Dog

From applyLenaTransform2Dog_withParams

Error using endsWith
Unrecognized parameter name '.mhd'. Parameter name must be 'IgnoreCase'.

Error in transformix (line 328)
        if endsWith(d.name,'.mhd')

Error in applyLenaTransform2Dog_withParams (line 29)
reg=transformix(umaTform,paramFiles,1);

Looks like transformSparsePoints_forward runs without error.

raacampbell commented 4 years ago

Can you tell me which version of MATLAB you are on? I think my examples were all written for an older version.

justbennet commented 4 years ago

I am using R2018b, but we'll likely be updating to R2019b or R2020a in September. I could possibly give this a try with R2016b if you need to check version compatibility.

raacampbell commented 4 years ago

I'm on 2019b. Don't worry about the older versions, I think it's likely it works there and anyway life needs to move forward. I'll run all the examples and update everything and/or make it a little more robust to version changes.

raacampbell commented 4 years ago

@raacampbell Tremendous respose! Pulled and it runs without errors now.

Should the correction for the CORRECTED: alpha=0.2 image be a set of diagonal lines? I get this as output.

image

I think that diagonal example has an element of randomness to it. I also get something very garbled but in a different way.

justbennet commented 4 years ago

Thanks for looking into this. I'm happy to rerun all the examples on my end if you want confirmation.

raacampbell commented 4 years ago

It was the same bug, actually. For some reason the .raw files were being passed on to later functions instead of the .mhd. The solution is to remove the .raw from the results of dir (d82972212e579f0b9ed933e777d738090e062c9f). I don't know why this ever worked correctly, TBH. Odd.

I also found some other bugs in the examples, which were old. They should all run now.

justbennet commented 4 years ago

Thanks, again. Did you look at the example_invert? I get this,


transformix is started at Tue Jul  7 21:30:15 2020.

which transformix:   transformix
transformix runs at: gl-build.arc-ts.umich.edu
  Linux 3.10.0-1062.9.1.el7.x86_64 (x64), #1 SMP Fri Dec 6 15:49:49 UTC 2019
  with 191709 MB memory, and 36 cores @ 2999 MHz.
Running transformix with parameter file "/tmp/transformix_200707173014_79220733/TransformParameters.1.txt".

Reading the elastix parameters from file ...

Installing all components.
InstallingComponents was successful.

ELASTIX version: 5.000
Command line options from ElastixBase:
-in       unspecified, so no input image specified
-out      /tmp/transformix_200707173014_79220733/
-threads  unspecified, so all available threads are used
-tp       /tmp/transformix_200707173014_79220733/TransformParameters.1.txt
-def      /tmp/transformix_200707173014_79220733/tmp_moving.txt
-jac      unspecified, so no det(dT/dx) computed
-jacmat   unspecified, so no dT/dx computed
Calling all ReadFromFile()'s ...
WARNING: The parameter "UseBinaryFormatForTransformationParameters", requested at entry number 0, does not exist at all.
  The default value "false" is used instead.
Reading the elastix parameters from file ...

WARNING: The parameter "UseBinaryFormatForTransformationParameters", requested at entry number 0, does not exist at all.
  The default value "false" is used instead.
  Calling all ReadFromFile()'s took 0.010078 s
Transforming points ...
  The transform is evaluated on some points, specified in the input point file.
  Reading input point file: /tmp/transformix_200707173014_79220733/tmp_moving.txt
  Input points are specified in world coordinates.
  Number of specified input points: 93
  The input points are transformed.
  The transformed points are saved in: /tmp/transformix_200707173014_79220733/outputpoints.txt
  Transforming points done, it took 0.00s
Compute determinant of spatial Jacobian ...
  The command-line option "-jac" is not used, so no det(dT/dx) computed.
  Computing determinant of spatial Jacobian done, it took 0.00s
Compute spatial Jacobian (full matrix) ...
  The command-line option "-jacmat" is not used, so no dT/dx computed.
  Computing spatial Jacobian done, it took 0.00s

transformix has finished at Tue Jul  7 21:30:15 2020.
Total time elapsed: 0.1s.

which doesn't look quite right. I don't know what I'm doing -- just installing for someone else, so if that is correct, sorry for the last bit of noise.

Thanks a bunch for looking at this!

raacampbell commented 4 years ago

Yes, I did test that. Just tested again and it works. You should see:

Screen Shot 2020-07-08 at 00 15 22

I don't see the warning you see but the last bunch of stuff otherwise looks similar:

transformix is started at Wed Jul  8 00:15:15 2020.

which transformix:   transformix
transformix runs at: cubiecube.local
  Mac OS X 10.13.6 (x64), 17G13035
  with 65536 MB memory, and 6 cores @ 4009 MHz.
Running transformix with parameter file "/private/var/folders/42/5jg5ygkn599dcytddlgdv_7h0000gn/T/transformix_200708001515_90579194/tmp_params_2.txt".

Reading the elastix parameters from file ...

Installing all components.
InstallingComponents was successful.

ELASTIX version: 5.000
Command line options from ElastixBase:
-in       unspecified, so no input image specified
-out      /private/var/folders/42/5jg5ygkn599dcytddlgdv_7h0000gn/T/transformix_200708001515_90579194/
-threads  unspecified, so all available threads are used
-tp       /private/var/folders/42/5jg5ygkn599dcytddlgdv_7h0000gn/T/transformix_200708001515_90579194/tmp_params_2.txt
-def      /private/var/folders/42/5jg5ygkn599dcytddlgdv_7h0000gn/T/transformix_200708001515_90579194/tmp_moving.txt
-jac      unspecified, so no det(dT/dx) computed
-jacmat   unspecified, so no dT/dx computed
Calling all ReadFromFile()'s ...
Reading the elastix parameters from file ...

  Calling all ReadFromFile()'s took 0.006050 s
Transforming points ...
  The transform is evaluated on some points, specified in the input point file.
  Reading input point file: /private/var/folders/42/5jg5ygkn599dcytddlgdv_7h0000gn/T/transformix_200708001515_90579194/tmp_moving.txt
  Input points are specified in world coordinates.
  Number of specified input points: 83
  The input points are transformed.
  The transformed points are saved in: /private/var/folders/42/5jg5ygkn599dcytddlgdv_7h0000gn/T/transformix_200708001515_90579194/outputpoints.txt
  Transforming points done, it took 0.00s
Compute determinant of spatial Jacobian ...
  The command-line option "-jac" is not used, so no det(dT/dx) computed.
  Computing determinant of spatial Jacobian done, it took 0.00s
Compute spatial Jacobian (full matrix) ...
  The command-line option "-jacmat" is not used, so no dT/dx computed.
  Computing spatial Jacobian done, it took 0.00s

transformix has finished at Wed Jul  8 00:15:15 2020.
Total time elapsed: 0.1s.
justbennet commented 4 years ago

Huh. Not sure what happened. I seem to be all good now, too. Thanks. I will close this now.