[Insight-users] ITK Watershed Filter

Steffi Meyer saufi25 at web.de
Tue Jan 31 07:31:56 EST 2006


 Hi to all,

I still have some problems with the itk watershed filter. I have a 3D grayscale volume (.dcm). 
I would like to save it to a .dcm or .vtk file and load it with VolView. Alternatively I could also
render with vtk, but there seems to be an error, because the size of the volume isn't correct
(one dimension is protracted).
I also still don't know, if the pipeline is now correct for grayscale intensities. Perhaps someone,
can have a look at the source & tell me the errors or ideas! Thanks very much!


        typedef itk::RGBPixel<unsigned char>   RGBPixelType;
	typedef itk::Image<RGBPixelType,3>    RGBImageType;
	typedef itk::Image<unsigned long,3>   LabeledImageType;
	typedef itk::Image<float,3>           ScalarImageType;
	typedef unsigned char InputPixelType;  
	typedef float OutputPixelType;
	typedef itk::Image<InputPixelType,3> InputImageType;
	typedef itk::Image<OutputPixelType,3> OutputImageType;
	
	typedef itk::ImageFileReader<InputImageType> FileReaderType;
	typedef itk::GradientAnisotropicDiffusionImageFilter<InputImageType,OutputImageType> DiffusionFilterType;
	typedef itk::WatershedImageFilter<ScalarImageType> WatershedFilterType;
	
	typedef itk::ImageFileWriter<RGBImageType> FileWriterType;

	FileReaderType::Pointer reader = FileReaderType::New();
	reader->SetFileName("E:\\readSeries.dcm");
	
	DiffusionFilterType::Pointer diffusion = DiffusionFilterType::New();
	diffusion->SetNumberOfIterations(20);
	diffusion->SetConductanceParameter(3.0);
	diffusion->SetTimeStep(0.0625);

	typedef itk::GradientMagnitudeImageFilter<OutputImageType,OutputImageType> GradientMagnitudeFilterType;
	GradientMagnitudeFilterType::Pointer gradientMagnitudeFilter = GradientMagnitudeFilterType::New();
	
	WatershedFilterType::Pointer watershed = WatershedFilterType::New();
	watershed->SetLevel(0.5);
	watershed->SetThreshold(0.1);

	typedef itk::Functor::ScalarToRGBPixelFunctor<unsigned long> ColorMapFunctorType;
	typedef itk::UnaryFunctorImageFilter<LabeledImageType,RGBImageType,ColorMapFunctorType> ColorMapFilterType;
	ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New();
	
	FileWriterType::Pointer writer = FileWriterType::New();
	writer->SetFileName("E:\\water.vtk");

	diffusion->SetInput(reader->GetOutput());
	gradientMagnitudeFilter->SetInput(diffusion->GetOutput());
	watershed->SetInput(gradientMagnitudeFilter->GetOutput());
	colormapper->SetInput(watershed->GetOutput());
	writer->SetInput(colormapper->GetOutput());

	try 
		{
		cout << "writer->Update()" << endl;
		writer->Update();
		}
	catch (itk::ExceptionObject &e)
		{
		std::cerr << e << std::endl;
		}
    

        // visualization
	typedef itk::ImageToVTKImageFilter<RGBImageType> ConnectorType;
	
	ConnectorType::Pointer connector = ConnectorType::New();
	connector->SetInput(colormapper->GetOutput());

        // Create the standard renderer, render window and interactor
	vtkRenderer* ren = vtkRenderer::New();
	vtkRenderWindow* renWin = vtkRenderWindow::New();
	renWin->AddRenderer(ren);
	vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
	iren->SetRenderWindow(renWin);

	// Create transfer mapping scalar value to opacity
	vtkPiecewiseFunction* opacityTransferFunction = vtkPiecewiseFunction::New();
	opacityTransferFunction->AddPoint(0, 0.0); // 20, 0.0
	opacityTransferFunction->AddPoint(255, 1.0); // 255, 0.2

	// The property describes how the data will look
	vtkVolumeProperty* volumeProperty = vtkVolumeProperty::New();
	volumeProperty->SetScalarOpacity(opacityTransferFunction);
	volumeProperty->ShadeOn();
	volumeProperty->SetInterpolationTypeToLinear();

	// The mapper knows how to render the data
	vtkVolumeTextureMapper2D* volumeMapper = vtkVolumeTextureMapper2D::New();

	// The mapper / ray cast function know how to render the data
	volumeMapper->SetInput(connector->GetOutput());

	// The volume holds the mapper and the property and
	// can be used to position/orient the volume
	vtkVolume* volume = vtkVolume::New();
	volume->SetMapper(volumeMapper);
	volume->SetProperty(volumeProperty);

	ren->AddVolume(volume);
	ren->SetBackground(0.4392, 0.5020, 0.5647);
	renWin->SetSize(300, 300);
	renWin->Render();

	iren->Initialize();
	renWin->Render();
	iren->Start();
______________________________________________________________________
XXL-Speicher, PC-Virenschutz, Spartarife & mehr: Nur im WEB.DE Club!		
Jetzt gratis testen! http://freemail.web.de/home/landingpad/?mc=021130



More information about the Insight-users mailing list