Dan here&#39;s my complete code.It is crashing inside the loop second time at the reader-&gt;Update().Can you or anyone please help me figure out what&#39;s wrong&nbsp; here? <br><br>Thanks,<br>Ashish<br>------------<br>#include &quot;
itkImageFileReader.h&quot;<br>#include &quot;itkImageFileWriter.h&quot;<br>#include &quot;itkRescaleIntensityImageFilter.h&quot;<br>#include &quot;itkGDCMImageIO.h&quot;<br>#include &quot;itkImageRegionConstIterator.h&quot;
<br>#include &quot;itkImageRegionIterator.h&quot;<br>#include &quot;itkRegionOfInterestImageFilter.h&quot;<br>#include &quot;itkGDCMSeriesFileNames.h&quot;<br>#include &lt;list&gt;<br>#include &lt;fstream&gt;<br>#include &lt;vector&gt;
<br>#include &lt;itksys/SystemTools.hxx&gt;<br><br>using namespace std;<br>&nbsp;int main( int argc, char* argv[] )<br>&nbsp;{<br><br>&nbsp; typedef signed short InputPixelType;<br>&nbsp; const unsigned int&nbsp;&nbsp; InputDimension = 2;<br><br>&nbsp; typedef itk::Image&lt; InputPixelType, InputDimension &gt; InputImageType;
<br>&nbsp; typedef itk::ImageFileReader&lt; InputImageType &gt; ReaderType;<br><br>&nbsp; typedef itk::GDCMImageIO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ImageIOType;<br>&nbsp; ImageIOType::Pointer gdcmImageIO = ImageIOType::New();<br><br>&nbsp; ReaderType::Pointer reader = ReaderType::New();
<br><br>&nbsp; typedef itk::GDCMSeriesFileNames NamesGeneratorType;<br>&nbsp; NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();<br>&nbsp; nameGenerator-&gt;SetInputDirectory( &quot;D:\\testimages\\SRS00001&quot;&nbsp; );
<br><br>&nbsp; typedef std::vector&lt;std::string&gt; FileNamesContainer;<br>&nbsp; FileNamesContainer fileNames = nameGenerator-&gt;GetInputFileNames();<br>&nbsp; unsigned int numberOfFilenames =&nbsp; fileNames.size();<br>&nbsp; std::cout &lt;&lt; numberOfFilenames &lt;&lt; std::endl; 
<br>&nbsp; unsigned int fni;<br>&nbsp; for(fni = 0; fni&lt;numberOfFilenames; fni++)<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; &quot;filename # &quot; &lt;&lt; fni &lt;&lt; &quot; = &quot;;<br>&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; fileNames[fni] &lt;&lt; std::endl;
<br>&nbsp; }<br>&nbsp;<br>&nbsp;typedef itk::Image&lt;InputPixelType, InputDimension&gt; InputImageType;<br>&nbsp;typedef itk::ImageRegionConstIterator&lt; InputImageType &gt; ConstIteratorType;<br>&nbsp;typedef itk::ImageRegionIterator&lt; InputImageType &gt; IteratorType;
<br>&nbsp;InputImageType::Pointer image2 = InputImageType::New();<br>&nbsp;typedef itk::ImageFileWriter&lt; InputImageType &gt;&nbsp; Writer1Type;<br>&nbsp;Writer1Type::Pointer writer1 = Writer1Type::New();<br><br>&nbsp; for(fni = 0; fni&lt;numberOfFilenames; fni++)
<br>&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp; cout&lt;&lt;&quot;inside for loop&quot;&lt;&lt;&quot; &quot;&lt;&lt;&quot;loop # &quot;&lt;&lt;fni&lt;&lt;endl;<br><br>&nbsp;&nbsp;&nbsp; &nbsp; reader-&gt;SetFileName( fileNames[fni] );<br>&nbsp;&nbsp;&nbsp; &nbsp; reader-&gt;SetImageIO( gdcmImageIO );
<br>&nbsp;&nbsp;&nbsp; &nbsp; try<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; reader-&gt;Update();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp; catch (itk::ExceptionObject &amp; e)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; &quot;exception in file reader &quot; &lt;&lt; std::endl;
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; e &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return EXIT_FAILURE;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; &nbsp;InputImageType::Pointer image = reader-&gt;GetOutput();&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;image2-&gt;SetRegions(image-&gt;GetRequestedRegion());
<br>&nbsp;&nbsp;&nbsp; &nbsp;image2-&gt;CopyInformation(image);<br>&nbsp;&nbsp;&nbsp; &nbsp;image2-&gt;Allocate();<br><br>&nbsp;&nbsp;&nbsp; &nbsp;ConstIteratorType in1( image, image-&gt;GetRequestedRegion() );<br><br>&nbsp;&nbsp;&nbsp; &nbsp;IteratorType out( image2, image-&gt;GetRequestedRegion() );
<br>&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp; &nbsp;for (in1.GoToBegin(),out.GoToBegin();!in1.IsAtEnd();++in1,++out) //copy original image to new image<br>&nbsp;&nbsp;&nbsp; &nbsp;{<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; out.Set(in1.Get());&nbsp;&nbsp;&nbsp; &nbsp;<br>&nbsp;&nbsp;&nbsp; &nbsp;}<br><br>&nbsp;&nbsp;&nbsp; &nbsp; if(fni==0)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; writer1-&gt;SetFileName(&quot;D:\\testimages\\SRS\\IM1.dcm&quot; );
<br>&nbsp;&nbsp;&nbsp; &nbsp; if(fni==1)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; writer1-&gt;SetFileName(&quot;D:\\testimages\\SRS\\IM2.dcm&quot; );<br>&nbsp;&nbsp;&nbsp; &nbsp; writer1-&gt;SetInput( image2 );<br>&nbsp;&nbsp;&nbsp; &nbsp; writer1-&gt;SetImageIO(gdcmImageIO);<br><br>&nbsp;&nbsp;&nbsp; &nbsp; try<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; writer1-&gt;Update();<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; &nbsp; catch (itk::ExceptionObject &amp; e)<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; &quot;exception in file writer &quot; &lt;&lt; std::endl;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; e &lt;&lt; std::endl;
<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return EXIT_FAILURE;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp; }//for loop end<br>&nbsp;&nbsp;&nbsp; return EXIT_SUCCESS;<br><br>&nbsp;}<br>--------------<br><br><div><span class="gmail_quote">On 1/11/07, <b class="gmail_sendername">Ashish Singh</b>
 &lt;<a href="mailto:mrasingh@gmail.com">mrasingh@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Thanks Dan. I tried this. It still doesn&#39;t 
work.Now I get an unhandled exception at 0x00406515 in my exe file.<div><span class="e" id="q_11012fcc5e4f57fe_1"><br><br><div><span class="gmail_quote">On 1/11/07, <b class="gmail_sendername">Daniel Mace</b> &lt;<a href="mailto:dlm19@duke.edu" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">

dlm19@duke.edu</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Ashish,<br><br>I think I ran into the same problem a while ago.&nbsp;&nbsp;I ended up replacing
<br>the code with the following<br>-----------------------------------------<br>const vector&lt;string&gt; &amp;fileNames =&nbsp;&nbsp;nameGenerator-&gt;GetInputFileNames();<br>-----------------------------------------<br><br>and then set the file names by calling
<br><br>---------------------------------------------<br>reader-&gt;SetFileName( fileNames[i].c_str());<br>---------------------------------------------<br><br>More of a quick fix for me (as I was returning to C++ after an 8 year
<br>hiatus), and I&#39;m sure there is something more efficient.&nbsp;&nbsp;Try making<br>that change and let me know if it works.<br><br>Cheers,<br>Dan<br><br>Ashish Singh wrote:<br>&gt; Thanks for replying Dan. Yes that&#39;s what it is,
<br>&gt; reader-&gt;SetFileName(fileNames[fni]).<br>&gt; The fname was a typo in my previous message,sorry for that. It doesn&#39;t<br>&gt; work with<br>&gt; reader-&gt;SetFileName(fileNames[fni])<br>&gt;<br>&gt; The exact error message is a pop up box, titled Microsft Visual C++
<br>&gt; debug Library. It reads-<br>&gt; ---------<br>&gt; Debug Assertion Failed!<br>&gt; Program:...<br>&gt; File: C:\program Files(x86)\Microsft Visual Studio 8\VC\include\vector<br>&gt; Line: 756<br>&gt;<br>&gt; Expression: vector subscript out of range
<br>&gt;<br>&gt; For information on how your program can cause assertion failure, see<br>&gt; the Visual C++ documentation on asserts.<br>&gt;<br>&gt; abort-retry-ignore<br>&gt; --------<br>&gt;<br>&gt; Do you know what is going wrong here?
<br>&gt;<br>&gt; Thanks,<br>&gt; Ashish<br>&gt;<br>&gt; On 1/11/07, *Daniel Mace* &lt;<a href="mailto:dlm19@duke.edu" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">dlm19@duke.edu</a> &lt;mailto:<a href="mailto:dlm19@duke.edu" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
dlm19@duke.edu</a>&gt;&gt; wrote:<br>&gt;
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Ashish,<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; What&#39;s the exact error message that it gives you?&nbsp;&nbsp;Also, where do you<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; set &quot;fname&quot;.&nbsp;&nbsp;perhaps it should be:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; -----------<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; reader-&gt;SetFileName(fileNames[fni])
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; --------<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; unless you set fname somewhere else in the code that isn&#39;t present.<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Cheers,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Dan<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; Ashish Singh wrote:<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; Hi,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; I am a newbie to ITK. I was trying to read a set of dicom images<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; from<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; a directory and then use reader-&gt;update() to process each one of<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; them<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; one after the other. But the reader-&gt;update() gives me an error
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; after<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; reading the first image. Can anyone please tell me how to fix this<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; problem?<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; This is what my code looks like. It is not the complete code,
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; but only<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; the relevant part of it.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; ---------------<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp; typedef itk::GDCMSeriesFileNames NamesGeneratorType;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp; NamesGeneratorType::Pointer nameGenerator =
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; NamesGeneratorType::New();<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp; nameGenerator-&gt;SetInputDirectory( &quot;D:\\testimages&quot;&nbsp;&nbsp;);<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp; typedef std::vector&lt;std::string&gt; FileNamesContainer;
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp; FileNamesContainer fileNames = nameGenerator-&gt;GetInputFileNames();<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp; unsigned int numberOfFilenames =&nbsp;&nbsp;fileNames.size();<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp; std::cout &lt;&lt; numberOfFilenames &lt;&lt; std::endl;
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp; unsigned int fni;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp; for(fni = 0; fni&lt;numberOfFilenames; fni++)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; &quot;filename # &quot; &lt;&lt; fni &lt;&lt; &quot; = &quot;;
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp; std::cout &lt;&lt; fileNames[fni] &lt;&lt; std::endl;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp; for(fni = 0; fni&lt;numberOfFilenames; fni++)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp; {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp; reader-&gt;SetFileName( fname);
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp; reader-&gt;SetImageIO( gdcmImageIO );<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp; try<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reader-&gt;Update();//this is where it gives me an error second
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; time in the loop.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp; catch (itk::ExceptionObject &amp; e)<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; &quot;exception in file reader &quot; &lt;&lt; std::endl;
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp; std::cerr &lt;&lt; e &lt;&lt; std::endl;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp; return EXIT_FAILURE;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; // code for processing the image //<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; //code for writing the processed image//
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; }// for loop complete<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; --------------------------------------<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; The filenames are correctly read, the code runs fine the first time<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; through the for loop, but second time it gives an error at the
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; reader-&gt;Update() line.<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; Can anyone please tell me why is this happening and how to fix it?<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; Thanks,<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; Ashish<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; ------------------------------------------------------------------------<br>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; _______________________________________________<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; Insight-users mailing list
<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; <a href="mailto:Insight-users@itk.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Insight-users@itk.org</a> &lt;mailto:<a href="mailto:Insight-users@itk.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
Insight-users@itk.org</a>&gt;<br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt; <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://www.itk.org/mailman/listinfo/insight-users</a><br>&gt;&nbsp;&nbsp;&nbsp;&nbsp; &gt;<br>&gt;<br>&gt;<br><br></blockquote></div><br>

</span></div></blockquote></div><br>