[vtkusers] Get voxel values from vtkNIFTIImageReader

David Gobbi david.gobbi at gmail.com
Mon Mar 25 10:39:16 EDT 2019


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 <mjordan at live.at> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20190325/7e70ad99/attachment.html>


More information about the vtkusers mailing list