Page MenuHomePhabricator

Incorrect Origin by converting mitk::Image to vtkImageData
Closed, DuplicatePublic

Description

When i load an image in VTK, convert it to mitk and convert it back, the origin gets wrong:

I have an loaded vtkImageData object:

vtkImageData* poVTKImage;
...//loading of image

//Print origin, index and size:
std::cout << "Origin: " << poVTKImage->GetOrigin()[0] << " " << poVTKImage->GetOrigin()[1] << " " << poVTKImage->GetOrigin()[2] << std::endl;

std::cout << "Index: " << poVTKImage->GetWholeExtent()[0] << " " << poVTKImage->GetWholeExtent()[2] << " " << poVTKImage->GetWholeExtent()[4] << std::endl;

std::cout << "Size: " << poVTKImage->GetWholeExtent()[1]+1 << " " << poVTKImage->GetWholeExtent()[3]+1 << " " << poVTKImage->GetWholeExtent()[5]+1 << std::endl;

//convert to mitk:

mitk::Image::Pointer oMITKImage = mitk::Image::New();

oMITKImage->Initialize(oImageReader->GetOutput()->GetImage());

oMITKImage->SetVolume(oImageReader->GetOutput()->GetImage()->GetScalarPointer());

oMITKImage->Update();

//convert back to vtk:

vtkImageData* poVTKImageFromMITKImage = oImage->GetVtkImageData();

std::cout << "Origin: " << poVTKImageFromMITKImage ->GetOrigin()[0] << " " << poVTKImageFromMITKImage ->GetOrigin()[1] << " " << poVTKImageFromMITKImage ->GetOrigin()[2] << std::endl;

std::cout << "Index: " << poVTKImageFromMITKImage ->GetWholeExtent()[0] << " " << poVTKImageFromMITKImage ->GetWholeExtent()[2] << " " << poVTKImageFromMITKImage ->GetWholeExtent()[4] << std::endl;

std::cout << "Size: " << poVTKImageFromMITKImage ->GetWholeExtent()[1]+1 << " " << poVTKImageFromMITKImage ->GetWholeExtent()[3]+1 << " " << poVTKImageFromMITKImage ->GetWholeExtent()[5]+1 << std::endl;

My cout output is:

Origin: -350.00 -358.20 -1363.50

Index: 0 0 0

Size: 512 512 181

Origin: 0.00 0.00 0.00

Index: 0 0 0

Size: 512 512 181

Origin does not match!!!!

Event Timeline

This is missing to compute the correct origin:

const mitk::Point3D& roOrigin = poMITKImage->GetSlicedGeometry()->GetGeometry2D(0)->GetOrigin();

const mitk::Vector3D& roSpacing = poMITKImage->GetSlicedGeometry()->GetGeometry2D(0)->GetSpacing();

poVTKImage->SetOrigin(roOrigin[0]/roSpacing[0],roOrigin[1]/roSpacing[1],roOrigin[2]/roSpacing[2]);

Thanks for the report, this was solved in another bug a few days ago.