[Insight-users] creating matrix of itkImage
Luis Ibanez
luis.ibanez at kitware.com
Thu Apr 1 19:27:55 EDT 2010
Hi Michiel,
You are missing to call
imageMatrix[i]->Allocate();
The code should be:
> for( unsigned int i=0;i<2;i++){
> imageMatrix[i]= ImageType::New();
> imageMatrix[i]->SetSpacing(sp);
> imageMatrix[i]->SetOrigin(origin);
> imageMatrix[i]->SetDirection(direction);
> imageMatrix[i]->SetRegions(image->GetLargestPossibleRegion());
imageMatrix[i]->Allocate();
> }
This is described in the "Data Representation" chapter
of the ITK Software Guide
http://www.itk.org/ItkSoftwareGuide.pdf
Regards,
Luis
-------------------------------------------------------------
On Thu, Apr 1, 2010 at 10:32 AM, michiel mentink
<michael.mentink at st-hughs.ox.ac.uk> wrote:
> Hi all,
>
> I'm trying to create an array of itkImages.
>
> This is what i got so far:
>
>
>
> int numLabels = 2;
>
> ImageType::Pointer* imageMatrix = new ImageType::Pointer[numLabels];
>
> for( unsigned int i=0;i<2;i++){
> imageMatrix[i]= ImageType::New();
> imageMatrix[i]->SetSpacing(sp);
> imageMatrix[i]->SetOrigin(origin);
> imageMatrix[i]->SetDirection(direction);
>
> imageMatrix[i]->SetLargestPossibleRegion(image->GetLargestPossibleRegion());
> }
>
> ImageType::SizeType sizeOfImage2 =
> imageMatrix[0]->GetLargestPossibleRegion().GetSize();
> std::cout << "Size2 ";
> std::cout << sizeOfImage2[0] << ", " << sizeOfImage2[1] << ", " <<
> sizeOfImage2[2] << std::endl <<std::endl;
>
> // snipped a bit here that gets an indexValue of [0, 0, 0 ]
>
> typedef itk::Index<3> indexType;
> indexType blah2;
> blah2 = inputIt.GetIndex();
> std::cout << "index : " << blah2 << std::endl;
>
> image->SetPixel(blah2,128);
> imageMatrix[0]->SetPixel(blah2,128);
> std::cout << "pixel: " << image->GetPixel(blah2) << std::endl;
>
>
>
> This is my output:
>
> Size2 512, 512, 52
>
> here 2
> index : [0, 0, 0]
> Segmentation fault
>
>
>
> So basically, when I'm accessing the image volume, the program crashes.
>
> Can anybody help me with this?
>
> cheers, Michael
>
> _____________________________________
> 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.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
>
>
More information about the Insight-users
mailing list