<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello,<div><br></div><div>The problem with this code is that the reader has not been updated before you are trying to get it's output origin. Before the call:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>image->GetOrigin();</div><div><br></div><div>your should call:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>image->UpdateOutputInformation(); </div><div><br></div><div>if you just want the meta data updated. Alternatively call:</div><div><br></div><div><span class="Apple-tab-span" style="white-space:pre">        </span>image->Update();</div><div><br></div><div>if you want to execute the reader, to load the image into memory. Chapter 13 in the ITK Software Guide goes over the execution of the pipeline if you'd like to know more.</div><div><br></div><div>Brad</div><div><br><div><div>On Feb 17, 2010, at 10:55 AM, <a href="mailto:edoardo.belletti@alice.it">edoardo.belletti@alice.it</a> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">
<div>
<!-- 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>
</div>
<span><ATT00001..txt></span></blockquote></div><br><div>
<span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="3" style="font: 12.0px Helvetica">========================================================</font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="3" style="font: 12.0px Helvetica">Bradley Lowekamp<span class="Apple-converted-space"> </span><span class="Apple-converted-space"> </span></font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font class="Apple-style-span" face="Arial"><span class="Apple-style-span" style="font-family: Arial; "><span class="Apple-style-span" style="font-family: Arial; ">Lockheed Martin </span></span></font><font face="Helvetica" size="3" style="font: 12.0px Helvetica">Contractor for</font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="3" style="font: 12.0px Helvetica">Office of High Performance Computing and Communications</font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="3" style="font: 12.0px Helvetica">National Library of Medicine<span class="Apple-converted-space"> </span></font></p><p style="margin: 0.0px 0.0px 0.0px 0.0px"><font face="Helvetica" size="3" style="font: 12.0px Helvetica"><a href="mailto:blowekamp@mail.nih.gov">blowekamp@mail.nih.gov</a></font></p><br class="Apple-interchange-newline"></span></span>
</div>
<br></div></body></html>