<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7655.8">
<TITLE> Problem with GetPixel</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->
<BR>
<P><FONT SIZE=2><BR>
Hi<BR>
I have a problem with this program, when I run it the output is that:<BR>
Segmentation fault<BR>
<BR>
The problem is with GetPixel I suppose.<BR>
<BR>
#if defined(_MSC_VER)<BR>
#pragma warning ( disable : 4786 )<BR>
#endif<BR>
<BR>
#ifdef __BORLANDC__<BR>
#define ITK_LEAN_AND_MEAN<BR>
#endif<BR>
<BR>
<BR>
#include "itkImage.h"<BR>
#include "itkImageFileReader.h"<BR>
#include "itkImageFileWriter.h"<BR>
<BR>
<BR>
int main( int argc, char ** argv )<BR>
{<BR>
// Verify the number of parameters in the command line<BR>
if( argc < 3 )<BR>
{<BR>
std::cerr << "Usage: " << std::endl;<BR>
std::cerr << argv[0] << " inputImageFile outputImageFile " << std::endl;<BR>
return EXIT_FAILURE;<BR>
}<BR>
<BR>
typedef unsigned char PixelType;<BR>
const unsigned int Dimension = 2;<BR>
typedef itk::Image< PixelType, Dimension > ImageType;<BR>
<BR>
typedef itk::ImageFileReader< ImageType > ReaderType;<BR>
typedef itk::ImageFileWriter< ImageType > WriterType;<BR>
<BR>
ReaderType::Pointer reader = ReaderType::New();<BR>
WriterType::Pointer writer = WriterType::New();<BR>
<BR>
const char * inputFilename = argv[1];<BR>
const char * outputFilename = argv[2];<BR>
<BR>
reader->SetFileName( inputFilename );<BR>
writer->SetFileName( outputFilename );<BR>
<BR>
ImageType::Pointer image = reader->GetOutput();<BR>
<BR>
const ImageType::PointType& orgn = image->GetOrigin();<BR>
std::cout << "Origin = ";<BR>
std::cout << orgn[0] << ", " << orgn[1] << std::endl;<BR>
<BR>
ImageType::IndexType pixelIndex;<BR>
<BR>
pixelIndex[0] = 27; // x position<BR>
pixelIndex[1] = 29; // y position<BR>
std::cout << "x position: " << pixelIndex[0] << "\ny position: " << pixelIndex[1] << std::endl;<BR>
<BR>
<BR>
ImageType::PixelType pixelValue = image->GetPixel(pixelIndex);<BR>
<BR>
std::cout << "valore pixel: " << pixelValue << std::endl;<BR>
<BR>
image->SetPixel( pixelIndex, pixelValue+1 );<BR>
<BR>
<BR>
writer->SetInput( image );<BR>
<BR>
try<BR>
{<BR>
writer->Update();<BR>
}<BR>
catch( itk::ExceptionObject & err )<BR>
{<BR>
std::cerr << "ExceptionObject caught !" << std::endl;<BR>
std::cerr << err << std::endl;<BR>
return EXIT_FAILURE;<BR>
}<BR>
<BR>
return EXIT_SUCCESS;<BR>
}<BR>
<BR>
<BR>
<BR>
Thanks<BR>
Edoardo<BR>
</FONT>
</P>
</BODY>
</HTML>