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

Can't move files error #30

Closed yuanci89 closed 3 years ago

yuanci89 commented 3 years ago

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 ignored

elastix 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 string

Error 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.

raacampbell commented 3 years ago

I think very likely your paths are at at fault because of the spaces and maybe because of the brackets too.

Changing the quotes didn't help because MATLAB doesn't alter how it represents the strings when you do that. The failure is actually happening where the Elastix binary itself is run via system command call and that command call right now looks like:

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

So it contains unquoted strings with spaces when it calls the binary and that is almost certainly the problem. I pushed a change (8ca8703e6a24e92d8d611c4e7866815d0449549b) that places double quoted strings around those paths in both elastix.m and transformix.m. I can't fully test it right now, but it seems to be writing the correct system call.

You should be able to get rid of the very annoying DropBox characters by creating a shortcut to the DropBox directory that does not have spaces and brackets. e.g. make a shortcut called Dropbox_UMich_ASNR.

yuanci89 commented 3 years ago

Thanks, I'm going to see if that double quote change works now.

yuanci89 commented 3 years ago

So I ended up just using a more straightforward subdirectory, and ended up with another issue...

outDir = 'C:\Users\yuanc\Desktop\shortcuts\test'; param = 'C:\Users\yuanc\Desktop\shortcuts\parameters_Rigid.txt'; elastix(Angiorun,MPRresize,outDir,param) Running: elastix -f "C:\Users\yuanc\Desktop\shortcuts\test\test_target.mhd" -m "C:\Users\yuanc\Desktop\shortcuts\test\test_moving.mhd" -out "C:\Users\yuanc\Desktop\shortcuts\test" -p "C:\Users\yuanc\Desktop\shortcuts\test\C:\Users\yuanc\Desktop\shortcuts\parameters_Rigid.txt"

Transform Failed!

elastix is started at Fri Jun 18 13:30:42 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\Desktop\shortcuts\test\C:\Users\yuanc\Desktop\shortcuts\parameters_Rigid.txt".

Current time: Fri Jun 18 13:30:42 2021. Reading the elastix parameters from file ...

ERROR: when reading the parameter file:

itk::ExceptionObject (0000000C6C8FEFC8) Location: "unknown" File: D:\X\src\elx\5.0.1\Common\ParameterFileParser\itkParameterFileParser.cxx Line: 130 Description: itk::ERROR: itk::ERROR: ParameterFileParser(000001BBA56F2E10): ERROR: the file C:\Users\yuanc\Desktop\shortcuts\test\C:\Users\yuanc\Desktop\shortcuts\parameters_Rigid.txt does not exist.

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 think it is somehow concatenating the output directory string with the param file string, so I tried removing the directory information from my param file string and got this:

param = 'parameters_Rigid.txt'; elastix(Angiorun,MPRresize,outDir,param) Error using copyfile No matching files were found.

Error in elastix (line 247) copyfile(paramFile,outputDir)

raacampbell commented 3 years ago

Ok I see. I'll look into it but maybe not right away. Look at my recent commits. Probably the answer is quite obvious based on those. Let me know if you figure it out.

On Fri, 18 Jun 2021, 18:46 yuanci89, @.***> wrote:

So I ended up just using a more straightforward subdirectory, and ended up with another issue...

outDir = 'C:\Users\yuanc\Desktop\shortcuts\test'; param = 'C:\Users\yuanc\Desktop\shortcuts\parameters_Rigid.txt'; elastix(Angiorun,MPRresize,outDir,param) Running: elastix -f "C:\Users\yuanc\Desktop\shortcuts\test\test_target.mhd" -m "C:\Users\yuanc\Desktop\shortcuts\test\test_moving.mhd" -out "C:\Users\yuanc\Desktop\shortcuts\test" -p "C:\Users\yuanc\Desktop\shortcuts\test\C:\Users\yuanc\Desktop\shortcuts\parameters_Rigid.txt"

Transform Failed!

elastix is started at Fri Jun 18 13:30:42 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\Desktop\shortcuts\test\C:\Users\yuanc\Desktop\shortcuts\parameters_Rigid.txt".

Current time: Fri Jun 18 13:30:42 2021. Reading the elastix parameters from file ...

ERROR: when reading the parameter file:

itk::ExceptionObject (0000000C6C8FEFC8) Location: "unknown" File: D:\X\src\elx\5.0.1\Common\ParameterFileParser\itkParameterFileParser.cxx Line: 130 Description: itk::ERROR: itk::ERROR: ParameterFileParser(000001BBA56F2E10): ERROR: the file C:\Users\yuanc\Desktop\shortcuts\test\C:\Users\yuanc\Desktop\shortcuts\parameters_Rigid.txt does not exist.

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 think it is somehow concatenating the output directory string with the param file string, so I tried removing the directory information from my param file string and got this:

param = 'parameters_Rigid.txt'; elastix(Angiorun,MPRresize,outDir,param) Error using copyfile No matching files were found.

Error in elastix (line 247) copyfile(paramFile,outputDir)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/raacampbell/matlab_elastix/issues/30#issuecomment-864188995, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJNEY3MWE6OH6Z35ASX46TTTOA7PANCNFSM464A4W7Q .

yuanci89 commented 3 years ago

I think I figured it out, it's on line 248. It's concatenating the two inputs for some reason, so I just removed the outputDir and it seemed to work.

% paramFname{1} = fullfile(outputDir,paramFile); paramFname{1} = fullfile(paramFile);

raacampbell commented 3 years ago

That is working but it's doing so in a way that might cause problems downstream. See that line in context:

        copyfile(paramFile,outputDir)        
        paramFname{1} = fullfile(outputDir,paramFile);

So the logic is that the parameter file is copied to the output directory then will later be used at that location. That's what is happening around line 260 in the case of multiple parameter files. Your fix causes the original parameter file to be used, which is not what happens elsewhere. It may make no difference at all but for the sake of consistency I have fixed the code in a way that retains the behavior shown elsewhere. See: 23e97c04f909d9d1ffde6e6d8ca611bab4a67cf9

I haven't test that. I just changed it on-line.

yuanci89 commented 3 years ago

Ah, I'm super new to GitHub so I don't really know how to edit things on here... I'll download and test out those changes.

Quick side question: how do I output into a matrix? I think the elastix outputs into an mhd by default, but I'm assuming it outputs as a matrix as well?

raacampbell commented 3 years ago

I just meant that to make the change I edited the file and didn't test anything. GitHub isn't important.

elastix.m returns the registered image. See help elastix in MATLAB. There is further stuff in a second output arg.

yuanci89 commented 3 years ago

Thank you for your support, I think I have it up and running now. :)