[Insight-users] Image to world coordinates
Vincent Garcia
Vincent.Garcia at sophia.inria.fr
Wed Jun 30 09:39:13 EDT 2010
Dženan,
Let I be an itk::Image. From this image, you can get these following
information:
- GetOrigin () : position of the first voxel (origin) in the world
coordinates (vector denoted O)
- GetSpacing () : size of the voxels in mm (vector denoted S)
- GetDirection () : direction cosine (square matrix denoted D)
A diagonal matrix (let's say S2) is built using the values of the vector S.
So, given some image coordinates (i,j,k)^T (for a 3D image).
The world coordinates (x,y,z)^T are computed as follow :
(x,y,z)^T = D * S2 * (i,j,k)^T + O
As you can see, it's just a simple matrix multiplication and addition.
Similarly, the image coordinates are obtained from the world coordinates
as follows:
(i,j,k)^T = ( D * S2 )^(-1) * ((x,y,z)^T - O)
This is what I understood from the code and I think that it's correct.
However, this kind of thing should be explained somewhere (programming
guide or whatever).
Moreover, a old ITK webpage using the notion of "direction cosine" is a
bit confusing (since it was a proposal).
The formula presented in this webpage are different from the one used in
the ITK code...
I hope this will help!
Regards,
Vincent Garcia
Dan Mueller wrote:
> Hi Dženan
>
> For an unobfuscated formula, you can check the CVS archive:
> http://www.itk.org/cgi-bin/viewcvs.cgi/Code/Common/itkImage.h?revision=1.143&root=Insight&view=markup
>
> HTH
>
> Cheers, Dan
>
> 2010/6/30 Dženan Zukić <dzenanz at gmail.com>:
>
>> Yes, I am interested in a plain formula for those conversions. The code in
>> ITK is very convoluted - optimized for performance not for clarity.
>> Dženan
>>
>> On Mon, Jun 28, 2010 at 15:08, Vincent Garcia
>> <Vincent.Garcia at sophia.inria.fr> wrote:
>>
>>> Thank you. The only problem here is that you have to check the source code
>>> to interpret the origin, spacing, and direction cosine value.
>>> It should be written into the programming guide, or at least somewhere.
>>> When you know the correct formula, the answer is straight forward.
>>> I'll try to write something about that in a next email if anyone wants to
>>> know the answer to my question.
>>> One more time, thank you!
>>>
>>> Vincent
>>>
>>>
>>> Dan Mueller wrote:
>>>
>>>> Hi Vincent,
>>>>
>>>> The following will convert an index in "image" coordinates to a
>>>> physical point in "world" coordinates:
>>>> image->TransformIndexToPhysicalPoint( index, point );
>>>>
>>>> This function is specified in Common/itkImageBase.h
>>>>
>>>> HTH
>>>>
>>>> Cheers, Dan
>>>>
>>>> On 28 June 2010 09:48, Vincent Garcia <Vincent.Garcia at sophia.inria.fr>
>>>> wrote:
>>>>
>>>>
>>>>> Hi all,
>>>>>
>>>>> When you read a medical image (let's say 3D), you have a 3D matrix
>>>>> containing image data and some information about the
>>>>> position/orientation of
>>>>> the image in the world coordinates. Given the image coordinates (i,j,k),
>>>>> I'd
>>>>> like to understand how to compute the corresponding world coordinates
>>>>> (x,y,z).
>>>>> I have access to some information from the itk::Image object:
>>>>>
>>>>> GetOrigin () : (vector) position of the first voxel in the world
>>>>> coordinates
>>>>> GetSpacing () : (vector) size of the voxels in mm
>>>>> GetDirection () : (matrix) direction cosine
>>>>>
>>>>> I've tried to search on the documentation but I haven't found the way to
>>>>> use
>>>>> these vectors and matrix to compute the world coordinates.
>>>>> The formula should be very simple but I just can't found it.
>>>>>
>>>>> Many thanks,
>>>>>
>>>>> Vincent Garcia
>>>>>
More information about the Insight-users
mailing list