[ITK] [ITK-users] 4D Image to Matrix inside mask
Timothee Evain
tevain at telecom-paristech.fr
Mon May 9 05:47:35 EDT 2016
Hello Javier,
About the question on pixel type, both are possible, it just depends on how you see it. But since it is for a temporal evolution of MRI image I would choose a 4D image. A 3D vector image is used to represent thing like displacement field or gradient of 3D images.
One way to do it is to iterate over your mask image and get the value where the spatial coordinates match your perfusion image:
itk::ImageRegionConstIteratorWithIndex<itk::Image<ValueType,3>> MyIterator(MaskImage,MaskImage->GetLargestPossibleRegion());
MyIterator.GoToBegin();
std::vector<std::vector<ValueType>> MyMatrix(N);//N number of ON pixels of the mask
for(int NbPix=0;NbPix<MyMatrix.size();NbPix++)//Initialize the matrix
{
std::vector<ValueType> tmp_vect(34);
MyMatrix.pushback(tmp_vect);
}
int count=0;
while(!MyIterator.IsAtEnd())
{
if (MyIterator.Get()==1)//Mask Pixel is ON
{
itk::Index<3> SpatialIndex=MyIterator.GetIndex();
for (int i=0;i<34;i++)
{
itk::Index<4> FullIndex;
FullIndex[0]=SpatialIndex[0];
FullIndex[1]=SpatialIndex[1];
FullIndex[2]=SpatialIndex[2];
FullIndex[3]=i;
MyMatrix[count][i]=PerfusionImage->GetPixel(FullIndex);
}
count++;
}
++MyIterator;
}
I've taken std::vector to do the matrix here, but you could change for the eigen matrix pretty easily if I remember well.
HTH,
Tim
----- Mail original -----
De: "Javier Juan Albarracín" <javij1 at gmail.com>
À: insight-users at itk.org
Envoyé: Jeudi 5 Mai 2016 11:48:24
Objet: [ITK] [ITK-users] 4D Image to Matrix inside mask
Hello,
I have a 4D image, which is a DSC Perfusion weighted MRI. Supose the image has the dimenisions 270x270x171x34. I want to convert this image into a Matrix of size Nx34, where N are the number of voxels inside the intracraneal mask. The Matrix class comes from Eigen library. In a classic "for loop" scheme the code would be
for (int x = 0; x < image.width(); x++)
{
for (int y = 0; y < image.height(); y++)
{
for (int z = 0; z < image.depth(); z++)
{
if (!mask(x, y, z))
continue;
for (int c = 0; c < image.spectrum(); c++)
Matrix(i, c) = image(x, y, z, c);
i++;
}
}
}
How can I do this in ITK?? I have read several ImageRegionIterator examples, but I do not find a clean and correct way to do what I want.
Thank you very much.
Regards.
Javier.
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php
Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users
_______________________________________________
Community mailing list
Community at itk.org
http://public.kitware.com/mailman/listinfo/community
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php
Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users
More information about the Community
mailing list