Thanks Dan. I tried this one also, still doesn't work. If I comment the
writer1->Update() line, it goes through the for loop(the code works then, but I want to be able to write the files).Or even if I
read the same image again and again in the loop, it works.<br><br><div><span class="gmail_quote">On 1/11/07, <b class="gmail_sendername">Daniel Mace</b> <<a href="mailto:dlm19@duke.edu">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>The assertion errors tend to pop up (only/more often) with windows<br>machines for some reason, so they are odd bugs to track down. I could
<br>be wrong, but I'm not entirely sure that your image file has set its<br>region settings correctly. Just to make sure, after the line<br>-----------------<br>InputImageType::Pointer image = reader->GetOutput();
<br>-----------------<br><br>add in a<br>-----------------<br>image->Update()<br>----------------<br><br>Just to make sure that the image->GetRequestedRegion() actually returns<br>a valid region. I'm pretty sure that assigning it to an image doesn't
<br>actually create the image regions until it is forced to update. Had<br>this code been in a ImageToImageFilter the Update() would be propagated<br>down the line before the Regions and iterators were called in the<br>GenerateData() method. I don't think that is happening here.
<br><br>Cheers,<br>Dan<br><br>Ashish Singh wrote:<br>> Hi Dan,<br>><br>> I tried it with the 'for' loop that you suggested. I even tried it<br>> with different set of images. It behaves the same each time,
i.e. the<br>> first run in the for loop goes fine, the second time, it crashes. So<br>> what I did was to comment each line below the reader->Update() one by<br>> one to find out if anything else is causing the error. And I found out
<br>> that if I comment the writer1->Update() line down below in the for<br>> loop, it doesn't crash at reader->Update anymore and goes through the<br>> entire for loop. But then I don't want to comment the
<br>> writer1->Update() line, because then I can't write the files.<br>> Do you know how to fix it? Has anyone else faced this problem?<br>><br>> Thanks,<br>> Ashish<br>><br>> On 1/11/07, *Daniel Mace* <
<a href="mailto:dlm19@duke.edu">dlm19@duke.edu</a> <mailto:<a href="mailto:dlm19@duke.edu">dlm19@duke.edu</a>>><br>> wrote:<br>><br>> Ashish,<br>><br>> It could be an issue with the reader reading in that particular file.
<br>> Tracking down the particular location of the vector assertion<br>> error can<br>> be a bit painful as everything is caught by the ITK exception<br>> libraries<br>> and repropagated. See what happens if you start you loop off with
<br>> the<br>> second image. Replace your for loop with the following and see if it<br>> gets through the first iteration.<br>><br>> ---------------------------<br>> for(fni = 1; fni<numberOfFilenames; fni++)
<br>> ---------------------------<br>><br>> If it still dies on the second loop, then we can at least<br>> contribute it<br>> to the code you wrote and not an error with the reader reading in a
<br>> particular tag/etc. for that particular image.<br>><br>> Cheers,<br>> Dan<br>><br>> Ashish Singh wrote:<br>> > Dan here's my complete code.It is crashing inside the loop
<br>> second time<br>> > at the reader->Update().Can you or anyone please help me figure out<br>> > 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 ><br>> 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 =<br>> 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 >
<br>> > 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<br>> ();!in1.IsAtEnd();++in1,++out)<br>> > //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></blockquote></div><br>