[vtkusers] Re: vtkImageReslice class

Emmanouil Moschidis moshman65 at yahoo.com
Tue Jun 26 13:20:09 EDT 2007


Hello David 

I think i got rid of all the problems (like the squeezed slices etc.) but I have some questions for you on your very first reply, since in some cases I get unexpected results or no results (empty slices). 

1) you mentioned there that the relationship between the coordinates of the input coordinate system (denoted x) and the output coordinate sytem (denoted x') is the following: x=T*M*x' , where T is ResliceTransform and M is resliceMatrix. 
 
Isn't it the other way around? Like : x'=T*M*x ...

2) In my case after registering the virtual head with the  real patient / head, I have a transformation that gives me for every point of the "Input coordinate system" or real space, the coordinates of it in the "output coordinate system" or virtual space. In that case should I set ResliceTransform to Identity? 

3) I asked this question in another thread but got no reply yet (so i thought i should ask it here as well).I am getting info regarding the rotation of the tool in quaternions. There is a method in vtkMath that gives a 3x3 rotation matrix from a quaternion. So I use the following lines of code to set up the 4x4 matrix that wiill feed the ResliceAxes with: 

vtkMath* math=vtkMath::New();
float quat3To3[3][3];
   
 float quat[4]={0,0,0,0};

quat[0]=newPosition[0];
quat[1]=newPosition[1];
quat[2]=newPosition[2];
quat[3]=newPosition[3];
math->QuaternionToMatrix3x3(quat,quat3To3); 
math->Delete();
    
    static double obliqueSliceElements[16] = {
        quat3To3[0][0], quat3To3[0][1], quat3To3[0][2], 0,
        quat3To3[1][0], quat3To3[1][1], quat3To3[1][2], 0,
        quat3To3[2][0], quat3To3[2][1], quat3To3[2][2], 0,
        0, 0, 0, 1 };

Is it correct? 

4) Is there a way to calculate the Extent of a slice produced by the reslice? It is obvious that it depends on the angle(s) in which the plane cuts the entire volume. 
But it seems tough to calculate.

Hope that wasn't too much. Thanks for the help 

David Gobbi <dgobbi at atamai.com> wrote: Hi Emmanouil,

The "squeezing" is a result of anisotropic voxels.   In your case it 
sounds like the slice spacing is much larger than the pixel spacing.  
There are a couple things that you need to be careful about:

1) When you create your vtkImageData objects, make sure that you call 
SetSpacing(xs,ys,zs) with the correct values, the third value must be 
set to the spacing between slices.

(note: if you are creating your vtkImageData objects from scratch, you 
won't have to use vtkImageImport)

2) When you use vtkImageReslice, you will probably want to call 
SetOutputSpacing(ss,ss,ss) where "ss" is the smallest voxel dimension.  
This will force vtkImageReslice to produce isotropic voxels, which 
should get rid of the squeezing that you see.

Note that (2) is not the only way to get rid of the squeezing.  If you 
display the image with vtkImageActor, then vtkImageActor will 
automatically stretch the texture to make the image look right, and in 
this case (2) will be unnecessary.

 - David



Emmanouil Moschidis wrote:
> Hello again. After reading the pixels form the memory I store every 
> image in a vtkImageData object and then I use a vtkImageAppend obbject 
> to add all the images there and thus create a volume.Then I set it as 
> input to the vtkImageReslice object(btw do i really need a vtkImport 
> object? ).
>
> However when I get the slice after the reslicing is prerformed it 
> seems it is a bit squeezed when I compare it with the orthogonal slice 
> I get from the DICOM viewer.  Is there a way of "stretching" the image 
> i get?
>
> */David Gobbi /* wrote:
>
>     Hi Emmanouil,
>
>     If you are reading DICOM files from disk, you need to use the
>     vtkDICOMImageReader instead of vtkImageReader2.
>
>     If you search the mailing list archive for "DICOM" you will
>     get lots of information (perhaps an overload) about reading
>     DICOM into VTK.
>
>     - David
>
>
>     Emmanouil Moschidis wrote:
>     > Hi again I decided to go the easy way and read from the hard
>     disk. So
>     > I get the path of the already loaded series, but I get the error
>     >
>     > Could not open file
>     > /Users/osirix/Documents/Emmanouil/MyTestImages/MRkid/05050914/.1
>     >
>     > the path is
>     /Users/osirix/Documents/Emmanouil/MyTestImages/MRkid/05050914/
>     > even when I hardcode the path i get the same result. Do you know
>     what
>     > might be wrong? (btw is the last forward slash necessary ? )
>     >
>     > */David Gobbi /* wrote:
>     >
>     > Hi Emmanouil,
>     >
>     > One thing you can do is create a vtkImageImport object for each
>     DICOM
>     > image, this will allow you to create a vtkImageData from each
>     > DICOM that
>     > you have stored in memory. Then, you can use vtkImageAppend to
>     create
>     > an image volume out of the series of images. The output of
>     > vtkImageAppend can be used by vtkImageReslice.
>     >
>     > - David
>     >
>     >
>     > Emmanouil Moschidis wrote:
>     > > Before being able to use some parts of the code I have to solve a
>     > > different problem. (I posted a new question but either it was not
>     > > quite clear or nobody has done that before (?) )
>     > >
>     > > I work within a DICOM viewer so the DICOM series are already
>     > loaded (I
>     > > do not read from a file like in case of the vtkImageReader2).
>     > Actually
>     > > every DICOM image is stored in a custom class and all together
>     in a
>     > > NSArray (yes it is objective-C). So I want to load the images
>     > from the
>     > > NSArray to the vtkImageReader2 object... I am not sure how
>     > should I do
>     > > that.
>     > >
>     > > Maybe first I need to load them into a vtkImageData object?
>     > (still I
>     > > haven't found any example for that)
>     > >
>     > > And then again I have the problem how to get the output
>     > properly. But
>     > > I guess these questions do not belong to this class.
>     > >
>     > > */David Gobbi /* wrote:
>     > >
>     > > Hi Emmanouil,
>     > >
>     > > The best example for what you are trying to do is probably
>     this one:
>     > >
>     > > VTK/Examples/ImageProcessing/Cxx/ImageSlicing.cxx
>     > >
>     > > This example is only in the CVS version of VTK, it isn't in the
>     > VTK 5
>     > > release.
>     > >
>     > > What I do with tracking systems is use the coordinate/quaternion
>     > from
>     > > the tracking system to create a vtkTransform, then I concatenate
>     > that
>     > > transform with a vtkMatrix4x4 from the patient registration, and
>     > then
>     > > feed the resulting transform to vtkImageReslice as the
>     > > ResliceTransform.
>     > >
>     > > If you have looked at the class page for vtkImageReslice, you will
>     > > notice that there are two methods for setting orientations:
>     > > SetResliceAxes() and SetResliceTransform().
>     > >
>     > > For tracking, I always set ResliceTransform to the
>     > > position/orientation
>     > > of the tool (in patient coordinates), and then set the ResliceAxes
>     > > according to how I want to orient the slice relative to
>     > > orientation of
>     > > the tool. In that way, the ResliceAxes is used to choose the tool
>     > > axes
>     > > along which you will be extracting the slice.
>     > >
>     > > The tricky thing with vtkImageReslice is getting the OutputOrigin,
>     > > OutputSpacing, and OutputExtent set properly for your application.
>     > > Together, these parameters can be used to describe an output slice
>     > > plane
>     > > with a particular pixel spacing. So for example:
>     > >
>     > > OutputOrigin = (-127.5, -127.5, 0.0)
>     > > OutputSpacing = (1.0, 1.0, 1.0)
>     > > OutputExtent = (0, 255, 0, 255, 0, 0)
>     > >
>     > > These describe a 256x256 output slice with 1mm pixel spacing. The
>     > > first
>     > > pixel is at (-127.5,-127.5,0) in the "output coordinate system" of
>     > > vtkImageReslice. The centre of the slice is at (0,0,0) in the
>     > "output
>     > > coordinate system" of vtkImageReslice.
>     > >
>     > > Now, the original input volume is in the "input coordinate
>     > system" of
>     > > vtkImageReslice. We can call the input coordinate system "x"
>     and the
>     > > output coordinate system "x'". The relationship between these
>     > > coordinates is as follows:
>     > >
>     > > x = T*M*x' where "T" is ResliceTransform and "M" is ResliceMatrix
>     > >
>     > > So this tells you that, if "M" is chosen to be a pure rotation
>     > > matrix,
>     > > and if "T" contains the position of the tool point in input image
>     > > coordinates, then the point x' = (0,0,0), which is in the centre
>     > > of our
>     > > output plane, will correspond to the point x = tool_point. So, we
>     > > will
>     > > be extracting a slice through the tool point position.
>     > >
>     > > I know that is probably not the best description, let me know if
>     > > things
>     > > aren't quite clear.
>     > >
>     > > - David
>     > >
>     > >
>     > >
>     > >
>     > > Emmanouil Moschidis wrote:
>     > > > Hello
>     > > >
>     > > > I want to use the vtkImageReslice class for reading a series of
>     > > slices
>     > > > and exctracting one slice based on coordinates and quaternions
>     > > > received from a tracking system.
>     > > >
>     > > > Is there any specific documentation and/or any working
>     > examples for
>     > > > this class? It is very powerful yet the only usable information
>     > > I have
>     > > > found is the class reference webpage.
>     > > >
>     > > > Any hint about how to proceed towards the insight of it would be
>     > > > highly appreciated
>     > > >
>     > > > thanks
>     > > >
>     > > >
>     > >
>     >
>     ------------------------------------------------------------------------
>     > > > Sick sense of humor? Visit Yahoo! TV's Comedy with an Edge
>     > > > to
>     > > > see what's on, when.
>     > > >
>     > >
>     >
>     ------------------------------------------------------------------------
>     > > >
>     > > > _______________________________________________
>     > > > This is the private VTK discussion list.
>     > > > Please keep messages on-topic. Check the FAQ at:
>     > > http://www.vtk.org/Wiki/VTK_FAQ
>     > > > Follow this link to subscribe/unsubscribe:
>     > > > http://www.vtk.org/mailman/listinfo/vtkusers
>     > > >
>     > >
>     > >
>     > >
>     >
>     ------------------------------------------------------------------------
>     > > Be a PS3 game guru.
>     > > Get your game face on with the latest PS3 news and previews at
>     > Yahoo!
>     > > Games.
>     >
>     >
>     >
>     ------------------------------------------------------------------------
>     > Yahoo! oneSearch: Finally, mobile search that gives answers
>     > ,
>     > not web links.
>
>
> ------------------------------------------------------------------------
> Luggage? GPS? Comic books?
> Check out fitting gifts for grads 
>  
> at Yahoo! Search. 



       
---------------------------------
Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more. 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070626/10cde86c/attachment.htm>


More information about the vtkusers mailing list