[Insight-users] How to convert 3d image into 1D vector array......
Habib Baluwala
habibbaluwala at gmail.com
Thu May 28 09:51:11 EDT 2009
Thank you, Ivan and Victor and will try out both methods and use the
appropriate one . And again thank you for the advice.
Iván Macía wrote:
>
> Hi Victor,
>
>
>
> This is inefficient in ITK since GetPixel() provides random access to
> pixels. You should do this with image iterators.
>
>
>
> Simple example to copy pixels from one image to the other:
>
>
>
> itk::ImageRegionConstIterator<ImageType> it( image,
> image->GetRequestionRegion() ); // const version is read only
>
> itk::ImageRegionIterator<ImageType> oit( outputImage,
> image->GetRequestionRegion() ); // make sure region is the same and it is
> in
> memory
>
>
>
> it.GoToBegin();
>
> oit.GoToBegin();
>
>
>
> while( !it.IsAtEnd() )
>
> {
>
> oit.Set( it.Get() ); // copy pixel to output image
>
> ++it;
>
> ++oit;
>
> }
>
>
>
> or alternatively
>
>
>
> for( it.GoToBegin(), oit.GoToBegin(); !it.IsAtEnd(); ++it, ++oit )
>
> oit.Set( it.Get() ); // do sth with ret value
>
>
>
> All this is in the ITK Software Guide
>
>
>
> Hope that helps
>
>
>
> Iván
>
>
>
>
>
>
>
>
>
> De: insight-users-bounces at itk.org [mailto:insight-users-bounces at itk.org]
> En
> nombre de Víctor Rodrigo
> Enviado el: miércoles, 27 de mayo de 2009 20:39
> Para: insight-users at itk.org
> Asunto: Re: [Insight-users] How to convert 3d image into 1D vector
> array......
>
>
>
> Hello.
>
> I don't know if is the best option, but you can do something like this:
>
>
> ImageType::SizeType size=image->GetLargestPossibleRegion().GetSize();
> ImageType::IndexType index;
> int i=0;
> int numVox=size[0]*size[1]*size[2];
> PixelType* img=new PixelType[numVox];
> for(index[2]=0;index[2]<size[2];index[2]++) {
> for(index[1]=0;index[1]<size[1];index[1]++) {
> for(index[0]=0;index[0]<size[0];index[0]++) {
> img[i++]=image->GetPixel(index);
> }
> }
> }
>
>
>
>
>
>
> _____________________________________
> 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 ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>
--
View this message in context: http://n2.nabble.com/How-to-convert-3d-image-into-1D-vector-array......-tp2981274p2987769.html
Sent from the ITK Insight Users mailing list archive at Nabble.com.
More information about the Insight-users
mailing list