[Insight-users] Re: ITK image origin & VTK world origin

Laurent PAUL Laurent.Paul at orto.ucl.ac.be
Tue Feb 28 11:44:09 EST 2006


Dear users,

Sorry To dig up this post from 2005/04, but there is another problem which
lies with this one (I think).
When I read a dicom serie, I use the ImageSeriesReader from ITK.
Then I pass the output to VTK with a connector. That's ok!
But Image was flipped so I corrected that behavior with your
FlipImageFilter (this flipping doesn't occur with ImageFileReader from
ITK). That's ok!

The remaining problem is that it seems the volume has absolute
coordinates. I mean the coordinates come from the scanner device (or
MRI...). So, the origin looks like (-147.000, -152.000, 430.900). This is
the "Image Position Patient" tag in the dicom dictionary.
Is there any method to change the origin to the origin of my volume (so
the origin looks like "0,0,0")?

The tricky solution I have is to Get values from "Image Patient Position"
tag and shift Origin values with that ones.
Is there something easier?

Thanks.

Laurent.


>Dear Insight-users,
>
>Thank you very much for your answer. That clarified things.
>My earlier post about the origin was incorrect, ITK's origin at the top
>left, VTK's at the bottom left.
>
>A quick look at the code cleared things up.
>
>vtkPNGWriter.cxx:
>  for (ui = 0; ui < height; ui++)
>    {
>    row_pointers[height - ui - 1] = (png_byte *)outPtr;
>    outPtr = (unsigned char *)outPtr + rowInc;
>    }
>  png_write_image(png_ptr, row_pointers);
>
>itkPNGIMageIO.cxx
>  for (unsigned int ui = 0; ui < height; ui++)
>    {
>    row_pointers[ui] = (png_byte *)outPtr;
>    outPtr = const_cast<unsigned char *>(outPtr) + rowInc;
>    }
>  png_write_image(png_ptr, row_pointers);
>
>And since raw pointers are passed across by ImageToVTKFilter, flipping is
>needed.
>
>Thanks again and sorry about the confusion
>Regards
>Karthik
>
>
>Lorensen, William E (Research) wrote:
>
> Karthik,
> Your explanation of origin is reversed. ITK's first byte on disk is
> origin, y goes down. This is the natural way to represent images. vtk,
> uses the computer graphics convention. The first byte of the last row
> on disk is the first byte on memory.
> Each system has different requirements unfortunately.
>
> Users need to flip the vertical axis to get the vtk and itk images
> aligned.
>
> Bill
>
>     -----Original Message-----
>     *From:* Karthik Krishnan [mailto:Karthik.Krishnan at kitware.com]
>     *Sent:* Wednesday, April 13, 2005 11:51 AM
>     *To:* Blezek, Daniel J (Research)
>     *Cc:* Lorensen, William E (Research); Miller, James V (Research);
>     Luis Ibanez (E-mail)
>     *Subject:* Re: [Insight-users] ITK image origin & VTK world origin
>
>Hi Dan,
>
>Actually I was just pondering on the comment I just made. Frankly I am
still confused. Here is a small test and the CMakeLists.txt file. The
test just creates a box spatial object at (0,0) and another one
translated by (15,15) and writes it using an ITK writer. Then it uses the
ImageToVTKImageFilter and writes it using the vtkPNGWriter.
>
>The two images are flipped.
>
>>From the ITK Software guide which says that the origin is at the bottom
left, y axis going upwards, which I believe is correct. My understanding
is that the origin is that index which points to first location in
memory where the image is stored and since PNG writers read from the
first location and write out in a ComputerGraphics convention, they
write it out upside down. And images need to be flipped while passing
from ITK to VTK.
>
>Maybe I've got all my concepts screwed up. Please let me know.
>
>Thanks
>Regards
>karthik
>
>PS: This is last weeks build (before the OrientedImage class was added
last night, but after the change was made to the writers about flipping
on Y.)
>
>
>
>
>
>
>     Blezek, Daniel J (Research) wrote:
>
>>Karthik,  Is this documented somewhere in ITK?  I believe this is an ad
hoc standard for ITK.  If it were truely a standard, the readers would
all need to be made consistent.  As I understand it, the readers put the
first byte on disk into the first byte of the volume.
>>
>>Oriented Image will take care of this issue, and the VTK / ITK interface
will need to be looked at.
>>
>>-dan
>>
>>-----Original Message-----
>>From: insight-users-bounces at itk.org
>>[mailto:insight-users-bounces at itk.org]On Behalf Of Karthik Krishnan
>>Sent: Wednesday, April 13, 2005 9:56 AM
>>To: Frederic Perez
>>Cc: insight-users at itk.org; Andres Munarriz
>>Subject: Re: [Insight-users] ITK image origin & VTK world origin
>>
>>
>>Hi Anders,
>>
>>VTK has its image origin on the top left as in graphics and ITK has it
on the bottom left as in math. VTK +y axis points down, ITK's points up.
>>A quick look at some of the applications in InsightApplications may
help. Several applications in InsightApplications apply ITK filters and
have a VTK renderer to visualize the output.
>>
>>Here is an excerpt from
>>
>>~/work/ITK/src/InsightApplications/SegmentationEditorFltkGui/EditorFltkGui/EditorConsoleBase.cxx
>>~/work/ITK/src/InsightApplications/SegmentationEditorFltkGui/EditorFltkGui/EditorConsole.cxx
>>
>>  converter = itk::ImageToVTKImageFilter<SourceImageType>::New();
>>  flip = itk::FlipImageFilter<SourceImageType>::New();
>>
>>  SourceAxes[0] = false;
>>  SourceAxes[1] = true;
>>  SourceAxes[2] = false;
>>
>>  flip->SetFlipAxes(SourceAxes);
>>  converter->SetInput(flip->GetOutput());
>>
>>As Frederic pointed out, you may also manually set the origin by j_new =
y_siz - j which is equivalent to flipping.
>>
>>Or you could go to VTK and then flip with vtkImageFlip
>>
>>Thanks
>>Regards
>>Karthik
>>
>>
>>
>>
>>
>>
>>
>>Frederic Perez wrote:
>>
>>
>>
>>>Hello again, Andres,
>>>
>>>On 4/12/05, Andres Munarriz <munarriz.a at gmail.com> wrote:
>>>
>>>
>>>
>>>
>>>>Hi Frederic,
>>>>
>>>>Would you please elaborate on each of the terms involved in your
>>>>transformation and how to obtain them? I'm not very skillfull in
>>>>either vtk nor itk.
>>>>
>>>>
>>>>
>>>>
>>>Here we go. We've got a MetaImage file containing a CT scan. Our
>>>goal is to segment a certain anatomical structure by means of a
>>>command-line program using a region growing filter from ITK 2.0.0.
>>>That particular filter expects a seed point from which the segmented
>>>region will grow. We use the method
>>>"void SetSeed(const IndexType &seed)"---thus we need to provide
>>>an index.
>>>
>>>Now, in order to provide that seed we first visualize the MetaImage
>>>file with an interactive application on top of VTK 4.4. We use
>>>vtkImagePlaneWidget objects to query the contents of the file, and
>>>to obtain a seed index (i_vtk, j_vtk, k_vtk).
>>>
>>>Finally, providing that tuple (i_vtk, j_vtk, k_vtk) to SeedSeed didn't
>>>yield the expected results. Fortunately we found that substituting
>>>j_vtk by "imgSize[1] - j_vtk - 1" (imgSize[1] being the second
>>>component of the size of the image) we obtained what we expected.
>>>Notice that mapping from ITK indices to VTK indices is easy too
>>>(isolate j_vtk): j_vtk = imgSize[1] - j_itk - 1.
>>>
>>>I don't know if this is applicable to your particular problem.
>>>I apologize if this is not the case.
>>>
>>>Cheers,
>>>
>>>Frederic Perez
>>>_______________________________________________
>>>Insight-users mailing list
>>>Insight-users at itk.org
>>>http://www.itk.org/mailman/listinfo/insight-users
>>>
>>>
>>>
>>>
>>>
>>
>>_______________________________________________
>>Insight-users mailing list
>>Insight-users at itk.org
>>http://www.itk.org/mailman/listinfo/insight-users
>>
>>
>>
>



More information about the Insight-users mailing list