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

Ashish Singh mrasingh at gmail.com
Thu Jan 11 18:23:00 EST 2007


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;
> >     >
> >     >  }
> >     > --------------
> >     >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070111/cd892880/attachment.html


More information about the Insight-users mailing list