users > landmarks, subsampling and .xform data
Showing 1-25 of 29 posts
Display:
Results per page:

1   2   Next >
Dec 17, 2012  04:12 PM | Ruben Portugues
landmarks, subsampling and .xform data
Hi,

I have 3 questions about cmtk alignment.

1) Landmark Alignments
Is there a workflow example on using landmark based alignments?  I did not find one on the documentation pdf and was wondering about this.
 
2) What is the output of the .xform files
I was hoping to understand the output of the .xform files that get generated with the transformations.  The ultimate aim would be to be able to generate a movie of one brain transforming into another and I was hoping to be able to create a one-parameter flow between the sample and the reference brain.  is there a way of doing this?

3) Is it possible to use a subsampled stack to find a transformation between two brains and then apply this to the original stack?  I am thinking about ease (and possibility) of computation without running into out of memory errors.

Any help on where I can find any documentation or examples would be great.  Thanks.

Ruben
Dec 17, 2012  06:12 PM | Torsten Rohlfing
RE: landmarks, subsampling and .xform data
Hi Ruben.
Originally posted by Ruben Portugues:
Hi,

I have 3 questions about cmtk alignment.

1) Landmark Alignments
Is there a workflow example on using landmark based alignments?  I did not find one on the documentation pdf and was wondering about this.

There isn't really a workflow for landmark-based alignment. There is a tool to fit linear transformations to landmarks: fit_affine_xform_landmarks

Nonrigid fitting (using multi-level B-spline) is supported by the library, but the command line tool that makes this available is very specific to using the fitted transformation for unwarping images using a reference scan of the ADNI phantom (in other words: that tool takes a phantom description in XML format rather than two landmark lists as its input).
 
2) What is the output of the .xform files
I was hoping to understand the output of the .xform files that get generated with the transformations.  The ultimate aim would be to be able to generate a movie of one brain transforming into another and I was hoping to be able to create a one-parameter flow between the sample and the reference brain.  is there a way of doing this?

Now this really depends on whether you mean linear (affine, rigid) xform files, or nonrigid (B-spline).

For the linear transformations, you can use the "dof2mat" tool to convert the xform representation (which uses canonical transformation parameters, e.g., translation, rotation, scales) into a transformation matrix.

But from what you are saying, it seems you are more interested in the nonrigid transformations. The bad news is, that the B-spline transformation is more complex than the linear transformation, and that is reflected in a more complex file format. I would advise against trying to read this format.

The good news is - there is a tool that should do almost exactly what you are asking: the "convert_warp" tool has a "--fractional" option, which takes a real number between 0 and 1. It will then read a nonrigid xform and write out a transformation that is either the full nonrigid transformation ("--fractional 1"), only the initial linear transformation ("--fractional 0"), or something in between (any value between 0 and 1).

This should allow you to create the intermediate transformations you are looking for, which you can then feed into the "reformatx" tool to create the animated brain deformation.


3) Is it possible to use a subsampled stack to find a transformation between two brains and then apply this to the original stack?  I am thinking about ease (and possibility) of computation without running into out of memory errors.

In general, yes (all command line tools involved will let you do this), but in practice probably not. The problem is that subsampling will change the field of view of the images, and thus their intrinsic coordinate systems.

This is specifically a problem with the nonrigid transformations, because the B-spline control point grid has to cover the image field of view. If you compute a deformation with a subsampled image (which has a smaller field of view) then the resulting control point grid will not cover the entire FOV of the original image.

You can instead control whether the original image data are used in the registration or not (the "warp" tool, for example, has a "--omit-original-data" command line options), but this only helps with speed of the computation, not with lack of memory.

Best,
  Torsten
Jan 8, 2013  03:01 PM | Ruben Portugues
RE: landmarks, subsampling and .xform data
Hi Torsten,
as always, thanks.  I finally got to try the convert_warp tool and after some trial and error I think I got the syntax right and it is working (btw is there an online resource where I can look up such things as the correct syntax when calling a function?).  Is there a similar tool to perform a fractional affine transformation?
Thank you.
Ruben
Jan 8, 2013  05:01 PM | Torsten Rohlfing
RE: landmarks, subsampling and .xform data
Hi Ruben:

There isn't an online resource per se for each tool's syntax, but virtually all of CMTK's command line tools (not currently shell scripts, but that is in the works) support multiple ways of getting on-the-fly command line help. Simply run the tool with either "--help" option (for simple help text), "--man" (for man page-style documentation; pipe through nroff etc.), "--wiki" (for MediaWiki-style documentation). Note that "--help" will by default exclude "advanced" options to keep things simple. To get the complete list of all supported options, use "--help-all" instead.

Regarding fractional affine transformations - no, sorry, there is no such thing. You can "fake" it rather easily, though - the standard file format for affine transformations in CMTK lists canonical transformation parameters, i.e., translation, rotation angles, scale factors, and shear coefficients, in a human-readable format. You can read such a file and simply compute the fractional parameters yourself, then write the result in a new transformation file in the same, straight-forward format.

Note that this is not truly a fractional transformation, though, in the sense that if you take 1/2 of each parameter, you will not get a transformation that, when concatenated with itself, gives you the original transformation. That is, you would not get the "square root" affine matrix using fractional 0.5. To do that kind of thing, especially for other fractional values, would require some more involved matrix algebra, and that isn't even supported by the back-end library at this point.

Best,
  Torsten

Originally posted by Ruben Portugues:
Hi Torsten,
as always, thanks.  I finally got to try the convert_warp tool and after some trial and error I think I got the syntax right and it is working (btw is there an online resource where I can look up such things as the correct syntax when calling a function?).  Is there a similar tool to perform a fractional affine transformation?
Thank you.
Ruben
Jan 8, 2013  08:01 PM | Ruben Portugues
RE: landmarks, subsampling and .xform data
Thank you, it makes perfect sense.
Best,
Ruben
Jan 8, 2013  11:01 PM | Ruben Portugues
RE: landmarks, subsampling and .xform data
Torsten, 
I was just checking the output of the convert_warp tool.  As I understand it, the "--fractional 1" option should equal the original transformation, so that when applied to the original stack using the reformatx tool they should give the same final outcome.  This is not the case for me.  What am I missing?

The commands I am using are:
convert_warp --fractional 1.0 warp_original.xform warp_fractional.xform
reformatx -o out_stack --floating in_stack reference_stack warp_(original or fractional).xform 

Thanks,
Ruben
Jan 8, 2013  11:01 PM | Torsten Rohlfing
RE: landmarks, subsampling and .xform data
Ruben:

I just checked the convert_warp source code, and confirmed that indeed "--fractional 1" should give you the same transformation as you put in.

Now that said, even in the f=1 case, there is the same arithmetic going on as for any other fractional value, so there will likely be subtle differences due to finite floating point precision. So a binary comparison of the input and output files should be expected to show some differences.

That said, these differences should be very small and should not really affect the result of the reformatting operation (beyond, again, differences on the order of machine precision).

If you want, you can send me your input and output transformations and I'll take a look what's going on.

TR

Originally posted by Ruben Portugues:
Torsten, 
I was just checking the output of the convert_warp tool.  As I understand it, the "--fractional 1" option should equal the original transformation, so that when applied to the original stack using the reformatx tool they should give the same final outcome.  This is not the case for me.  What am I missing?

The commands I am using are:
convert_warp --fractional 1.0 warp_original.xform warp_fractional.xform
reformatx -o out_stack --floating in_stack reference_stack warp_(original or fractional).xform 

Thanks,
Ruben
Jan 9, 2013  03:01 AM | Torsten Rohlfing
RE: landmarks, subsampling and .xform data
I put a fix into SVN (r4670) that addresses this problem. It will also be in CMTK 2.3.0, but that will take a little while to appear. For now, you'll have to build from source to get the corrected version.

Best,
  Torsten
Jan 9, 2013  01:01 PM | Ruben Portugues
RE: landmarks, subsampling and .xform data
Thank you Torsten, I will try do build it (I have never tried before).
I found some instructions on:
http://www.nitrc.org/forum/message.php?m...
but I am using a windows machine.  Are there any instructions as to how to do it?
Best,
Ruben
Jan 9, 2013  06:01 PM | Torsten Rohlfing
RE: landmarks, subsampling and .xform data
The easiest way for you would be to build using Cygwin, in which case basically the same instructions apply as on Linux or Mac. Except, you would have to use the source code from SVN rather than a downloaded archive. You could get the code via

svn co https://nitrc.org/svn/cmtk/trunk/core cmtk

(code will end up in cmtk/ subdirectory).

If you want to build using MS VisualStudio, you will need the Windows version of CMake (from cmake.org). You will also need a Windows SVN client (e.g., Tortoise), but I cannot provide instructions on how to use that.

Anyway, start CMake GUI, and select the source directory checked out from SVN and select/create a build directory. Then push the "Configure" and after that the "Generate" buttons. Afterwards, go into VS and open the "Solution" CMTK created in the selected build directory. Finally, build the software.

Let me know if you run into any specific problems.

TR

Originally posted by Ruben Portugues:
Thank you Torsten, I will try do build it (I have never tried before).
I found some instructions on:
http://www.nitrc.org/forum/message.php?m...
but I am using a windows machine.  Are there any instructions as to how to do it?
Best,
Ruben
Jan 10, 2013  01:01 PM | Ruben Portugues
RE: landmarks, subsampling and .xform data
Hi Torsten,
so I decided to try the cygwin approach.  I am trying to follow the instructions below (from http://www.nitrc.org/forum/message.php?m...):

- Download the CMTK source archive (from the same download page as the binary packages)
- Unpack archive using "tar -xzvf CMTK-2.2.4-Source.tar.gz"
- Make a build directory: "mkdir cmtk-build"
- "cd cmtk-build"
- Configure: "cmake ../cmtk-2.2.4/"
- Build: "make

I downloaded cygwin, opened a terminal, downloaded "cmtk-scm-latest.tar.gz" and unpacked it.  It created a directory called "cmtk-scm-2013-01-06".  If I cd into it and run the cmake command it tells me: "cake: command not found".  I guess maybe "cmtk-scm-latest.tar.gz" is not the right file?  If I go to "https://nitrc.org/svn/cmtk/trunk/core" I see a big directory structure with lots of subdirectories and files, but I am not sure how do download all these files.  I am new to building code so I apologize if these questions are trivial.
Thanks,
Ruben
Jan 10, 2013  06:01 PM | Torsten Rohlfing
RE: landmarks, subsampling and .xform data
Hi Ruben:

So the archive you downloaded appears to be some kind of default archive generated by NITRC... to be hnoest, I am not sure what's in there.

The best way to get the code in Cygwin is to install the "subversion" package, if it's not already installed (you should have a command "svn" in your path then).

Afterwards, run

svn co https://nitrc.org/svn/cmtk/trunk/core cmtk

And you should see all the necessary files appear under the newly-created cmtk/ directory. (Choose a different name if you prefer).

You should then be able to proceed as follows:

mkdir cmtk-build
cd cmtk-build
cmake ../cmtk
make

I guess you used a web browser to access the SVN repository, which indeed does not get you very far.

Hope this helps.

Torsten
Jan 10, 2013  07:01 PM | Ruben Portugues
RE: landmarks, subsampling and .xform data
So I think I am getting close, thank you for your patience.
 
I installed the subversion package and typed
"svn co https://nitrc.org/svn/cmtk/trunk/core cmtk"
which indeed installed the files in the directory cmtk. This directory is in my cygwin/home/username directory.  So from this directory (cygwin/home/username) I then type
"mkdir cmtk-build"
"cd cmtk-build"
"cmake ../cmtk"
And I get the answer:
"-bash: cmake: command not found"

I feel that maybe I am not in the right directory, but I have tried around with no luck.  Where am I going wrong?
Thanks!
Jan 10, 2013  07:01 PM | Torsten Rohlfing
RE: landmarks, subsampling and .xform data
Sorry, you also need to install the Cygwin "cmake" package :)
Jan 10, 2013  07:01 PM | Ruben Portugues
RE: landmarks, subsampling and .xform data
Ok. I installed it. Typed
"cmake ../cmtk"
and got:
CMake Error: The source directory "/home/rportugues/cmtk" does not appear to con tain CMakeLists.txt.
 
So I then tried:
"cmake ../cmtk/core"
and got
"
CMake Error: CMake was unable to find a build program corresponding to "Unix Mak efiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a differen t build tool.
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file:/home/rportugues/cmtk-build/CMakeF iles/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file:/home/rportugues/cmtk-build/CMakeF iles/CMakeCXXCompiler.cmake
CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
"
 
This last message looks a bit scary.
Jan 10, 2013  07:01 PM | Torsten Rohlfing
RE: landmarks, subsampling and .xform data
Ah, yes, sorry... I forgot how little stuff cygwin installs by default.

You are right about "cmtk cmtk/core/" though; sorry for the confusion.

Now, here's a list of additional Cygwin packages that you should install (hope this will be enough):

gcc4
gcc4-c++
make

This should be enough for a plain CMTK build.

Fingers crossed.

Nothing scary in the errors by the way - just unable to find the compiler, that's all.
Jan 10, 2013  08:01 PM | Ruben Portugues
RE: landmarks, subsampling and .xform data
Ok, so
"cmake ../cmtk-core"
worked I think, and then
"make"
worked for a bit until I got:

[ 38%] Building CXX object libs/System/CMakeFiles/cmtkSystem.dir/cmtkMemory.cxx.o
[ 38%] Building CXX object libs/System/CMakeFiles/cmtkSystem.dir/cmtkMountPoints.cxx.o
[ 38%] Building CXX object libs/System/CMakeFiles/cmtkSystem.dir/cmtkProgress.cxx.o
[ 38%] Building CXX object libs/System/CMakeFiles/cmtkSystem.dir/cmtkProgressConsole.cxx.o
[ 39%] Building CXX object libs/System/CMakeFiles/cmtkSystem.dir/cmtkRegressionTracker.cxx.o
[ 39%] Building CXX object libs/System/CMakeFiles/cmtkSystem.dir/cmtkStackBacktrace.cxx.o
[ 39%] Building CXX object libs/System/CMakeFiles/cmtkSystem.dir/cmtkStrUtility.cxx.o
[ 39%] Building CXX object libs/System/CMakeFiles/cmtkSystem.dir/cmtkThreads.cxx.o
In file included from /home/rportugues/cmtk/core/libs/System/cmtkThreads.cxx:75:0:
/home/rportugues/cmtk/core/libs/System/cmtkFFTW.h:36:19: fatal error: fftw3.h: No such file or directory
compilation terminated.
libs/System/CMakeFiles/cmtkSystem.dir/build.make:655: recipe for target 'libs/System/CMakeFiles/cmtkSystem.dir/cmtkThreads.cxx.o' failed
make[2]: *** [libs/System/CMakeFiles/cmtkSystem.dir/cmtkThreads.cxx.o] Error 1
CMakeFiles/Makefile2:4714: recipe for target 'libs/System/CMakeFiles/cmtkSystem.dir/all' failed
make[1]: *** [libs/System/CMakeFiles/cmtkSystem.dir/all] Error 2
Makefile:146: recipe for target 'all' failed
make: *** [all] Error 2
 
Does this mean anything to you?
Jan 10, 2013  09:01 PM | Torsten Rohlfing
RE: landmarks, subsampling and .xform data
Ah, yes, it is not finding the Fourier Transform library... that is supposed to be optional, but it seems that's not being configured properly. I am going to but a bug into the tracker.

In the meantime, just install the

libfftw3-devel

package, which should fix the problem.

Sorry.

Torsten
Jan 10, 2013  10:01 PM | Ruben Portugues
RE: landmarks, subsampling and .xform data
So "cmake" and "make" worked, and now I get a problem when trying to run the registration command that it cannot find cygwin1.dll. 
I feel I am getting close :)
 
Jan 10, 2013  10:01 PM | Torsten Rohlfing
RE: landmarks, subsampling and .xform data
Close indeed :)

The easiest thing to do is probably to run all CMTK tools built under Cygwin from a Cygwin terminal/command line, not the Windows command line.

If you do that, your Windows disk c: will be under /cygdrive/c (other disks analogous), so you should have access to all your data.

If you do want to run things from Win command line, add the directory that contains cygwin1.dll (likely c:\cygwin\bin) to your PATH.

TR
Jan 10, 2013  10:01 PM | Ruben Portugues
RE: landmarks, subsampling and .xform data
Incredible, I added it to the windows path (so I can use a small Matlab wrapper I wrote) and I believe it is performing an affine transformation now.  
Thank you so much Torsten.
I will try the fractional warping and let you know how those turn out.
Best,
Ruben
Jan 10, 2013  10:01 PM | Torsten Rohlfing
RE: landmarks, subsampling and .xform data
Yay! :)

By the way - an additional benefit of using Cygwin builds is that gcc supports OpenMP, which Visual Studio Express (I don't have a full version) only started supporting in the 2012 version. So you get more parallel code (at least until I start releasing VS2012 builds).

If you want some more performance oomph - go into "ccmake" in your build directory, find the "CMAKE_C_FLAGS" and "CMAKE_CXX_FLAGS" variables and add the following to both (!):

-march=nocona -mmmx -msse -msse2 -mfpmath=sse

(This is assuming you have an x86_64-capable CPU, but these days, who doesn't?)

Best,
  Torsten
Jan 11, 2013  03:01 PM | Ruben Portugues
RE: landmarks, subsampling and .xform data
Ok, I will try to implement this (I do have an x86_64 cpu).  In my cmtk-newbuild directory I have several subdirectories (apps, bin, cmakafiles, data, install, libs, scripts, testing, utiliies).  I searched for "CMAKE_C_FLAGS" and "CMAKE_CXX_FLAGS" and did not find these.
Jan 11, 2013  04:01 PM | Torsten Rohlfing
RE: landmarks, subsampling and .xform data
Ah, no, what you do is:

In the same directory where you ran cmake originally, run "ccmake ." - that will open a GUI-like interface to configure the build. You have to press "t" to toggle the advanced options, then you should be able to find the two variables I mentioned.

After adding the optimization settings, also change "BUILD_TYPE" to "Release" for activating compiler optimizations.

Then press "c" for "configure", after which you can exit the GUI via "q" and re-run "make"

Hope this all makes sense. :-) 

Torsten
Jan 11, 2013  09:01 PM | Ruben Portugues
RE: landmarks, subsampling and .xform data
Ok, I think I implemented the changes you mentioned, reran both cake and make and it worked ok.  
I am having some problems though running some cmtk commands.  For example, when running the 
reformatx command I get an error when attempting to write the nrrd image:
"ERROR: NrrdIO library returned error '[nrrd] nrrdSave: couldn't open("cygdrive/c/cmtk/cmtk_newbuild /bin/\Users ..."

I think this has to do with what the home directory and where I am running the commands right?  Even if I run a command from a dos terminal it gives me this error.  
Any thoughts?

1   2   Next >