[Insight-users] problem of segmentation gray image using watershed

sd d anis_youssef2003 at yahoo.fr
Mon Jul 5 10:18:01 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"

	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;
		}

	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,ScalarImageType> GradientMagnitudeFilterType; 
	typedef itk::WatershedImageFilter<ScalarImageType> WatershedFilterType;
  // Software Guide : EndCodeSnippet

	typedef itk::ImageFileWriter<ImageType> FileWriterType;

	FileReaderType::Pointer reader = FileReaderType::New();
	reader->SetFileName( argv[1] );

	DiffusionFilterType::Pointer diffusion = DiffusionFilterType::New();
	diffusion->SetInput(reader->GetOutput());
	diffusion->SetTimeStep(0.0625);
	diffusion->SetConductanceParameter(9.0);
	diffusion->SetNumberOfIterations(  5 );

	GradientMagnitudeFilterType:: Pointer gradient =GradientMagnitudeFilterType::New();
	gradient->SetInput(diffusion->GetOutput());
	
	WatershedFilterType::Pointer watershed = WatershedFilterType::New();
	watershed->SetInput(gradient->GetOutput());
	watershed->SetThreshold(0.1);
	watershed->SetLevel(0.6);

	FileWriterType::Pointer writer = FileWriterType::New();
	writer->SetFileName( argv[2] );
	writer->SetInput( watershed->GetOutput()  );
	writer->Update();
	return 0;}


More information about the Insight-users mailing list