[prev in list] [next in list] [prev in thread] [next in thread] 

List:       insight-users
Subject:    Re: [Insight-users] coordinate system
From:       WANG Chengjia <wangchengjia1986 () gmail ! com>
Date:       2014-02-19 19:16:42
Message-ID: CADmrLXd39XWWmL=jOUHfSC7o2j_L0LdSx5vXorXwgpAU2bZbvw () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Hi all,

Thank you very much for all your suggestions! Just realize that ITK
assuming a LPS coordinate, I need to invert all the image coordinate values
to get right transformation matrix. Especially thanks to Alex and Luis's
help!

However, the transformed result is still a little wrong: I found before and
after resampling the image,  the origin in the original image was a little
shifted (centre of [0 0 0] point in original volume shifted to [x0, y0,
z0], and this shifted value is different in upsample and downsample cases).
What I exactly need for resampling is to have the centre of the origin
pixel fixed.

Thank you very much!

Best,





On Wed, Feb 19, 2014 at 2:05 PM, Alex Taylor <Alex.Taylor@mathworks.com>wrote:

>  Hi,
>
>  I have a couple suggestions based on what you've told me.
>
>
>    1. As Luis pointed out, ITK always performs resampling in a world
>    coordinate system. You are discussing isotropic vs. non-isotropic voxels.
>    It sounds to me like in ITK you may not be working in the default pixel
>    based coordinate system and you are specifying an original and spacing with
>    your ITK images. If this is the case, you should look at the function
>    IMWARP for resampling your images:
>
> http://www.mathworks.com/help/images/ref/imwarp.html
>
>  Using IMWARP, you can specify optional spatial referencing arguments
> along with your geometric transformation. These spatial referencing
> arguments define the position of the image grid in a world coordinate
> system, and are analogous to the Spacing/Origin properties of the ITK image
> object.
>
>  http://www.mathworks.com/help/images/ref/imref3dclass.html
>
>  What I suspect is happening is that there is a difference in world units
> per pixel in your ITK images vs. your MATLAB images. If this is the case,
> you would expect that the "rotation matrix" portion of your transform would
> be consistent between ITK and MATLAB but that your translation factors
> would be off by the difference in scale in each dimension between ITK and
> MATLAB. To confirm this, you should either register your images in ITK
> using an isotropic spacing of 1 unit/pixel in all dimensions to be
> consistent with the default MATLAB coordinate system, or you should use
> IMWARP and define a world coordinate system when solving your
> registration/resampling that is consistent with the coordinate system in
> ITK.
>
>  2) I work on the Image Processing Toolbox and don't have very much
> experience at all with Neural Networks in MATLAB. I would recommend posting
> your second question to MATLAB Answers. MATLAB Answers is a very responsive
> forum and should provide you with good information:
>
>  http://www.mathworks.com/matlabcentral/answers/
>
>  *- Alex*
>
>   From: WANG Chengjia <wangchengjia1986@gmail.com>
> Date: Tuesday, February 18, 2014 11:13 PM
> To: Alex Taylor <Alex.Taylor@mathworks.com>
> Subject: Re: [Insight-users] coordinate system
>
>   Hi Alex,
>
>  Sorry to bother again, two additional questions as it is a very valuable
> chance to talk to a developer from the MathWorks.
>
>  1. Do you know how to get the same performance of Matlab function
> "interp3" in ITK so that I can control the number of slices I want to
> insert between two original slice?
>
>  2. The main reason I'm developing my present algorithm using c++
> (ITK+OpenCV) is because of training of Radial basis neural network (NN). I
> found in Matlab, to train a NN, I have to put all the inputs in one matrix,
> then the NN training goes automatically one iteration after another. But my
> problem is there are huge amount of NN inputs and I will encounter a memory
> overflow to complete the training process. So is there a way in Matlab to
> perform just one iteration of NN training?
>
>  Thank you very much for all your helps!
>
>  Best,
>
>
> On Wed, Feb 19, 2014 at 4:00 AM, WANG Chengjia <wangchengjia1986@gmail.com
> > wrote:
>
>> Hi Alex,
>>
>>  Thank you very much for fast response!
>>
>>  I'm using linear interpolation in both Matlab and ITK.  It's strange
>> that because the rotation matrix (used in transform->SetMatrix(rot)) was
>> the same in both ITK and Matlab, I only need to x/y coordinate for
>> translation (when doing trainsform->SetTranslation()) to get close result.
>>
>>  I've just realized that when I resample the data for isotropic voxels,
>> ITK produced a few more slices, which may changed the Origin of the volume.
>> Because in Matlab, the first slice in the original anisotropic volume is
>> still the first slice in the interpolated isotropic volume. But the result
>> seems that in ITK this may not be true.
>>
>>  Thank you very much!
>>
>>  Best,
>>  Chengjia
>>
>>
>>
>> On Wed, Feb 19, 2014 at 3:51 AM, Alex Taylor <Alex.Taylor@mathworks.com>wrote:
>>
>>>  Hi Wang,
>>>
>>>  I'm a developer from the MathWorks who is also familiar with ITK. The
>>> x/y transpose issue is likely due to row major vs. column major differences
>>> between MATLAB and ITK. I'd have see the corresponding matlab and ITK code
>>> to say for sure.
>>>
>>>  When you resample your images in matlab/itk, which interpolation
>>> method are you using?
>>>
>>>  Best,
>>>
>>>  Alex
>>>
>>>
>>>
>>>
>>>
>>> On Feb 18, 2014, at 10:41 PM, "WANG Chengjia" <
>>> wangchengjia1986@gmail.com> wrote:
>>>
>>>   More generally, I have a transformation matrix calculated, anyone
>>> know how to transform a volume using this matrix?
>>>
>>>  It is just a simple Rigid 3D transformation. In Matlab, I just use
>>> "tform = maketform('affine', transM');" to make up the transformation and
>>> apply it using " tformarray " then the images are perfectly aligned. But in
>>> ITK, I find I have to switch the x, y coordinate of translation when doing
>>> "targetTransform->SetTranslation(trans)". The result was still wrong,
>>> although quite close to the one I got in Matlab.
>>>
>>>  Can anyone help? Thanks in advance!
>>>
>>>  Best,
>>>
>>>
>>>
>>> On Tue, Feb 18, 2014 at 7:39 PM, WANG Chengjia <
>>> wangchengjia1986@gmail.com> wrote:
>>>
>>>> Hello,
>>>>
>>>>  I'm now working on a machine learning based 3D image registration
>>>> work. To create the ground truth registration, I need to firstly using
>>>> simple least square method to calculate a transformation from the
>>>> corresponding point (I'm using RIRE datasets).
>>>>
>>>>  The same working flow in matlab and itk produced the same
>>>> transformation matrix, but different transformed volume! In matlab, it's
>>>> well aligned using the coordinates of control points given by RIRE dataset.
>>>> But in ITK I have to inverse and switch the translation parameters. Then I
>>>> realized it's because of the different coordinate system in itk and Matlab.
>>>>
>>>>  Can anyone tell me a method to convert transformation matrix
>>>> calculated from the common coordinate system into the ITK one?
>>>>
>>>>  Thank you very much!
>>>>
>>>>  Best,
>>>>
>>>>  --
>>>> Chengjia Wang
>>>> Phd Student,
>>>> University of Edinburgh
>>>> Clinical Research Imaging Center (CRIC)
>>>> Toshiba Medical Visualization Systems Europe, Ltd
>>>> Email: wangchengjia1986@gmail.com
>>>>
>>>
>>>
>>>
>>>  --
>>> Chengjia Wang
>>> Phd Student,
>>> University of Edinburgh
>>> Clinical Research Imaging Center (CRIC)
>>> Toshiba Medical Visualization Systems Europe, Ltd
>>> Email: wangchengjia1986@gmail.com
>>>
>>>   _____________________________________
>>> Powered by www.kitware.com
>>>
>>> Visit other Kitware open-source projects at
>>> http://www.kitware.com/opensource/opensource.html
>>>
>>> Kitware offers ITK Training Courses, for more information visit:
>>> http://www.kitware.com/products/protraining.php
>>>
>>> Please keep messages on-topic and check the ITK FAQ at:
>>> http://www.itk.org/Wiki/ITK_FAQ
>>>
>>> Follow this link to subscribe/unsubscribe:
>>> http://www.itk.org/mailman/listinfo/insight-users
>>>
>>>
>>
>>
>>  --
>> Chengjia Wang
>> Phd Student,
>> University of Edinburgh
>> Clinical Research Imaging Center (CRIC)
>> Toshiba Medical Visualization Systems Europe, Ltd
>> Email: wangchengjia1986@gmail.com
>>
>
>
>
>  --
> Chengjia Wang
> Phd Student,
> University of Edinburgh
> Clinical Research Imaging Center (CRIC)
> Toshiba Medical Visualization Systems Europe, Ltd
> Email: wangchengjia1986@gmail.com
>



-- 
Chengjia Wang
Phd Student,
University of Edinburgh
Clinical Research Imaging Center (CRIC)
Toshiba Medical Visualization Systems Europe, Ltd
Email: wangchengjia1986@gmail.com

[Attachment #5 (text/html)]

<div dir="ltr">Hi all,<div><br></div><div>Thank you very much for all your \
suggestions! Just realize that ITK assuming a LPS coordinate, I need to invert all \
the image coordinate values to get right transformation matrix. Especially thanks to \
Alex and Luis&#39;s help!</div> <div><br></div><div>However, the transformed result \
is still a little wrong: I found before and after resampling the image,  the origin \
in the original image was a little shifted (centre of [0 0 0] point in original \
volume shifted to [x0, y0, z0], and this shifted value is different in upsample and \
downsample cases). What I exactly need for resampling is to have the centre of the \
origin pixel fixed.</div> <div><br></div><div>Thank you very \
much!</div><div><br></div><div>Best,</div><div><br></div><div><br></div><div><br></div></div><div \
class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Feb 19, 2014 at 2:05 PM, \
Alex Taylor <span dir="ltr">&lt;<a href="mailto:Alex.Taylor@mathworks.com" \
target="_blank">Alex.Taylor@mathworks.com</a>&gt;</span> wrote:<br> <blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex">



<div style="font-size:14px;font-family:Calibri,sans-serif;word-wrap:break-word">
<div>Hi,</div>
<div><br>
</div>
<div>I have a couple suggestions based on what you&#39;ve told me.</div>
<div><br>
</div>
<ol>
<li>As Luis pointed out, ITK always performs resampling in a world coordinate system. \
You are discussing isotropic vs. non-isotropic voxels. It sounds to me like in ITK \
you may not be working in the default pixel based coordinate system and you are \
specifying  an original and spacing with your ITK images. If this is the case, you \
should look at the function IMWARP for resampling your images:</li></ol> <div><a \
href="http://www.mathworks.com/help/images/ref/imwarp.html" \
target="_blank">http://www.mathworks.com/help/images/ref/imwarp.html</a></div> \
<div><br> </div>
<div>Using IMWARP, you can specify optional spatial referencing arguments along with \
your geometric transformation. These spatial referencing arguments define the \
position of the image grid in a world coordinate system, and are analogous to the \
Spacing/Origin  properties of the ITK image object.</div>
<div><br>
</div>
<div><a href="http://www.mathworks.com/help/images/ref/imref3dclass.html" \
target="_blank">http://www.mathworks.com/help/images/ref/imref3dclass.html</a></div> \
<div><br> </div>
<div>What I suspect is happening is that there is a difference in world units per \
pixel in your ITK images vs. your MATLAB images. If this is the case, you would \
expect that the &quot;rotation matrix&quot; portion of your transform would be \
consistent between ITK and  MATLAB but that your translation factors would be off by \
the difference in scale in each dimension between ITK and MATLAB. To confirm this, \
you should either register your images in ITK using an isotropic spacing of 1 \
unit/pixel in all dimensions to be consistent  with the default MATLAB coordinate \
system, or you should use IMWARP and define a world coordinate system when solving \
your registration/resampling that is consistent with the coordinate system in ITK. \
</div> <div><br>
</div>
<div>2) I work on the Image Processing Toolbox and don&#39;t have very much \
experience at all with Neural Networks in MATLAB. I would recommend posting your \
second question to MATLAB Answers. MATLAB Answers is a very responsive forum and \
should provide you with  good information:</div>
<div><br>
</div>
<div><a href="http://www.mathworks.com/matlabcentral/answers/" \
target="_blank">http://www.mathworks.com/matlabcentral/answers/</a></div> <div><br>
</div>
<div><u>- Alex</u></div>
<div><br>
</div>
<span>
<div style="border-right:medium \
none;padding-right:0in;padding-left:0in;padding-top:3pt;text-align:left;font-size:11pt;border-bottom:medium \
none;font-family:Calibri;border-top:#b5c4df 1pt \
solid;padding-bottom:0in;border-left:medium none">

<span style="font-weight:bold">From: </span>WANG Chengjia &lt;<a \
href="mailto:wangchengjia1986@gmail.com" \
target="_blank">wangchengjia1986@gmail.com</a>&gt;<br> <span \
style="font-weight:bold">Date: </span>Tuesday, February 18, 2014 11:13 PM<br> <span \
style="font-weight:bold">To: </span>Alex Taylor &lt;<a \
href="mailto:Alex.Taylor@mathworks.com" \
target="_blank">Alex.Taylor@mathworks.com</a>&gt;<br> <span \
style="font-weight:bold">Subject: </span>Re: [Insight-users] coordinate system<br> \
</div><div><div class="h5"> <div><br>
</div>
<div>
<div>
<div dir="ltr">Hi Alex,
<div><br>
</div>
<div>Sorry to bother again, two additional questions as it is a very valuable chance \
to talk to a developer from the MathWorks. </div> <div><br>
</div>
<div>1. Do you know how to get the same performance of Matlab function \
&quot;interp3&quot; in ITK so that I can control the number of slices I want to \
insert between two original slice?</div> <div><br>
</div>
<div>2. The main reason I&#39;m developing my present algorithm using c++ \
(ITK+OpenCV) is because of training of Radial basis neural network (NN). I found in \
Matlab, to train a NN, I have to put all the inputs in one matrix, then the NN \
training goes automatically  one iteration after another. But my problem is there are \
huge amount of NN inputs and I will encounter a memory overflow to complete the \
training process. So is there a way in Matlab to perform just one iteration of NN \
training?</div>

<div><br>
</div>
<div>Thank you very much for all your helps!</div>
<div><br>
</div>
<div>Best,</div>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Wed, Feb 19, 2014 at 4:00 AM, WANG Chengjia <span \
dir="ltr"> &lt;<a href="mailto:wangchengjia1986@gmail.com" \
target="_blank">wangchengjia1986@gmail.com</a>&gt;</span> wrote:<br> <blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"> <div dir="ltr">Hi Alex,
<div><br>
</div>
<div>Thank you very much for fast response! </div>
<div><br>
</div>
<div>I&#39;m using linear interpolation in both Matlab and ITK.  It&#39;s strange \
that because the rotation matrix (used in transform-&gt;SetMatrix(rot)) was the same \
in both ITK and Matlab, I only need to x/y coordinate for translation (when doing \
trainsform-&gt;SetTranslation())  to get close result.</div>
<div><br>
</div>
<div>I&#39;ve just realized that when I resample the data for isotropic voxels, ITK \
produced a few more slices, which may changed the Origin of the volume. Because in \
Matlab, the first slice in the original anisotropic volume is still the first slice \
in the interpolated  isotropic volume. But the result seems that in ITK this may not \
be true.</div> <div>
<div><br>
</div>
<div>Thank you very much!</div>
<div><br>
</div>
<div>Best,</div>
</div>
<span><font color="#888888">
<div>Chengjia</div>
<div><br>
</div>
</font></span></div>
<div>
<div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Wed, Feb 19, 2014 at 3:51 AM, Alex Taylor <span \
dir="ltr"> &lt;<a href="mailto:Alex.Taylor@mathworks.com" \
target="_blank">Alex.Taylor@mathworks.com</a>&gt;</span> wrote:<br> <blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"> <div dir="auto">
<div>Hi Wang,</div>
<div><br>
</div>
<div>I&#39;m a developer from the MathWorks who is also familiar with ITK. The x/y \
transpose issue is likely due to row major vs. column major differences between \
MATLAB and ITK. I&#39;d have see the corresponding matlab and ITK code to say for \
sure.</div>

<div><br>
</div>
<div>When you resample your images in matlab/itk, which interpolation method are you \
using?</div> <div><br>
</div>
<div>Best,</div>
<div><br>
</div>
<div>Alex</div>
<div>
<div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
</div>
<div><br>
On Feb 18, 2014, at 10:41 PM, &quot;WANG Chengjia&quot; &lt;<a \
href="mailto:wangchengjia1986@gmail.com" \
target="_blank">wangchengjia1986@gmail.com</a>&gt; wrote:<br> <br>
</div>
<blockquote type="cite">
<div>
<div dir="ltr">More generally, I have a transformation matrix calculated, anyone know \
how to transform a volume using this matrix?  <div><br>
</div>
<div>It is just a simple Rigid 3D transformation. In Matlab, I just use &quot;tform = \
maketform(&#39;affine&#39;, transM&#39;);&quot; to make up the transformation and \
apply it using &quot; tformarray &quot; then the images are perfectly aligned. But in \
ITK, I find I have to switch the x,  y coordinate of translation when doing \
&quot;targetTransform-&gt;SetTranslation(trans)&quot;. The result was still wrong, \
although quite close to the one I got in Matlab.</div> <div><br>
</div>
<div>Can anyone help? Thanks in advance!</div>
<div><br>
</div>
<div>Best,</div>
<div>
<div><br>
</div>
</div>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">On Tue, Feb 18, 2014 at 7:39 PM, WANG Chengjia <span \
dir="ltr"> &lt;<a href="mailto:wangchengjia1986@gmail.com" \
target="_blank">wangchengjia1986@gmail.com</a>&gt;</span> wrote:<br> <blockquote \
class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc \
solid;padding-left:1ex"> <div dir="ltr">Hello, 
<div><br>
</div>
<div>I&#39;m now working on a machine learning based 3D image registration work. To \
create the ground truth registration, I need to firstly using simple least square \
method to calculate a transformation from the corresponding point (I&#39;m using RIRE \
datasets). </div>

<div><br>
</div>
<div>The same working flow in matlab and itk produced the same transformation matrix, \
but different transformed volume! In matlab, it&#39;s well aligned using the \
coordinates of control points given by RIRE dataset. But in ITK I have to inverse and \
switch the translation  parameters. Then I realized it&#39;s because of the different \
coordinate system in itk and Matlab. </div> <div><br>
</div>
<div>Can anyone tell me a method to convert transformation matrix calculated from the \
common coordinate system into the ITK one?</div> <div><br>
</div>
<div>Thank you very much!</div>
<div><br>
</div>
<div>Best,</div>
<span><font color="#888888">
<div>
<div><br>
</div>
-- <br>
Chengjia Wang<br>
Phd Student, <br>
University of Edinburgh<br>
Clinical Research Imaging Center (CRIC)<br>
Toshiba Medical Visualization Systems Europe, Ltd<br>
Email: <a href="mailto:wangchengjia1986@gmail.com" \
target="_blank">wangchengjia1986@gmail.com</a><br> </div>
</font></span></div>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
Chengjia Wang<br>
Phd Student, <br>
University of Edinburgh<br>
Clinical Research Imaging Center (CRIC)<br>
Toshiba Medical Visualization Systems Europe, Ltd<br>
Email: <a href="mailto:wangchengjia1986@gmail.com" \
target="_blank">wangchengjia1986@gmail.com</a><br> </div>
</div>
</blockquote>
</div>
</div>
<blockquote type="cite">
<div><span>_____________________________________</span><br>
<span>Powered by <a href="http://www.kitware.com" \
target="_blank">www.kitware.com</a></span><br> <span></span><br>
<span>Visit other Kitware open-source projects at</span><br>
<span><a href="http://www.kitware.com/opensource/opensource.html" \
target="_blank">http://www.kitware.com/opensource/opensource.html</a></span><br> \
<span></span><br> <span>Kitware offers ITK Training Courses, for more information \
visit:</span><br> <span><a href="http://www.kitware.com/products/protraining.php" \
target="_blank">http://www.kitware.com/products/protraining.php</a></span><br> \
<span></span><br> <span>Please keep messages on-topic and check the ITK FAQ \
at:</span><br> <span><a href="http://www.itk.org/Wiki/ITK_FAQ" \
target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a></span><br> <span></span><br>
<span>Follow this link to subscribe/unsubscribe:</span><br>
<span><a href="http://www.itk.org/mailman/listinfo/insight-users" \
target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a></span><br> \
</div> </blockquote>
</div>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
Chengjia Wang<br>
Phd Student, <br>
University of Edinburgh<br>
Clinical Research Imaging Center (CRIC)<br>
Toshiba Medical Visualization Systems Europe, Ltd<br>
Email: <a href="mailto:wangchengjia1986@gmail.com" \
target="_blank">wangchengjia1986@gmail.com</a><br> </div>
</div>
</div>
</blockquote>
</div>
<br>
<br clear="all">
<div><br>
</div>
-- <br>
Chengjia Wang<br>
Phd Student, <br>
University of Edinburgh<br>
Clinical Research Imaging Center (CRIC)<br>
Toshiba Medical Visualization Systems Europe, Ltd<br>
Email: <a href="mailto:wangchengjia1986@gmail.com" \
target="_blank">wangchengjia1986@gmail.com</a><br> </div>
</div>
</div>
</div></div></span>
</div>

</blockquote></div><br><br clear="all"><div><br></div>-- <br>Chengjia Wang<br>Phd \
Student, <br>University of Edinburgh<br>Clinical Research Imaging Center \
(CRIC)<br>Toshiba Medical Visualization Systems Europe, Ltd<br>Email: <a \
href="mailto:wangchengjia1986@gmail.com" \
target="_blank">wangchengjia1986@gmail.com</a><br>

</div>



_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.itk.org/mailman/listinfo/insight-users


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic