[Insight-users] problem with floodfill iterator
Jie Zhu
zhujie1979 at gmail.com
Fri Sep 17 13:59:11 EDT 2004
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