Get voxel values from vtkNIFTIImageReader

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Get voxel values from vtkNIFTIImageReader

Tom08
Hi,

I am using the vtkNIFTIImageReader to use Nifti files within VTK (e.g. for creating surfaces using marching cubes).
Now I want to simply get the intensity of a certain voxel (e.g. 4 / 17 / 52). Nevertheless, I always get a value of zero.

vtkSmartPointer<vtkNIFTIImageReader> readerVol = vtkSmartPointer<vtkNIFTIImageReader>::New();
readerVol->SetFileName(image.toStdString().c_str());
readerVol->Update();

vtkSmartPointer<vtkImageData> volume = vtkSmartPointer<vtkImageData>:: New();
volume->DeepCopy(readerVol->GetOutput());

float value = volume->GetScalarComponentAsFloat(4, 17, 52, 0);

I also tried to do it like this: https://vtk.org/Wiki/VTK/Examples/Cxx/ImageData/IterateImageData, but it is the same.

When I load the image into an external Nifti viewer, the viewer shows the expected voxel intensity for the given voxel.

What I am doing wrong?

Thank you very much!
Regards

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers
Reply | Threaded
Open this post in threaded view
|

Re: Get voxel values from vtkNIFTIImageReader

David Gobbi
Hi M.,

It doesn't look like you are doing anything wrong, so the first thing to do is make sure the reader actually read the image.  You can ask the reader to print the NIfTI header:

    readerVol->Update();
    readerVol->GetNIFTIHeader()->Print(std::cout);

Likewise, you can print info about the image to make sure the Extent is correct:

    readerVol->GetOutput()->Print(std::cout);

And you can get the range of values stored in the image to check whether they're all zero:

    double range[2];
    readerVol->GetOutput()->GetPointData()->GetScalars()->GetRange(range);
    std::cout << range[0] << ", " << range[1] << std::endl;

Hope this helps,
    David

On Mon, Mar 25, 2019 at 8:18 AM M. Jordan <[hidden email]> wrote:
Hi,

I am using the vtkNIFTIImageReader to use Nifti files within VTK (e.g. for creating surfaces using marching cubes).
Now I want to simply get the intensity of a certain voxel (e.g. 4 / 17 / 52). Nevertheless, I always get a value of zero.

vtkSmartPointer<vtkNIFTIImageReader> readerVol = vtkSmartPointer<vtkNIFTIImageReader>::New();
readerVol->SetFileName(image.toStdString().c_str());
readerVol->Update();

vtkSmartPointer<vtkImageData> volume = vtkSmartPointer<vtkImageData>:: New();
volume->DeepCopy(readerVol->GetOutput());

float value = volume->GetScalarComponentAsFloat(4, 17, 52, 0);

I also tried to do it like this: https://vtk.org/Wiki/VTK/Examples/Cxx/ImageData/IterateImageData, but it is the same.

When I load the image into an external Nifti viewer, the viewer shows the expected voxel intensity for the given voxel.

What I am doing wrong?

Thank you very much!
Regards

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
https://vtk.org/mailman/listinfo/vtkusers