World coordinate do not give me the correct dicom coordinate

Dear all,

I use itk to perform 2d segmentation of a 3d volume given by a dicom series
and i need to add some seeds with the mouse for some 2d slices. So i am
forced to show a 2d slice in vtk obtained with itk (using extractfilter) in
a vtk windows flipping the slide as it is upside down. Then i pick a point
with the mouse to choose the seeds. But i found that it does not give the
exact coordinate. At least it is different from the one given in slicer 3d.
As i need it for itk segmentation and accuracy is very important. Is there
any way to get the same coordinates fro itk and vtk?

Thanks

Slicer uses RAS world space, whereas DICOM (and hence ITK) use LPS. What DICOM calls LPS, ITK calls RAI. And you will probably need to use TransformIndexToPhysicalPoint for conversion from index space to physical space.

Hello thank you for your answer.

So once i have the point given by the mouse from vtk i have to use the TransformIndexToPhysicalPoint with the input mouse selection in vtk world coordinates to obtain the LPS space of itk?. I know this forum is only for itk but you know if vtk has the same world space than itk? And my mistake was to check 3d slicer which has a different coordinate because i used the 3d slicer to verify the coordinates? Or vtk has also a different world coordinates? If this is the case i should use

TransformIndexToPhysicalPoint to find the itk coordinate so that i can perfom the segmentation with seeds in the correct position?

Thanks again. Really helpful all your answers !!

Cheers

I don’t remember in which coordinate system (physical or index) VTK provides the point. But you should be able to find it out in VTK documentation. If it is not in index space, convert it to index space. Then use ITK’s method I linked to get to DICOM space.

Hi,

I have tried to use this function but it do not get the correct position in itk.

    using PointType = itk::Point< float, 3 >;

    PointType coordinate_vtk;
    coordinate_vtk[0] = seeds[0];    // x coordinate obtained by the mouse of the 2d slices of the 3d volume of dicom series extracted by itk::ExtractFilter
     coordinate_vtk[1] = seeds[1];   
    // y coordinate obtained by the mouse of the 2d slices of the 3d volume of dicom series extracted by itk::ExtractFilter

     coordinate_vtk[2] = sliceNumber;    
    //z coordinate obtained by the mouse of the 2d slices  of the 3d volume of dicom series extracted by itk::ExtractFilter

    typedef itk::Image< float, 3 > ImageTyper;
    ImageTyper::IndexType coordinate_itk;

    bool isInside =
        image->TransformPhysicalPointToIndex(coordinate_vtk, coordinate_itk);
    if (isInside) {

        ImageType::PixelType pixelValue = image->GetPixel(coordinate_itk);
    }

And it gives me very big value one as 30000,1500,2000 so always outside the area

Any idea?

Thanks

Sincerely

Esmeralda

Even if i do it in the slice extracted in 2d i get a wrong coordinate. And the mouse returns the world corrdinates in vtk of the mouse

typedef itk::Image< float, 2 > ImageTyper;
ImageTyper::IndexType coordinate_itk;

    bool isInside =
        extractFilter->GetOutput()->TransformPhysicalPointToIndex(coordinate_vtk, coordinate_itk);
    if (isInside) {

        ImageType::PixelType pixelValue = extractFilter->GetOutput()->GetPixel(coordinate_itk);
    }

Thanks

VTK inverts Y axis for 2D images (at least from ITK’s perspective). Can you give the numbers for coordinates at each stage of transformation? And do that for a few locations: near top left, near top right, near bottom left, near bottom right. And give us the metadata of the slice: pixel size, spacing, origin.

Note that there are several ITK-based semiautomatic segmentation tools implemented in 3D Slicer’s Segment Editor. You can implement your segmentation the same way, as a plugin for the Segment Editor module, either in Python (using SimpleITK) or in C++ (using regular ITK). This way you don’t need to worry about user interface or low level details, such as coordinate transformations between DICOM/ITK/VTK.

Here is a good example of how to create a Segment Editor effect from ITK’s watershed filter - a complete segmentation tool in 135 lines of code:

2 Likes

Dear all,

I dont want to use the slicer, i want to use my own code.

I still have the same problem.

I am going from vtk to itk so i flip the image like this.

FlipImageFilterType::Pointer flipFilter
= FlipImageFilterType::New();
flipFilter->SetInput(myitkImage);
flipFilter->SetFlipAxes(flipAxes);

But the points of the segmentation are now in itk so when i want to visualize the points with a spline are not in vtk anymore. How can i translate this itk points in vtk?.

Thanks

I have figured out that i have to flip in both axes not only y. I do not have clear the theory. i read that changing the camera you do not need the flipping.

Now i am able to get the points in both coordinates in the 3d volume extracted in slices.

Thanks

1 Like

Dear all,

I have anothr question now i have the coordinates in vtk-itk but my surprise is when i check the bounding box is smaller than the positions in 2d.

I get positions in 2d like [400,216,129] in itk and in the volume the bounding box is [0,80,0,80]. And i get the 2d slices from this volume.

Any help?

Thank you

Pixels can have spacing (distance between them) both bigger and smaller than 1.0. I assume you are talking about VTK’s bounding box?

Sure i read it wrong and it thought it was one. All working. Thank you very much !!!

1 Like