[Insight-users] problem with floodfill iterator

Jie Zhu zhujie1979 at gmail.com
Mon Sep 20 11:37:57 EDT 2004


Thanks. Got it working.
Jie


On Sun, 19 Sep 2004 20:04:12 -0400, Luis Ibanez <luis.ibanez at kitware.com> wrote:
> 
> Hi Jie,
> 
> Please read the chapter on Image Iterators
> from the ITK Software Guide.
> 
>     http://www.itk.org/ItkSoftwareGuide.pdf
> 
> Chapter 11, pdf-page 481.
> 
> Your iterator should be created as:
> 
>   IteratorType it ( outputImage, function, m_SeedList );
>   it.GoToBegin();
> 
> where seed list is a std::vector< index >
> 
> Note also that you don't need to write this code after all,  :-)
> 
> ...because the functionality is already provided by the Connected
> Threshold Image Filter.  Please read the ITK Software Guide,
> Section 9.1.1, pdf-page 342, where this filter is described in
> detail.
> 
>   Regards,
> 
>     Luis
> 
> --------------------------
> 
> 
> Jie Zhu wrote:
> 
> > Hi All,
> > I am learning to use the FloodFillIterator, and I am running into a
> > problem. I assigned an empty outputimage, a binary thresholding
> > (between) function of an input image and a starting point, but when I
> > call the iterator the program just crashes. I made sure that at the
> > starting point, pixel value is between the lower and upper boundaries.
> > Can somebody please tell me why this is happening? Also, altough the
> > starting point was inside the boundaries, the it.Get() returned 0, is
> > this right?
> > Thank you,
> > Jie
> > ------------------------------------------------------------------------------------------
> > Here is the code:
> >
> > typedef itk::Image<unsigned char,2>            ImageType;
> >
> > typedef itk::ImageFileReader< ImageType >  ReaderType;
> > typedef itk::ImageFileWriter< ImageType >  WriterType;
> >
> > ReaderType::Pointer reader = ReaderType::New();
> > WriterType::Pointer writer = WriterType::New();
> >
> > const char * inputFilename  = argv[1];
> > const char * outputFilename = argv[2];
> >
> > reader->SetFileName( inputFilename  );
> > writer->SetFileName( outputFilename );
> >
> > reader->Update();
> > ImageType::Pointer image = reader->GetOutput();
> >
> >
> > typedef itk::BinaryThresholdImageFunction<ImageType> FunctionType;
> > typedef itk::FloodFilledImageFunctionConditionalIterator<ImageType,
> > FunctionType> IteratorType;
> >
> > index[0] = atoi( argv[3] );
> > index[1] = atoi( argv[4] );
> >
> > int lowerThreshold = atoi( argv[5] );
> > int upperThreshold = atoi( argv[6] );
> >
> > ImageType::Pointer outputImage = ImageType::New();
> > outputImage->SetBufferedRegion( image->GetRequestedRegion() );
> > outputImage->Allocate();
> > outputImage->FillBuffer ( 0 );
> >
> > FunctionType::Pointer function = FunctionType::New();
> > function->SetInputImage ( image );
> > function->ThresholdBetween ( lowerThreshold, upperThreshold );
> > IteratorType floodIt = IteratorType( outputImage, function, index );
> >
> > //works till this point
> > //returns one 0 then crashes
> > while(!floodIt.IsAtEnd){
> >   std::cout << floodIt.Get() << std::endl;
> >   ++floodIt;
> > }
> >
> 
> 



-- 
Jie Zhu
Cornell University


More information about the Insight-users mailing list