[Insight-users] difficulties on watershed for gray Images
sd d
anis_youssef2003 at yahoo.fr
Thu Jul 15 07:03:13 EDT 2004
Skipped content of type multipart/alternative-------------- next part --------------
#include <iostream>
#include "itkGradientAnisotropicDiffusionImageFilter.h"
#include "itkGradientMagnitudeImageFilter.h"
#include "itkWatershedImageFilter.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkUnaryFunctorImageFilter.h"
//#include "itkScalarToRGBPixelFunctor.h"
int main( int argc, char *argv[] )
{
if (argc < 3 )
{
std::cerr << "Missing Parameters " << std::endl;
std::cerr << "Usage: " << argv[0];
std::cerr << " inputImage outputImage " << std::endl;
return 1;
}
//import sys;
typedef unsigned char PixelType;
typedef itk::Image<PixelType, 2> ImageType;
typedef itk::Image<unsigned long, 2> LabeledImageType;
typedef itk::Image<float, 2> ScalarImageType;
typedef itk::ImageFileReader<ScalarImageType> FileReaderType;
typedef itk::GradientAnisotropicDiffusionImageFilter<ScalarImageType,
ScalarImageType> DiffusionFilterType;
// typedef itk::GradientMagnitudeImageFilter<ScalarImageType> ScalarMagnitudeFilterType;
typedef itk::GradientMagnitudeImageFilter<ScalarImageType,ScalarImageType> GradientMagnitudeFilterType;
typedef itk::WatershedImageFilter<ScalarImageType> WatershedFilterType;
// Software Guide : EndCodeSnippet
// typedef itk::ImageFileWriter<ImageType> FileWriterType;
typedef itk::Image< unsigned long, 2> OutputImageType;
typedef itk::ImageFileWriter< OutputImageType > FileWriterType;
FileReaderType::Pointer reader = FileReaderType::New();
reader->SetFileName( argv[1] );
DiffusionFilterType::Pointer diffusion = DiffusionFilterType::New();
//diffusion = itk.itkGradientAnisotropicDiffusionImageFilterF2F2_New();
diffusion->SetInput(reader->GetOutput());
diffusion->SetTimeStep(0.0625);
diffusion->SetConductanceParameter(9.0);
diffusion->SetNumberOfIterations( 5 );
GradientMagnitudeFilterType:: Pointer gradient =GradientMagnitudeFilterType::New();
//gradient = itk->itkGradientMagnitudeImageFilterF2F2_New();
gradient->SetInput(diffusion->GetOutput());
WatershedFilterType::Pointer watershed = WatershedFilterType::New();
//watershed = itk->itkWatershedImageFilterF2_New();
watershed->SetInput(gradient->GetOutput());
watershed->SetThreshold(0.1);
watershed->SetLevel(0.6);
//writer = itk->itkImageFileWriterUL2_New();
FileWriterType::Pointer writer = FileWriterType::New();
writer->SetFileName( argv[2] );
writer->SetInput( watershed->GetOutput() );
writer->Update();}
More information about the Insight-users
mailing list