[Insight-users] How to write the Image after Iterator operation
Fucang Jia
jiafucang@hotmail.com
Mon, 06 Jan 2003 17:54:39 +0800
Hello, everyone,
I want to threshold a gray image using Otsu method. But I can not write the
binaried image. I have not understand the iterator, could anyone explain
what is wrong? Here is the code:
typedef unsigned char PixelType;
PixelType threshold;
typedef itk::Image< PixelType, 2 > ImageType;
typedef itk::OtsuThresholdImageCalculator< ImageType > CalculatorType;
typedef itk::ImageFileReader< ImageType > ReaderType;
typedef itk::ImageFileWriter< ImageType > WriterType;
typedef itk::ImageRegionIterator< ImageType > IteratorType;
ReaderType::Pointer reader = ReaderType::New();
CalculatorType::Pointer calculator = CalculatorType::New();
WriterType::Pointer writer = WriterType::New();
itk::MetaImageIO::Pointer metaWriter = itk::MetaImageIO::New();
reader->SetFileName( argv[1] );
reader->Update();
calculator->SetImage(reader->GetOutput());
calculator->Compute();
threshold = calculator->GetThreshold();
ImageType::Pointer image=reader->GetOutput();
ImageType::RegionType region = image->GetBufferedRegion();
IteratorType it(image,region);
it.GoToBegin();
while(!it.IsAtEnd())
{
if(it.Value()<threshold)
it.Set(0);
else
it.Set(255);
++it;
}
writer->SetImageIO(metaWriter);
writer->SetFileName(argv[2]);
writer->SetInput(it);
writer->Write();
==========================================
/data2/itkcvs/Insight/Examples/Filtering/OtsuThreshold.cxx: In
function `int main(int, char**)':
/data2/itkcvs/Insight/Examples/Filtering/OtsuThreshold.cxx:57: no
matching function for call to `itk::ImageFileWriter<main(int,
char**)::ImageType>::SetInput(main(int, char**)::IteratorType&)'
/data2/itkcvs/Insight/Code/IO/itkImageFileWriter.txx:51: candidates are:
void
itk::ImageFileWriter<TInputImage>::SetInput(const TInputImage*) [with
TInputImage = main(int, char**)::ImageType]
make[3]: *** [BinaryThresholdImageFilter.o] Error 1
make[2]: *** [default_target] Error 2
make[1]: *** [default_target_Filtering] Error 2
make: *** [default_target] Error 2
I looked some code, the error occurred on line "writer->SetInput(it);", but
I do not know how to correct this line.
Thanks !
Fucang
_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail