[Insight-users] Problem with GetPixel
edoardo.belletti at alice.it
edoardo.belletti at alice.it
Wed Feb 17 10:55:53 EST 2010
Hi
I have a problem with this program, when I run it the output is that:
Segmentation fault
The problem is with GetPixel I suppose.
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#ifdef __BORLANDC__
#define ITK_LEAN_AND_MEAN
#endif
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
int main( int argc, char ** argv )
{
// Verify the number of parameters in the command line
if( argc < 3 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " inputImageFile outputImageFile " << std::endl;
return EXIT_FAILURE;
}
typedef unsigned char PixelType;
const unsigned int Dimension = 2;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::ImageFileReader< ImageType > ReaderType;
typedef itk::ImageFileWriter< ImageType > WriterType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
const char * inputFilename = argv[1];
const char * outputFilename = argv[2];
reader->SetFileName( inputFilename );
writer->SetFileName( outputFilename );
ImageType::Pointer image = reader->GetOutput();
const ImageType::PointType& orgn = image->GetOrigin();
std::cout << "Origin = ";
std::cout << orgn[0] << ", " << orgn[1] << std::endl;
ImageType::IndexType pixelIndex;
pixelIndex[0] = 27; // x position
pixelIndex[1] = 29; // y position
std::cout << "x position: " << pixelIndex[0] << "\ny position: " << pixelIndex[1] << std::endl;
ImageType::PixelType pixelValue = image->GetPixel(pixelIndex);
std::cout << "valore pixel: " << pixelValue << std::endl;
image->SetPixel( pixelIndex, pixelValue+1 );
writer->SetInput( image );
try
{
writer->Update();
}
catch( itk::ExceptionObject & err )
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Thanks
Edoardo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100217/cb3fcc93/attachment.htm>
More information about the Insight-users
mailing list