raacampbell / matlab_elastix Goto Github PK
View Code? Open in Web Editor NEWMATLAB Elastix wrapper
Home Page: http://www.mathworks.com/matlabcentral/fileexchange/52982-matlab-elastix
License: GNU Lesser General Public License v3.0
MATLAB Elastix wrapper
Home Page: http://www.mathworks.com/matlabcentral/fileexchange/52982-matlab-elastix
License: GNU Lesser General Public License v3.0
looks like an integer overflow is happening
Hi,
It seems you example code does not work, possibly because of your recent update.
Undefined variable "mElastixYML" or class "mElastixYML.yaml.ReadYaml".
Error in elastixYAML2struct (line 40)
yml=mElastixYML.yaml.ReadYaml(fname);Error in elastix_parameter_write (line 56)
params=elastixYAML2struct(YAML); %Default params from a user-supplied YAML or the default YAMLError in elastix (line 195)
elastix_parameter_write(paramFname{ii},paramFile,paramstruct(ii))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)40 yml=mElastixYML.yaml.ReadYaml(fname);
Hi, I've downloaded the most recent version with the single parameter file bug fix, but now I'm running into a different issue.
Angiorun and MPRresize are 512 x 512 x 497 matrices
outDir = 'C:\Users\yuanc\Dropbox (University of Michigan)[ASNR ASFNR AI Workshop]\test'
param = 'C:\Users\yuanc\Dropbox (University of Michigan)[ASNR ASFNR AI Workshop]\matlab_elastix-master\example_parameter_files\parameters_Rigid.txt'
elastix(Angiorun,MPRresize,outDir,param)
At first, it was giving me an error because it didn't recognize the full directory name due to the spaces
Running: elastix -f C:\Users\yuanc\Dropbox (University of Michigan)[ASNR ASFNR AI Workshop]\test\test_target.mhd -m C:\Users\yuanc\Dropbox (University of Michigan)[ASNR ASFNR AI Workshop]\test\test_moving.mhd -out C:\Users\yuanc\Dropbox (University of Michigan)[ASNR ASFNR AI Workshop]\test -p C:\Users\yuanc\Dropbox (University of Michigan)[ASNR ASFNR AI Workshop]\test\C:\Users\yuanc\Dropbox (University of Michigan)[ASNR ASFNR AI Workshop]\matlab_elastix-master\example_parameter_files\parameters_Rigid.txt
*** Transform Failed! ***
WARNING!
Argument (Universityis only required once.
Arguments (University ofare ignored
WARNING!
Argument Michigan)[ASNRis only required once.
Arguments Michigan)[ASNR ASFNRare ignored
WARNING!
Argument AIis only required once.
Arguments AI Workshop]\test\test_moving.mhdare ignored
WARNING!
Argument (Universityis only required once.
Arguments (University ofare ignored
WARNING!
Argument Michigan)[ASNRis only required once.
Arguments Michigan)[ASNR ASFNRare ignored
WARNING!
Argument AIis only required once.
Arguments AI Workshop]\testare ignored
WARNING!
Argument (Universityis only required once.
Arguments (University ofare ignored
WARNING!
Argument Michigan)[ASNRis only required once.
Arguments Michigan)[ASNR ASFNRare ignored
WARNING!
Argument AIis only required once.
Arguments AI Workshop]\test\C:\Users\yuanc\Dropboxare ignored
WARNING!
Argument (Universityis only required once.
Arguments (University ofare ignored
WARNING!
Argument Michigan)[ASNRis only required once.
Arguments Michigan)[ASNR ASFNRare ignored
WARNING!
Argument AIis only required once.
Arguments AI Workshop]\matlab_elastix-master\example_parameter_files\parameters_Rigid.txtare ignoredelastix is started at Thu Jun 17 12:13:51 2021.
which elastix: elastix
elastix runs at: Envy
Windows Personal (x64), (Build 9200)
with 32630 MB memory, and 8 cores @ 2904 MHz.Running elastix with parameter file 0: "C:\Users\yuanc\Dropbox".
Current time: Thu Jun 17 12:13:51 2021.
Reading the elastix parameters from file ...ERROR: when reading the parameter file:
itk::ExceptionObject (00000020858FF408)
Location: "unknown"
File: D:\X\src\elx\5.0.1\Common\ParameterFileParser\itkParameterFileParser.cxx
Line: 140
Description: itk::ERROR: itk::ERROR: ParameterFileParser(000001C34DFB18D0): ERROR: the file C:\Users\yuanc\Dropbox is a directory.ERROR: Something went wrong during initialization of the configuration object.
ERROR:
The configuration object has not been initialized.
Errors occurred!You may want to check out the Elastix FAQ: https://github.com/SuperElastix/elastix/wiki/FAQ
I just tried running that same line again, without changing anything and then I get this error...
elastix(Angiorun,MPRresize,outDir,param)
Error using elastix (line 219)
Can't move files
Finally, I tried using double quotes "" instead of single quotes '' for the directory and parameter file name.
param = "C:\Users\yuanc\Dropbox (University of Michigan)[ASNR ASFNR AI Workshop]\matlab_elastix-master\example_parameter_files\parameters_Rigid.txt";
outDir = "C:\Users\yuanc\Dropbox (University of Michigan)[ASNR ASFNR AI Workshop]\test";
elastix(Angiorun,MPRresize,outDir,param)Error using mhd_write (line 41)
fname should be a stringError in elastix (line 217)
mhd_write(movingImage,movingFname);
I'm sure there's a simple solution to getting it to recognize the full file name with the spaces. I can't remove the spaces because the data is on dropbox, and that is automatically named with spaces in there.
OUT=elastix(movingImage,fixedImage);
Using default parameter file elastix_default.yml
Cell contents assignment to a non-cell array object.
Error in elastix (line 200)
paramFname{1} = fullfile(outputDir,paramFname);
I ran the example_2D_affine_nSpatialSamples.m and it failed. This was the result:
Starting registration
Transform: AffineTransform
MaximumNumberOfIterations: 1500
SP_alpha: 6.000000e-01
NumberOfSpatialSamples: 50
Undefined variable "yaml" or class "yaml.ReadYaml".
Error in elastixYAML2struct (line 42)
yml=yaml.ReadYaml(fname);
Error in elastix_parameter_write (line 56)
params=elastixYAML2struct(YAML); %Default params from a user-supplied YAML or the default YAML
Error in elastix (line 194)
elastix_parameter_write(paramFname{ii},paramFile,paramstruct(ii))
Error in example_2D_affine_nSpatialSamples>runExampleLena (line 54)
reg=elastix(lenaTrans,lena,[],'elastix_default.yml','paramstruct',p);
Error in example_2D_affine_nSpatialSamples (line 41)
runExampleLena(lenaTrans,lena,p,ind)
I also ran the selftest report for YAML shows 'Failed, Crash' for all tests bar the read
I'm trying to use this (for the first time), and I keep getting an error, I think it's trying to call 'paramFname' before it has been initialized.
I pasted what I'm seeing below.
Angiorun and MPRresize are both 512x512x497 matrices, I am basically just trying to do a rigid transformation.
elastix(Angiorun,MPRresize,'C:\Users\yuanc\Dropbox (University of Michigan)[ASNR ASFNR AI Workshop]\test','C:\Users\yuanc\Dropbox (University of Michigan)[ASNR ASFNR AI Workshop]\matlab_elastix-master\example_parameter_files\parameters_Rigid.txt')
Unrecognized function or variable 'paramFname'.Error in elastix (line 247)
copyfile(paramFname,outputDir)
It should work as follows:
Provide path to elastix transform directory. From this extract the fixed image path and params paths. Automatically create a directory called "inverse" within the directory (or allow the user to specify a location). Run it.
This does a non-rigid only:
p.Transform='AffineTransform';
[OUT,stats]=elastix(movingImage,fixedImage,'./testElastix',[],'paramstruct',p);
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
When I ran my matlab code in Linux environment on HPC, I ran into following warning signs:
Warning: A worker aborted during execution of the parfor loop. The parfor loop will now run again on the remaining workers.
Now my questions are:
My matlab code works in Windows environment perfectly without above issues at all.
In transformix, it's supposed to be possible to output a deformation field rather than an image. (I'm working with hyperspectral so it's much easier to get the deformation field and transform all the layers individually using the deformation field. Anyway, I came up with a fix outlined below. Note that the fix is tailored to my needs. This is for a 2D image, not sure how it would work for 3D
Originally I did get an output but it was an empty 1x1 stucture
fid = fopen(fullfile(outputDir,'deformationField.raw'));
raw_out = fread(fid,Inf,'float');
out_points(:,:,1) = reshape(raw_out(1:2:end),size_im(2),size_im(1));
out_points(;,:,2) = reshape(raw_out(2:2:end),size_im(2),size_im(1));
out_points = permute(out_points,[2,1,3]);
From there, I'm able to just cycle through and call
for ii = 1:num_channels
out(:,:,ii) = imwarp(moving(:,:,ii),out_points);
end
I originally just ran all the layers through but this comes out to a 1.5 minutes saving per data cube processed.
Also, how to I insert code formatting here? Not used to github.
When running elastix.m on linux, then following section produces an error:
% Run the command and report back if it failed fprintf('Running: %s\n',CMD) if isunix CMD=['LD_LIBRARY_PATH= ', CMD]; end
Commenting out this prefixing solves the issue.
I have tried both Windows 10 and mac systems. Following all the steps, set up Elastix binary files to PATH, and add "code" and "yamlmatlab" onto MATLAB path. However, I still receive these error messages saying that there cannot find elastic binary in system path. Could you please help me?
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*** ERROR: Unable to find elastix binary in system path. Quitting ***
One or more output arguments not assigned during call
to "varargout".
Error in example_2D_affineThenWarping (line 48)
[~,out]=elastix(lenaTrans,lena,[],'elastix_default.yml','paramstruct',p);
Dear Rob,
first, thanks for putting together this project.
I think there is a small bug in the function elastix_paramStruct2txt.m, when writting out logical values. Here both only true gets written in the text file. I think line 72 should be
str = sprintf('(%s "false")\n',param);
Best
Florian
I am trying to use your wrapper with an Elastix parameter file (in .txt format) but I get this error:
Undefined function or variable 'paramFname'.
Error in elastix (line 247)
copyfile(paramFname,outputDir)
Error in Register_images_FF2 (line 30)
elastix(movingImage,fixedImage,outputDir,param_file);
Do you know what could cause it?
Thanks!
Hi,
I've followed the guidance of "Getting started". But I ran into the error:No function or variable 'Elastix' is defined when I ran the examples in MelastiX_examples.
未定义函数或变量 'elastix'。
出错 example_2D_affine_alpha>runExampleLena (line 52)
reg=elastix(lenaTrans,lena,[],'elastix_default.yml','paramstruct',p);
出错 example_2D_affine_alpha (line 40)
runExampleLena(lenaTrans,lena,p,ind)
Maybe do you konw which step I did wrong?
Thank you very much!!
Hey,
Do you know if elastix works with the M1 chip and is it the same method to add elastix to the system path as non M1 macs?
Thanks!
Whilst I have added the option for a deformation field image by having first input argument be empty. I still need to have it read control points, so we can register sparse points.
Either add compression as an option to the reader or stop MelastiX compressing under all circumstances
Is it possible to obtain some kind of deformation field via Melastix of Mtransformix? When I run the transformix file it loops like you have to alter your input or something, but I don't know how or whether this is possible?
The only output that I obtain is an image and some logfile...
Thanks in advance!
Error` using fwrite
Invalid file identifier. Use fopen to generate a valid file identifier.
Error in mhd_write (line 61)
cnt=fwrite(fid,im,class(im));
Error in elastix (line 217)
mhd_write(movingImage,movingFname);
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)
the following errors were coming while performing the examples given in the matlab elastix .
please help me to resolve these issues.
Elastix writes no image if writeImageResult is false. We don't check for this. If the user asks for an output argument then we should automatically set this to true. Otherwise, we should leave untouched.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.