[Insight-users] image reader update error

Daniel Mace dlm19 at duke.edu
Thu Jan 11 15:59:43 EST 2007


Ashish,

I think I ran into the same problem a while ago.  I ended up replacing 
the code with the following
-----------------------------------------
const vector<string> &fileNames =  nameGenerator->GetInputFileNames();
-----------------------------------------

and then set the file names by calling

---------------------------------------------
reader->SetFileName( fileNames[i].c_str());
---------------------------------------------

More of a quick fix for me (as I was returning to C++ after an 8 year 
hiatus), and I'm sure there is something more efficient.  Try making 
that change and let me know if it works.

Cheers,
Dan

Ashish Singh wrote:
> Thanks for replying Dan. Yes that's what it is, 
> reader->SetFileName(fileNames[fni]).
> The fname was a typo in my previous message,sorry for that. It doesn't 
> work with
> reader->SetFileName(fileNames[fni])
>
> The exact error message is a pop up box, titled Microsft Visual C++ 
> debug Library. It reads-
> ---------
> Debug Assertion Failed!
> Program:...
> File: C:\program Files(x86)\Microsft Visual Studio 8\VC\include\vector
> Line: 756
>
> Expression: vector subscript out of range
>
> For information on how your program can cause assertion failure, see 
> the Visual C++ documentation on asserts.
>
> abort-retry-ignore
> --------
>
> Do you know what is going wrong here?
>
> Thanks,
> Ashish
>
> On 1/11/07, *Daniel Mace* <dlm19 at duke.edu <mailto:dlm19 at duke.edu>> wrote:
>
>     Ashish,
>
>     What's the exact error message that it gives you?  Also, where do you
>     set "fname".  perhaps it should be:
>     -----------
>     reader->SetFileName(fileNames[fni])
>     --------
>     unless you set fname somewhere else in the code that isn't present.
>
>     Cheers,
>     Dan
>
>     Ashish Singh wrote:
>     > Hi,
>     >
>     > I am a newbie to ITK. I was trying to read a set of dicom images
>     from
>     > a directory and then use reader->update() to process each one of
>     them
>     > one after the other. But the reader->update() gives me an error
>     after
>     > reading the first image. Can anyone please tell me how to fix this
>     > problem?
>     >
>     > This is what my code looks like. It is not the complete code,
>     but only
>     > the relevant part of it.
>     > ---------------
>     >   typedef itk::GDCMSeriesFileNames NamesGeneratorType;
>     >   NamesGeneratorType::Pointer nameGenerator =
>     NamesGeneratorType::New();
>     >   nameGenerator->SetInputDirectory( "D:\\testimages"  );
>     >
>     >   typedef std::vector<std::string> FileNamesContainer;
>     >   FileNamesContainer fileNames = nameGenerator->GetInputFileNames();
>     >     unsigned int numberOfFilenames =  fileNames.size();
>     >   std::cout << numberOfFilenames << std::endl;
>     >   unsigned int fni;
>     >
>     >   for(fni = 0; fni<numberOfFilenames; fni++)
>     >     {
>     >     std::cout << "filename # " << fni << " = ";
>     >     std::cout << fileNames[fni] << std::endl;
>     >     }
>     >
>     >   for(fni = 0; fni<numberOfFilenames; fni++)
>     >   {
>     >   reader->SetFileName( fname);
>     >
>     >   reader->SetImageIO( gdcmImageIO );
>     >
>     >   try
>     >     {
>     >         reader->Update();//this is where it gives me an error second
>     > time in the loop.
>     >     }
>     >   catch (itk::ExceptionObject & e)
>     >     {
>     >     std::cerr << "exception in file reader " << std::endl;
>     >     std::cerr << e << std::endl;
>     >     return EXIT_FAILURE;
>     >     }
>     > // code for processing the image //
>     > //code for writing the processed image//
>     > }// for loop complete
>     > --------------------------------------
>     > The filenames are correctly read, the code runs fine the first time
>     > through the for loop, but second time it gives an error at the
>     > reader->Update() line.
>     > Can anyone please tell me why is this happening and how to fix it?
>     >
>     > Thanks,
>     > Ashish
>     >
>     >
>     >
>     ------------------------------------------------------------------------
>
>     >
>     > _______________________________________________
>     > Insight-users mailing list
>     > Insight-users at itk.org <mailto:Insight-users at itk.org>
>     > http://www.itk.org/mailman/listinfo/insight-users
>     >
>
>



More information about the Insight-users mailing list