VTK - How to read Tensors/Matrix per cell from a NIFTI Image?

﹥>﹥吖頭↗ 提交于 2019-12-12 03:46:47

问题


I'm trying to implement a MRT-DTI real-time fibertracking visualization tool based on VTK. Therefore we need to read the DTI tensors/matrices per cell stored in a NIFTI Image (.nii) and I really can't figure out how to do this.

It's not a problem to retrieve a single scalar value from the NIFTI file, but I don't know how to get the tensor (3x3/4x4 matrix). We would really appreciate any help !

Since the NIFTIImageReader is supposed to read a tensor NIFTI image as a multi-component vtkImage we tried this:

  vtkSmartPointer<vtkImageExtractComponents> extractTupel1 = vtkSmartPointer<vtkImageExtractComponents>::New();
  extractTupel1->SetInputConnection(reader->GetOutputPort());
  extractTupel1->SetComponents(0,1,2);
  extractTupel1->Update();

  vtkSmartPointer<vtkImageExtractComponents> extractTupel2 = vtkSmartPointer<vtkImageExtractComponents>::New();
  extractTupel2->SetInputConnection(reader->GetOutputPort());
  extractTupel2->SetComponents(3, 4, 5);
  extractTupel2->Update();

  vtkSmartPointer<vtkImageExtractComponents> extractTupel3 = vtkSmartPointer<vtkImageExtractComponents>::New();
  extractTupel3->SetInputConnection(reader->GetOutputPort());
  extractTupel3->SetComponents(6, 7, 8);
  extractTupel3->Update();


  extractTupel1->GetOutput()->GetPoint(pointId, tupel1);
  extractTupel2->GetOutput()->GetPoint(pointId, tupel2);
  extractTupel3->GetOutput()->GetPoint(pointId, tupel3);

But it doesn't work. Maybe the GetPoint-Method is the wrong choice? Please help :)


回答1:


Answer by David Gobbi, really much thanks to him!:

No, the GetPoint() method will not return the tensor value. It will return the coordinates of the voxel. So vtkImageExtractComponents is not necessary here, either.

A vtkImageData always stores the voxel values as its "Scalars" array, even if the voxel values are not scalar quantities.

A simple (but inefficient way) to get the scalar values is this method:

GetScalarComponentAsDouble (int x, int y, int z, int component)

For each voxel, you would call this method 9 times with component = [0..8].

A much more efficient way of getting the tensors is to get the scalar array from the data, and then look up the tensors via the pointId:

reader->Update(); vtkDataArray *tensors = reader->GetOutput()->GetPointData()->GetScalars(); double tensor[9]; tensors->GetTuple(pointId, tensor);

This is orders of magnitude more efficient than GetScalarComponentAsDouble().



来源:https://stackoverflow.com/questions/32137726/vtk-how-to-read-tensors-matrix-per-cell-from-a-nifti-image

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!