Re: Get voxel values from vtkNIFTIImageReader
David Gobbi <[email protected]> Mon, 25 Mar 2019 08:39:16 -0600
| Newsgroups | gmane.comp.lib.vtk.user |
|---|---|
| Message-ID | <CANwS1=GdAzWpfPLt0Tz4m6r5ueftP77R05GAE5+cN6RjS6rp9w@mail.gmail.com> |
--===============0130282132==
Content-Type: multipart/alternative; boundary="000000000000f7b19d0584ec2bac"
--000000000000f7b19d0584ec2bac
Content-Type: text/plain; charset="UTF-8"
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 <[email protected]> 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
>
--000000000000f7b19d0584ec2bac
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Hi M.,</div><div><br></div><div>It doesn't look l=
ike you are doing anything wrong, so the first thing to do is make sure the=
reader actually read the image.=C2=A0 You can ask the reader to print the =
NIfTI header:</div><div><br></div><div>=C2=A0 =C2=A0 readerVol->Update()=
;</div><div>=C2=A0 =C2=A0 readerVol->GetNIFTIHeader()->Print(std::cou=
t);</div><div><br></div><div>Likewise, you can print info about the image t=
o make sure the Extent is correct:</div><div><br></div><div>=C2=A0 =C2=A0 r=
eaderVol->GetOutput()->Print(std::cout);</div><div><br></div><div>And=
you can get the range of values stored in the image to check whether they&=
#39;re all zero:</div><div><br></div><div>=C2=A0 =C2=A0 double range[2];</d=
iv><div>=C2=A0 =C2=A0 readerVol->GetOutput()->GetPointData()->GetS=
calars()->GetRange(range);</div><div>=C2=A0 =C2=A0 std::cout << ra=
nge[0] << ", " << range[1] << std::endl;</div><=
div><br></div><div>Hope this helps,</div><div>=C2=A0 =C2=A0 David</div><br>=
<div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Mon, Ma=
r 25, 2019 at 8:18 AM M. Jordan <<a href=3D"mailto:[email protected]">mjor=
[email protected]</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding=
-left:1ex">
<div dir=3D"ltr">
<div style=3D"font-family:Calibri,Helvetica,sans-serif;font-size:12pt;color=
:rgb(0,0,0)">
Hi, <br>
<br>
I am using the vtkNIFTIImageReader to use Nifti files within VTK (e.g. for =
creating surfaces using marching cubes).<br>
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.<br>
<br>
<span>vtkSmartPointer<vtkNIFTIImageReader> readerVol =3D vtkSmartPoin=
ter<vtkNIFTIImageReader>::New();<br>
</span>
<div>readerVol->SetFileName(image.toStdString().c_str());<br>
</div>
<span>readerVol->Update();</span><br>
<br>
<span>vtkSmartPointer<vtkImageData> volume =3D vtkSmartPointer<vtk=
ImageData>:: New();<br>
</span><span>volume->DeepCopy(readerVol->GetOutput());</span><br>
<br>
float value =3D volume->GetScalarComponentAsFloat(4, 17, 52, 0);<br>
<br>
I also tried to do it like this: <a href=3D"https://vtk.org/Wiki/VTK/Exampl=
es/Cxx/ImageData/IterateImageData" id=3D"gmail-m_694450742014783349LPNoLP54=
1099" target=3D"_blank">
https://vtk.org/Wiki/VTK/Examples/Cxx/ImageData/IterateImageData</a>, but i=
t is the same.<br>
<br>
When I load the image into an external Nifti viewer, the viewer shows the e=
xpected voxel intensity for the given voxel.<br>
<br>
What I am doing wrong?<br>
<br>
Thank you very much!<br>
Regards</div></div>
</blockquote></div></div>
--000000000000f7b19d0584ec2bac--
--===============0130282132==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
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
--===============0130282132==--