[Insight-users] Re: image reader->Update() problem

Wes Turner wes.turner at kitware.com
Fri Jan 12 10:06:05 EST 2007


I missed the first part of the thread, but thought I would comment on
Daniels assertion regarding the windows machines.  VS 8 has implemented
assertions into the stl libraries only for DEBUG mode in an attempt to
remove memory management errors.  These are real errors, that are never
caught and rarely cause problems on non-Windows systems during run time.  A
quick check might be to compile and run your code and ITK as Release
(RelWithDebInfo may also work, try it first).  One of three things will
happen. 1)  If the assertion is not thrown by the VS 8 debug libraries, but
is thrown by something else, your code will behave the same.  2) If the
assertion is being thrown by the VS 8 debug libraries, but the error does
not cause immediate problems, your code will run, or 3) Your code will crash
and you can get an idea of where (you will need many print statements to do
this in Release, RelWithDebInfo should get you within a few lines in the
debugger.)

- Wes Turner

On 1/11/07, Ashish Singh <mrasingh at gmail.com> wrote:
>
> 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.
>
> On 1/11/07, Daniel Mace <dlm19 at duke.edu> wrote:
> >
> > Ashish,
> >
> > The assertion errors tend to pop up (only/more often) with windows
> > machines for some reason, so they are odd bugs to track down.  I could
> > be wrong, but I'm not entirely sure that your image file has set its
> > region settings correctly.  Just to make sure, after the line
> > -----------------
> > InputImageType::Pointer image = reader->GetOutput();
> > -----------------
> >
> > add in a
> > -----------------
> > image->Update()
> > ----------------
> >
> > Just to make sure that the image->GetRequestedRegion() actually returns
> > a valid region.  I'm pretty sure that assigning it to an image doesn't
> > actually create the image regions until it is forced to update.  Had
> > this code been in a ImageToImageFilter the Update() would be propagated
> > down the line before the Regions and iterators were called in the
> > GenerateData() method.  I don't think that is happening here.
> >
> > Cheers,
> > Dan
> >
> > Ashish Singh wrote:
> > > Hi Dan,
> > >
> > > I tried it with the 'for' loop that you suggested. I even tried it
> > > with different set of images. It behaves the same each time, i.e. the
> > > first run in the for loop goes fine, the second time, it crashes. So
> > > what I did was to comment each line below the reader->Update() one by
> > > one to find out if anything else is causing the error. And I found out
> >
> > > that if I comment the writer1->Update() line down below in the for
> > > loop, it doesn't crash at reader->Update anymore and goes through the
> > > entire for loop. But then I don't want to comment the
> > > writer1->Update() line, because then I can't write the files.
> > > Do you know how to fix it? Has anyone else faced this problem?
> > >
> > > Thanks,
> > > Ashish
> > >
> > > On 1/11/07, *Daniel Mace* < dlm19 at duke.edu <mailto:dlm19 at duke.edu>>
> > > wrote:
> > >
> > >     Ashish,
> > >
> > >     It could be an issue with the reader reading in that particular
> > file.
> > >     Tracking down the particular location of the vector assertion
> > >     error can
> > >     be a bit painful as everything is caught by the ITK exception
> > >     libraries
> > >     and repropagated.  See what happens if you start you loop off with
> >
> > >     the
> > >     second image.  Replace your for loop with the following and see if
> > it
> > >     gets through the first iteration.
> > >
> > >     ---------------------------
> > >       for(fni = 1; fni<numberOfFilenames; fni++)
> > >     ---------------------------
> > >
> > >     If it still dies on the second loop, then we can at least
> > >     contribute it
> > >     to the code you wrote and not an error with the reader reading in
> > a
> > >     particular tag/etc. for that particular image.
> > >
> > >     Cheers,
> > >     Dan
> > >
> > >     Ashish Singh wrote:
> > >     > 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?
> > >     >
> > >     > Thanks,
> > >     > Ashish
> > >     > ------------
> > >     > #include " itkImageFileReader.h"
> > >     > #include "itkImageFileWriter.h"
> > >     > #include "itkRescaleIntensityImageFilter.h"
> > >     > #include " itkGDCMImageIO.h"
> > >     > #include "itkImageRegionConstIterator.h"
> > >     > #include "itkImageRegionIterator.h"
> > >     > #include "itkRegionOfInterestImageFilter.h"
> > >     > #include "itkGDCMSeriesFileNames.h"
> > >     > #include <list>
> > >     > #include <fstream>
> > >     > #include <vector>
> > >     > #include <itksys/SystemTools.hxx>
> > >     >
> > >     > using namespace std;
> > >     >  int main( int argc, char* argv[] )
> > >     >  {
> > >     >
> > >     >   typedef signed short InputPixelType;
> > >     >   const unsigned int   InputDimension = 2;
> > >     >
> > >     >   typedef itk::Image< InputPixelType, InputDimension >
> > >     InputImageType;
> > >     >   typedef itk::ImageFileReader< InputImageType > ReaderType;
> > >     >
> > >     >   typedef itk::GDCMImageIO           ImageIOType;
> > >     >   ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
> > >     >
> > >     >   ReaderType::Pointer reader = ReaderType::New();
> > >     >
> > >     >   typedef itk::GDCMSeriesFileNames NamesGeneratorType;
> > >     >   NamesGeneratorType::Pointer nameGenerator =
> > >     NamesGeneratorType::New();
> > >     >   nameGenerator->SetInputDirectory(
> > "D:\\testimages\\SRS00001"  );
> > >     >
> > >     >   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;
> > >     >   }
> > >     >
> > >     >  typedef itk::Image<InputPixelType, InputDimension>
> > InputImageType;
> > >     >  typedef itk::ImageRegionConstIterator< InputImageType >
> > >     > ConstIteratorType;
> > >     >  typedef itk::ImageRegionIterator< InputImageType >
> > IteratorType;
> > >     >  InputImageType::Pointer image2 = InputImageType::New();
> > >     >  typedef itk::ImageFileWriter< InputImageType >  Writer1Type;
> > >     >  Writer1Type::Pointer writer1 = Writer1Type::New();
> > >     >
> > >     >   for(fni = 0; fni<numberOfFilenames; fni++)
> > >     >   {
> > >     >       cout<<"inside for loop"<<" "<<"loop # "<<fni<<endl;
> > >     >
> > >     >       reader->SetFileName( fileNames[fni] );
> > >     >       reader->SetImageIO( gdcmImageIO );
> > >     >       try
> > >     >         {
> > >     >             reader->Update();
> > >     >         }
> > >     >       catch (itk::ExceptionObject & e)
> > >     >         {
> > >     >             std::cerr << "exception in file reader " <<
> > std::endl;
> > >     >             std::cerr << e << std::endl;
> > >     >             return EXIT_FAILURE;
> > >     >         }
> > >     >
> > >     >      InputImageType::Pointer image = reader->GetOutput();
> > >     >      image2->SetRegions(image->GetRequestedRegion());
> > >     >      image2->CopyInformation(image);
> > >     >      image2->Allocate();
> > >     >
> > >     >      ConstIteratorType in1( image, image->GetRequestedRegion()
> > );
> > >     >
> > >     >      IteratorType out( image2, image->GetRequestedRegion() );
> > >     >
> > >     >      for (in1.GoToBegin(),out.GoToBegin
> > >     ();!in1.IsAtEnd();++in1,++out)
> > >     > //copy original image to new image
> > >     >      {
> > >     >         out.Set(in1.Get());
> > >     >      }
> > >     >
> > >     >       if(fni==0)
> > >     >         writer1->SetFileName("D:\\testimages\\SRS\\IM1.dcm" );
> > >     >       if(fni==1)
> > >     >           writer1->SetFileName("D:\\testimages\\SRS\\IM2.dcm" );
> > >     >       writer1->SetInput( image2 );
> > >     >       writer1->SetImageIO(gdcmImageIO);
> > >     >
> > >     >       try
> > >     >         {
> > >     >             writer1->Update();
> > >     >         }
> > >     >       catch (itk::ExceptionObject & e)
> > >     >         {
> > >     >             std::cerr << "exception in file writer " <<
> > std::endl;
> > >     >             std::cerr << e << std::endl;
> > >     >             return EXIT_FAILURE;
> > >     >         }
> > >     >   }//for loop end
> > >     >     return EXIT_SUCCESS;
> > >     >
> > >     >  }
> > >     > --------------
> > >     >
> >
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
>
>


-- 
Wesley D. Turner, Ph.D.
R&D Engineer
28 Corporate Drive
Clifton Park, NY 12065-8662
Phone: 518-371-3971 x120
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070112/adabadd7/attachment-0001.htm


More information about the Insight-users mailing list