コード例 #1
0
void ttt::AJSegmentationDijkstraFilter<TInputAJGraph,TPlatenessImage, TVertexnessImage,TOutputAJGraph>::DoFastMarching() {

	typedef itk::Image<int, NumDimensions> VoronoiImageType;

	typedef itk::ImageFileWriter<VoronoiImageType> VoronoiWriterType;

	typename VoronoiWriterType::Pointer voronoiWriter = VoronoiWriterType::New();
	voronoiWriter->SetFileName("VertexVoronoi.mha");

	typedef ttt::VoronoiTesselationImageFilter<VoronoiImageType,typename TPlatenessImage::PixelType> VoronoiFilterType;

	typename VoronoiFilterType::Pointer voronoiFilter = VoronoiFilterType::New();

	typedef ttt::FastMarchingImageFilter<LevelSetImageType, PlatenessImageType> FastMarchingImageFilterType;

	typename FastMarchingImageFilterType::Pointer fastMarching = FastMarchingImageFilterType::New();
	fastMarching->SetInput(m_Speed);

	typedef typename VoronoiFilterType::NodeContainer VoronoiNodeContainer;
	typedef typename VoronoiFilterType::LevelSetNodeType VoronoiNodeType;

	typedef typename FastMarchingImageFilterType::NodeContainer NodeContainer;
	typedef typename FastMarchingImageFilterType::NodeType NodeType;
	typename NodeContainer::Pointer seeds = NodeContainer::New();
	seeds->Initialize();

	typename VoronoiNodeContainer::Pointer seedsVoronoi = VoronoiNodeContainer::New();
	;
	seedsVoronoi->Initialize();

	int k = 0;

	for (auto vit = this->GetInputAJGraph()->VerticesBegin(); vit != this->GetInputAJGraph()->VerticesEnd(); vit++) {

		typename PlatenessImageType::PointType seedPosition = this->GetInputAJGraph()->GetAJVertex(*vit)->GetPosition();
		typename PlatenessImageType::IndexType seedIndex;

		this->GetPlatenessImage()->TransformPhysicalPointToIndex(seedPosition, seedIndex);

		NodeType node;
		const double seedValue = 0.0;
		node.SetValue(seedValue);
		node.SetIndex(seedIndex);

		seeds->InsertElement(k, node);

		VoronoiNodeType nodeVoronoi;

		nodeVoronoi.SetValue(seedValue);
		node.SetIndex(seedIndex);
		seedsVoronoi->InsertElement(k, nodeVoronoi);

		k++;
	}

	voronoiFilter->SetOutputSize(m_Speed->GetLargestPossibleRegion().GetSize());
	voronoiFilter->SetOutputDirection(m_Speed->GetDirection());
	voronoiFilter->SetOutputRegion(m_Speed->GetLargestPossibleRegion());
	voronoiFilter->SetOutputSpacing(m_Speed->GetSpacing());
	voronoiFilter->SetOutputOrigin(m_Speed->GetOrigin());

	voronoiFilter->SetTrialPoints(seeds);
	voronoiFilter->Update();

	voronoiWriter->SetInput(voronoiFilter->GetOutput());
	voronoiWriter->Update();

	fastMarching->SetStoppingValue(m_StoppingValue);
	fastMarching->SetTrialPoints(seeds);
	fastMarching->SetOutputSize(m_Speed->GetBufferedRegion().GetSize());

	fastMarching->SetVoronoiImage(voronoiFilter->GetOutput());
	fastMarching->Update();

	m_LevelSet = fastMarching->GetOutput();
	m_Labels = fastMarching->GetClusterImage();

	itk::ImageRegionIterator<LevelSetImageType> levelsetIterator(m_LevelSet, m_LevelSet->GetLargestPossibleRegion());

	levelsetIterator.GoToBegin();

	while (!levelsetIterator.IsAtEnd()) {

		if (levelsetIterator.Value() == static_cast<double>(itk::NumericTraits<double>::max() / 2.0)) {
			levelsetIterator.Set(-1);
		}

		++levelsetIterator;
	}

	typedef itk::ImageFileWriter<LevelSetImageType> LevelSetWriterType;

	typename LevelSetWriterType::Pointer levelSetWriter = LevelSetWriterType::New();

	levelSetWriter->SetFileName("LevelSet.mha");
	levelSetWriter->SetInput(m_LevelSet);
	levelSetWriter->Update();

}
コード例 #2
0
void FastMarchingImageFilterITK::fastMarchingImageFilterITK() {

    if (!enableProcessing_.get()) {
        outport1_.setData(inport1_.getData(), false);
        return;
    }

    //typedefs images
    typedef itk::Image<T, 3> InputImageType;

    //input image p1
    typename InputImageType::Pointer p1 = voreenToITK<T>(inport1_.getData());

    typedef  itk::FastMarchingImageFilter< InputImageType, InputImageType >    FastMarchingFilterType;
    typename FastMarchingFilterType::Pointer  fastMarching = FastMarchingFilterType::New();

    typedef typename FastMarchingFilterType::NodeContainer   NodeContainer;
    typedef typename FastMarchingFilterType::NodeType        NodeType;

    typename NodeContainer::Pointer seeds = NodeContainer::New();

    if (seedPointPort_.hasChanged()) {
        const PointListGeometry<tgt::vec3>* pointList = dynamic_cast< const PointListGeometry<tgt::vec3>* >(seedPointPort_.getData());
        if (pointList) {
            seedPoints = pointList->getData();
            if (!seedPoints.empty()) {
                numSeedPoint_.setMinValue(1);
                numSeedPoint_.setMaxValue(seedPoints.size());
                numSeedPoint_.set(seedPoints.size());
            }
            else {
                numSeedPoint_.setMinValue(0);
                numSeedPoint_.setMaxValue(0);
                numSeedPoint_.set(0);
            }
        }
    }

    if(!seedPoints.empty()) {
        seedPoint_.set(seedPoints[numSeedPoint_.get()-1]);
    }
    else {
        seedPoint_.set(tgt::vec3 (1));
    }


    typename InputImageType::IndexType  seedPosition;

    seedPosition[0] = seedPoint_.get().x;
    seedPosition[1] = seedPoint_.get().y;
    seedPosition[2] = seedPoint_.get().z;

    const double initialDistance = initialDistance_.get();

    NodeType node;

    const double seedValue = - initialDistance;

    node.SetValue( seedValue);
    node.SetIndex (seedPosition);

    seeds->Initialize();
    seeds->InsertElement( 0, node);

    fastMarching->SetTrialPoints( seeds );
    fastMarching->SetSpeedConstant( 1.0f );
    fastMarching->SetStoppingValue( stoptime_.get() );

    fastMarching->SetInput(p1);

    observe(fastMarching.GetPointer());

    try
    {
        fastMarching->Update();
    }
    catch (itk::ExceptionObject &e)
    {
        LERROR(e);
    }

    Volume* outputVolume1 = 0;
    outputVolume1 = ITKToVoreenCopy<T>(fastMarching->GetOutput());

    if (outputVolume1) {
        transferTransformation(inport1_.getData(), outputVolume1);
        outport1_.setData(outputVolume1);
    }
    else
        outport1_.setData(0);

}
void GeodesicActiveContourShapePriorLevelSetImageFilterWorkflowITK::geodesicActiveContourShapePriorLevelSetImageFilterWorkflowITK() {

    inputIsBinary_.setVisible(true);
    squaredDistance_.setVisible(true);
    useImageSpacing_.setVisible(true);

    if (!enableProcessing_.get()) {
        outport1_.setData(inport1_.getData(), false);
        return;
    }

    //typedefs images
    typedef itk::Image<T, 3> InputImageType;

    //input image p1
    typename InputImageType::Pointer p1 = voreenToITK<T>(inport1_.getData());

    //LevelsetFilter
    typedef itk::GeodesicActiveContourShapePriorLevelSetImageFilter<InputImageType, InputImageType> LevelType;
    typename LevelType::Pointer levelfilter = LevelType::New();
    typename LevelType::Pointer levelfilter2 = LevelType::New();

    //smoothing, gradient, sigmoid
    typedef   itk::CurvatureAnisotropicDiffusionImageFilter<
                               InputImageType,
                               InputImageType >  SmoothingFilterType;

    typename SmoothingFilterType::Pointer smoothing = SmoothingFilterType::New();

    typedef   itk::GradientMagnitudeRecursiveGaussianImageFilter<
                               InputImageType,
                               InputImageType >  GradientFilterType;

    typedef   itk::SigmoidImageFilter<
                               InputImageType,
                               InputImageType >  SigmoidFilterType;

    typename GradientFilterType::Pointer  gradientMagnitude = GradientFilterType::New();

    typename SigmoidFilterType::Pointer sigmoid = SigmoidFilterType::New();
    sigmoid->SetOutputMinimum( 0.0 );
    sigmoid->SetOutputMaximum( 1.0 );

    smoothing->SetInput(p1);
    smoothing->SetTimeStep( timestep_.get() );
    smoothing->SetNumberOfIterations(  numberofiterations_.get() );
    smoothing->SetConductanceParameter( conductanceparameter_.get() );

    gradientMagnitude->SetInput( smoothing->GetOutput() );
    gradientMagnitude->SetSigma( sigma_.get());
    sigmoid->SetInput( gradientMagnitude->GetOutput() );
    sigmoid->SetAlpha( alpha_.get() );
    sigmoid->SetBeta( beta_.get() );
    sigmoid->SetOutputMinimum(  0.0  );
    sigmoid->SetOutputMaximum(  1.0f  );

    if (initLevelSet_.isSelected("danielsson")){

        //initial Level Set using DanielssonDistanceMapImageFiler
        typedef itk::DanielssonDistanceMapImageFilter<InputImageType, InputImageType> DanielssonType;
        typename DanielssonType::Pointer danielssonfilter = DanielssonType::New();


        danielssonfilter->SetInput(p1);
        danielssonfilter->SetInputIsBinary(inputIsBinary_.get());
        danielssonfilter->SetSquaredDistance(squaredDistance_.get());
        danielssonfilter->SetUseImageSpacing(useImageSpacing_.get());


        levelfilter->SetInput(danielssonfilter->GetOutput());
        levelfilter->SetFeatureImage (sigmoid->GetOutput());
        levelfilter->SetPropagationScaling(propagationScaling_.get());
        levelfilter->SetCurvatureScaling( 1.0 );
        levelfilter->SetAdvectionScaling( 1.0 );
        levelfilter->SetMaximumRMSError( 0.02 );
        levelfilter->SetNumberOfIterations( 800 );

        observe(levelfilter.GetPointer());

        try
        {
            levelfilter->Update();
        }
        catch (itk::ExceptionObject &e)
        {
            LERROR(e);
        }


        Volume* outputVolume1 = 0;
        outputVolume1 = ITKToVoreenCopy<T>(levelfilter->GetOutput());

        if (outputVolume1) {
            transferTransformation(inport1_.getData(), outputVolume1);
            outport1_.setData(outputVolume1);
        }
        else
            outport1_.setData(0);
    }

    else if (initLevelSet_.isSelected("fastmarching")){

        inputIsBinary_.setVisible(false);
        squaredDistance_.setVisible(false);
        useImageSpacing_.setVisible(false);

        //initial Level set using FastMarchingImageFilter
        typedef  itk::FastMarchingImageFilter<
                              InputImageType,
                              InputImageType >    FastMarchingFilterType;

        typename FastMarchingFilterType::Pointer  fastMarching = FastMarchingFilterType::New();

        typedef typename FastMarchingFilterType::NodeContainer   NodeContainer;
        typedef typename FastMarchingFilterType::NodeType        NodeType;

        typename NodeContainer::Pointer seeds = NodeContainer::New();

        if (seedPointPort_.hasChanged()) {
            const PointListGeometry<tgt::vec3>* pointList = dynamic_cast< const PointListGeometry<tgt::vec3>* >(seedPointPort_.getData());
            if (pointList) {
                seedPoints = pointList->getData();
                if (!seedPoints.empty()) {
                    numSeedPoint_.setMinValue(1);
                    numSeedPoint_.setMaxValue(seedPoints.size());
                    numSeedPoint_.set(seedPoints.size());
                }
                else {
                    numSeedPoint_.setMinValue(0);
                    numSeedPoint_.setMaxValue(0);
                    numSeedPoint_.set(0);
                }
            }
        }

        if(!seedPoints.empty()) {
            seedPoint_.set(seedPoints[numSeedPoint_.get()-1]);
        }
        else {
            seedPoint_.set(tgt::vec3 (1));
        }


        typename InputImageType::IndexType  seedPosition;

        seedPosition[0] = seedPoint_.get().x;
        seedPosition[1] = seedPoint_.get().y;
        seedPosition[2] = seedPoint_.get().z;

        const double initialDistance = initialDistance_.get();

        NodeType node;

        const double seedValue = - initialDistance;

        node.SetValue( seedValue);
        node.SetIndex (seedPosition);

        seeds->Initialize();
        seeds->InsertElement( 0, node);

        fastMarching->SetTrialPoints( seeds );

        fastMarching->SetSpeedConstant( 1.0f );
        fastMarching->SetStoppingValue( stoptime_.get() );

        fastMarching->SetInput(p1);

        observe(levelfilter2.GetPointer());

        levelfilter2->SetInput(fastMarching->GetOutput());
        levelfilter2->SetFeatureImage (sigmoid->GetOutput());
        levelfilter2->SetPropagationScaling(propagationScaling_.get());
        levelfilter2->SetCurvatureScaling( 1.0 );
        levelfilter2->SetAdvectionScaling( 1.0 );
        levelfilter2->SetMaximumRMSError( 0.02 );
        levelfilter2->SetNumberOfIterations( 800 );


        try
        {
            levelfilter2->Update();
        }
        catch (itk::ExceptionObject &e)
        {
            LERROR(e);
        }

        Volume* outputVolume1 = 0;
        outputVolume1 = ITKToVoreenCopy<T>(levelfilter2->GetOutput());

        if (outputVolume1) {
            transferTransformation(inport1_.getData(), outputVolume1);
            outport1_.setData(outputVolume1);
        }
        else
            outport1_.setData(0);

    }
}