Dan here's my complete code.It is crashing inside the loop second time at the reader->Update().Can you or anyone please help me figure out what's wrong here? <br><br>Thanks,<br>Ashish<br>------------<br>#include "
itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br>#include "itkRescaleIntensityImageFilter.h"<br>#include "itkGDCMImageIO.h"<br>#include "itkImageRegionConstIterator.h"
<br>#include "itkImageRegionIterator.h"<br>#include "itkRegionOfInterestImageFilter.h"<br>#include "itkGDCMSeriesFileNames.h"<br>#include <list><br>#include <fstream><br>#include <vector>
<br>#include <itksys/SystemTools.hxx><br><br>using namespace std;<br> int main( int argc, char* argv[] )<br> {<br><br> typedef signed short InputPixelType;<br> const unsigned int InputDimension = 2;<br><br> typedef itk::Image< InputPixelType, InputDimension > InputImageType;
<br> typedef itk::ImageFileReader< InputImageType > ReaderType;<br><br> typedef itk::GDCMImageIO ImageIOType;<br> ImageIOType::Pointer gdcmImageIO = ImageIOType::New();<br><br> ReaderType::Pointer reader = ReaderType::New();
<br><br> typedef itk::GDCMSeriesFileNames NamesGeneratorType;<br> NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();<br> nameGenerator->SetInputDirectory( "D:\\testimages\\SRS00001" );
<br><br> typedef std::vector<std::string> FileNamesContainer;<br> FileNamesContainer fileNames = nameGenerator->GetInputFileNames();<br> unsigned int numberOfFilenames = fileNames.size();<br> std::cout << numberOfFilenames << std::endl;
<br> unsigned int fni;<br> for(fni = 0; fni<numberOfFilenames; fni++)<br> {<br> std::cout << "filename # " << fni << " = ";<br> std::cout << fileNames[fni] << std::endl;
<br> }<br> <br> typedef itk::Image<InputPixelType, InputDimension> InputImageType;<br> typedef itk::ImageRegionConstIterator< InputImageType > ConstIteratorType;<br> typedef itk::ImageRegionIterator< InputImageType > IteratorType;
<br> InputImageType::Pointer image2 = InputImageType::New();<br> typedef itk::ImageFileWriter< InputImageType > Writer1Type;<br> Writer1Type::Pointer writer1 = Writer1Type::New();<br><br> for(fni = 0; fni<numberOfFilenames; fni++)
<br> {<br> cout<<"inside for loop"<<" "<<"loop # "<<fni<<endl;<br><br> reader->SetFileName( fileNames[fni] );<br> reader->SetImageIO( gdcmImageIO );
<br> try<br> {<br> reader->Update();<br> }<br> catch (itk::ExceptionObject & e)<br> {<br> std::cerr << "exception in file reader " << std::endl;
<br> std::cerr << e << std::endl;<br> return EXIT_FAILURE;<br> }<br><br> InputImageType::Pointer image = reader->GetOutput(); <br> image2->SetRegions(image->GetRequestedRegion());
<br> image2->CopyInformation(image);<br> image2->Allocate();<br><br> ConstIteratorType in1( image, image->GetRequestedRegion() );<br><br> IteratorType out( image2, image->GetRequestedRegion() );
<br> <br> for (in1.GoToBegin(),out.GoToBegin();!in1.IsAtEnd();++in1,++out) //copy original image to new image<br> {<br> out.Set(in1.Get()); <br> }<br><br> if(fni==0)<br> writer1->SetFileName("D:\\testimages\\SRS\\IM1.dcm" );
<br> if(fni==1)<br> writer1->SetFileName("D:\\testimages\\SRS\\IM2.dcm" );<br> writer1->SetInput( image2 );<br> writer1->SetImageIO(gdcmImageIO);<br><br> try<br> {<br>
writer1->Update();<br> }<br> catch (itk::ExceptionObject & e)<br> {<br> std::cerr << "exception in file writer " << std::endl;<br> std::cerr << e << std::endl;
<br> return EXIT_FAILURE;<br> }<br> }//for loop end<br> return EXIT_SUCCESS;<br><br> }<br>--------------<br><br><div><span class="gmail_quote">On 1/11/07, <b class="gmail_sendername">Ashish Singh</b>
<<a href="mailto:mrasingh@gmail.com">mrasingh@gmail.com</a>> 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'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> <<a href="mailto:dlm19@duke.edu" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
dlm19@duke.edu</a>> 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. I ended up replacing
<br>the code with the following<br>-----------------------------------------<br>const vector<string> &fileNames = nameGenerator->GetInputFileNames();<br>-----------------------------------------<br><br>and then set the file names by calling
<br><br>---------------------------------------------<br>reader->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'm sure there is something more efficient. Try making<br>that change and let me know if it works.<br><br>Cheers,<br>Dan<br><br>Ashish Singh wrote:<br>> Thanks for replying Dan. Yes that's what it is,
<br>> reader->SetFileName(fileNames[fni]).<br>> The fname was a typo in my previous message,sorry for that. It doesn't<br>> work with<br>> reader->SetFileName(fileNames[fni])<br>><br>> The exact error message is a pop up box, titled Microsft Visual C++
<br>> debug Library. It reads-<br>> ---------<br>> Debug Assertion Failed!<br>> Program:...<br>> File: C:\program Files(x86)\Microsft Visual Studio 8\VC\include\vector<br>> Line: 756<br>><br>> Expression: vector subscript out of range
<br>><br>> For information on how your program can cause assertion failure, see<br>> the Visual C++ documentation on asserts.<br>><br>> abort-retry-ignore<br>> --------<br>><br>> Do you know what is going wrong here?
<br>><br>> Thanks,<br>> Ashish<br>><br>> On 1/11/07, *Daniel Mace* <<a href="mailto:dlm19@duke.edu" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">dlm19@duke.edu</a> <mailto:<a href="mailto:dlm19@duke.edu" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
dlm19@duke.edu</a>>> wrote:<br>>
<br>> Ashish,<br>><br>> What's the exact error message that it gives you? Also, where do you<br>> set "fname". perhaps it should be:<br>> -----------<br>> reader->SetFileName(fileNames[fni])
<br>> --------<br>> unless you set fname somewhere else in the code that isn't present.<br>><br>> Cheers,<br>> Dan<br>><br>> Ashish Singh wrote:<br>> > Hi,<br>> >
<br>> > I am a newbie to ITK. I was trying to read a set of dicom images<br>> from<br>> > a directory and then use reader->update() to process each one of<br>> them<br>> > one after the other. But the reader->update() gives me an error
<br>> after<br>> > reading the first image. Can anyone please tell me how to fix this<br>> > problem?<br>> ><br>> > This is what my code looks like. It is not the complete code,
<br>> but only<br>> > the relevant part of it.<br>> > ---------------<br>> > typedef itk::GDCMSeriesFileNames NamesGeneratorType;<br>> > NamesGeneratorType::Pointer nameGenerator =
<br>> NamesGeneratorType::New();<br>> > nameGenerator->SetInputDirectory( "D:\\testimages" );<br>> ><br>> > typedef std::vector<std::string> FileNamesContainer;
<br>> > FileNamesContainer fileNames = nameGenerator->GetInputFileNames();<br>> > unsigned int numberOfFilenames = fileNames.size();<br>> > std::cout << numberOfFilenames << std::endl;
<br>> > unsigned int fni;<br>> ><br>> > for(fni = 0; fni<numberOfFilenames; fni++)<br>> > {<br>> > std::cout << "filename # " << fni << " = ";
<br>> > std::cout << fileNames[fni] << std::endl;<br>> > }<br>> ><br>> > for(fni = 0; fni<numberOfFilenames; fni++)<br>> > {<br>> > reader->SetFileName( fname);
<br>> ><br>> > reader->SetImageIO( gdcmImageIO );<br>> ><br>> > try<br>> > {<br>> > reader->Update();//this is where it gives me an error second
<br>> > time in the loop.<br>> > }<br>> > catch (itk::ExceptionObject & e)<br>> > {<br>> > std::cerr << "exception in file reader " << std::endl;
<br>> > std::cerr << e << std::endl;<br>> > return EXIT_FAILURE;<br>> > }<br>> > // code for processing the image //<br>> > //code for writing the processed image//
<br>> > }// for loop complete<br>> > --------------------------------------<br>> > The filenames are correctly read, the code runs fine the first time<br>> > through the for loop, but second time it gives an error at the
<br>> > reader->Update() line.<br>> > Can anyone please tell me why is this happening and how to fix it?<br>> ><br>> > Thanks,<br>> > Ashish<br>> ><br>> >
<br>> ><br>> ------------------------------------------------------------------------<br>><br>> ><br>> > _______________________________________________<br>> > Insight-users mailing list
<br>> > <a href="mailto:Insight-users@itk.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Insight-users@itk.org</a> <mailto:<a href="mailto:Insight-users@itk.org" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
Insight-users@itk.org</a>><br>> > <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>> ><br>><br>><br><br></blockquote></div><br>
</span></div></blockquote></div><br>