<div style="background-color:rgb(255,255,255)"><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px">Hello,</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px">
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px">I am facing problem in writing the image. I have written this code for writing</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px">
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px">Here </div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px">enFaceImageType is:</div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px"><br></div><div><font color="#222222" face="arial, sans-serif">typedef float EnFacePixelType;<span class="Apple-tab-span" style="white-space:pre">        </span></font></div>
<div><font color="#222222" face="arial, sans-serif">typedef itk::Image< EnFacePixelType, 2 > enFaceImageType;</font></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px">
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px">int writeImage( const string &sFileName, const enFaceImageType::Pointer &enFaceImage )</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px">
{</div></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px;background-color:rgb(255,255,255)"><span style="white-space:pre-wrap">        </span>// Define the image to be written to be of type unsigned char:</div>
<div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px;background-color:rgb(255,255,255)"><div><span style="white-space:pre-wrap">        </span>typedef unsigned char<span style="white-space:pre-wrap">        </span>WritePixelType;</div>
<div><span style="white-space:pre-wrap">        </span>const unsigned int<span style="white-space:pre-wrap">        </span>Dimension = 2;</div><div><span style="white-space:pre-wrap">        </span>typedef itk::Image<WritePixelType, Dimension> WriteImageType;</div>
<div><br></div><div><span style="white-space:pre-wrap">        </span>// Rescaling image for writing:</div><div><span style="white-space:pre-wrap">        </span>typedef itk::RescaleIntensityImageFilter<enFaceImageType,WriteImageType > RescaleFilter;</div>
<div><span style="white-space:pre-wrap">        </span>RescaleFilter::Pointer rescale = RescaleFilter::New();</div><div><span style="white-space:pre-wrap">        </span>// Set the scale range:</div><div><span style="white-space:pre-wrap">        </span>rescale->SetOutputMinimum( 0 );</div>
<div><span style="white-space:pre-wrap">        </span>rescale->SetOutputMaximum( 255 );</div><div><span style="white-space:pre-wrap">        </span>rescale->SetInput( enFaceImage );</div><div><br></div><div><span style="white-space:pre-wrap">        </span>typedef itk::ImageFileWriter< WriteImageType > newWriterType;</div>
<div><span style="white-space:pre-wrap">        </span>newWriterType::Pointer imageWriter = newWriterType::New();</div><div><span style="white-space:pre-wrap">        </span>imageWriter->SetInput( rescale->GetOutput() );</div><div>
<span style="white-space:pre-wrap">        </span>imageWriter->SetFileName( sFileName.c_str() );</div><div><span style="white-space:pre-wrap">        </span>try {</div><div><span style="white-space:pre-wrap">                </span>imageWriter->Update();</div>
<div><span style="white-space:pre-wrap">        </span>}</div><div><span style="white-space:pre-wrap">        </span>catch( itk::ExceptionObject & err ) { </div><div> <span style="white-space:pre-wrap">        </span>std::cout << "ExceptionObject caught !" << std::endl; </div>
<div> <span style="white-space:pre-wrap">        </span>std::cout << err << std::endl; </div><div> <span style="white-space:pre-wrap">        </span>return -1;</div><div> <span style="white-space:pre-wrap">        </span>}</div>
<div><span style="white-space:pre-wrap">        </span>cout << "writeEnFaceImage(): Successfully wrote to " << sFileName << "!" << endl;</div><div><span style="white-space:pre-wrap">        </span>return EXIT_SUCCESS;</div>
<div>}</div></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px;background-color:rgb(255,255,255)">
Crash is happening in Update() call. I traced the call stack, the site of crash is: </div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px;background-color:rgb(255,255,255)"><br>
</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px;background-color:rgb(255,255,255)"><div>ImageIOBase::Pointer ImageIOFactory::CreateImageIO(const char* path, FileModeType mode)</div>
<div>{</div><div><br></div><div> RegisterBuiltInFactories();</div><div><br></div><div> std::list<ImageIOBase::Pointer> possibleImageIO;</div><div> std::list<LightObject::Pointer> allobjects = ObjectFactoryBase::CreateAllInstance("itkImageIOBase"); -----> this call </div>
</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px;background-color:rgb(255,255,255)">...</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px;background-color:rgb(255,255,255)">
.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px;background-color:rgb(255,255,255)"><br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px;background-color:rgb(255,255,255)">
.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px;background-color:rgb(255,255,255)">.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px;background-color:rgb(255,255,255)">
.</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px;background-color:rgb(255,255,255)">}</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px;background-color:rgb(255,255,255)">
<br></div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px;background-color:rgb(255,255,255)">This call return allobjects [0] = { m_pointer = ??? }</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px;background-color:rgb(255,255,255)">
I think it is not creating any instance of "itkImageIOBase" so no memory is allocated to write data. What could be the possible reason for this ?</div><div style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:12.727272033691406px;background-color:rgb(255,255,255)">
<br></div><div>Error I am getting is - </div><div><br></div><div><div>First-chance exception at 0x0d69c2b0 (CI.SD.Algorithms.dll) in ProcessInvocation86.exe: 0xC0000005: Access violation reading location 0x0000000f.</div>
<div>A first chance exception of type 'System.AccessViolationException' occurred in CI.SD.Algorithms.dll</div><div>An exception of type 'System.AccessViolationException' occurred in CI.SD.Algorithms.dll</div>
<div><br></div><div>Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.</div><div>The thread 'Win32 Thread' (0x1454) has exited with code 0 (0x0).</div>
</div><div><br></div><div><br></div><div><br></div><div><br></div>-- <br><span style="font-family:georgia,serif">Thanks & Regards,<br>- - -<br><br>Amit Suveer </span><font face="georgia, serif"><br><br></font>