[Insight-users] GetPixel problem

Robert Maroon robertmaroon@yahoo.com
Thu May 20 18:12:28 EDT 2004


Hi all,

I am currently writing an application where I input a
100x100x100 3D volume and I am simply trying to get
the value at one pixel and do a cout to see the value.


However, as soon as I call GetPixel, I get a
segmentation fault. The pixel coordinates I pass are
definitely within the bounds of the volume so I can't
see what the problem is.

I've included the code below (it is a modification of
the image3.cxx example from Examples/Data
Representation/Image), with the problematic line of
code commented.

Thanks!


#include "itkImage.h"
#include "itkImageFileReader.h"
#include <iostream>
using namespace std;

int main(int , char ** argv)
{
  int i, j, k;
  typedef unsigned char	         PixelType;
  const unsigned int             Dimension = 3;

  // First the image type should be declared
  typedef itk::Image< PixelType, Dimension >
ImageType;

  // Then the image object can be created
  ImageType::Pointer image = ImageType::New();

  // Define typedefs for the readers and writers
  typedef itk::ImageFileReader< ImageType >
ReaderType;

  // Initialize pointers for the readers and writers
  ReaderType::Pointer reader = ReaderType::New();

  reader->SetFileName( argv[0] );

  // The image region should be initialized
  ImageType::IndexType start;
  ImageType::SizeType  size;

  size[0]  = 100;  // size along X
  size[1]  = 100;  // size along Y
  size[2]  = 100;  // size along Z

  start[0] =   0;  // first index on X
  start[1] =   0;  // first index on Y
  start[2] =   0;  // first index on Z

  ImageType::RegionType region;
  region.SetSize( size );
  region.SetIndex( start );

  // Pixel data is allocated
  image->SetRegions( region );
  image->Allocate();
  image = reader->GetOutput();

  ImageType::IndexType pixelIndex;
  pixelIndex[0] = 50;
  pixelIndex[1] = 50;
  pixelIndex[2] = 9;

  /* CRASHES ON THIS LINE WITH A SEGMENTATION FAULT */
  ImageType::PixelType  pixelValue = 
                        image->GetPixel( pixelIndex );
  cout<<"Pixel Value is:"<<pixelValue<<"\n";

  return 0;

}


	
		
__________________________________
Do you Yahoo!?
Yahoo! Domains – Claim yours for only $14.70/year
http://smallbusiness.promotions.yahoo.com/offer 



More information about the Insight-users mailing list