1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
10
// OpenWalnut is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
15
// OpenWalnut is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Lesser General Public License for more details.
20
// You should have received a copy of the GNU Lesser General Public License
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
23
//---------------------------------------------------------------------------
25
#ifndef WSEGMENTATIONALGOREGIONGROWINGCONFIDENCECONNECTED_H
26
#define WSEGMENTATIONALGOREGIONGROWINGCONFIDENCECONNECTED_H
34
#include "itkConfidenceConnectedImageFilter.h"
35
#include "itkGradientAnisotropicDiffusionImageFilter.h"
36
#include "itkCastImageFilter.h"
38
#include "core/kernel/WKernel.h"
39
#include "core/kernel/WROIManager.h"
41
#include "core/graphicsEngine/WROIBox.h"
43
#include "core/dataHandler/WITKImageConversion.h"
45
#include "WSegmentationAlgo.h"
48
* Confidence connected region growing segmentation.
49
* \class WSegmentationAlgoRegionGrowingConfidenceConnected
51
class WSegmentationAlgoRegionGrowingConfidenceConnected : public WSegmentationAlgo
55
* Standard constructor.
57
WSegmentationAlgoRegionGrowingConfidenceConnected();
62
virtual ~WSegmentationAlgoRegionGrowingConfidenceConnected();
65
* Return the name of this algorithm.
68
virtual std::string getName();
71
* Return a description of this algorithm.
72
* \return A description.
74
virtual std::string getDescription();
77
* Checks if any properties were changed.
78
* \return True, iff any properties were changed.
80
virtual bool propChanged();
83
* Implements the operation.
85
* \tparam The type of the values in the dataset's valueset.
86
* \param valueset The dataset's valueset.
87
* \return The resulting dataset.
89
template< typename T >
90
DataSetPtr operator() ( WValueSet< T > const* valueset ) const;
94
* Initializes the algorithm's properties.
96
virtual void properties();
99
* A virtual function that calls the correct segmentation operation.
100
* \return The resulting dataset.
102
virtual DataSetPtr applyOperation();
104
//! The number of iteration in the smoothing filter.
105
WPropInt m_smoothingIter;
107
//! The conductance parameter for the anisotropic smoothing.
108
WPropDouble m_conductance;
110
//! The number of iteration in region growing.
111
WPropInt m_regionGrowingIterations;
113
//! The initial neighborhood radius.
114
WPropInt m_neighborhoodRadius;
116
//! The multiplier for the variance.
117
WPropDouble m_multiplier;
120
template< typename T >
121
WSegmentationAlgo::DataSetPtr WSegmentationAlgoRegionGrowingConfidenceConnected::operator() ( WValueSet< T > const* ) const
123
typedef itk::Image< T, 3 > ImgType;
124
typedef itk::Image< double, 3 > RealType;
125
typedef itk::Image< uint64_t, 3 > LabelType; // this might be a problem on 32-bit systems
126
typedef itk::Image< float, 3 > FinalType;
128
typedef itk::GradientAnisotropicDiffusionImageFilter< ImgType, RealType > SmoothingType;
129
typedef itk::CastImageFilter< LabelType, FinalType > CastFilter;
130
typedef itk::ConfidenceConnectedImageFilter< RealType, LabelType > RegionGrowingFilter;
132
typename ImgType::Pointer image = makeImageFromDataSet< T >( m_dataSet );
133
typename SmoothingType::Pointer smoothing = SmoothingType::New();
134
typename CastFilter::Pointer cast = CastFilter::New();
135
typename RegionGrowingFilter::Pointer regionGrowing = RegionGrowingFilter::New();
137
std::vector< osg::ref_ptr< WROI > > rois = WKernel::getRunningKernel()->getRoiManager()->getRois();
143
while( !box && k < rois.size() )
145
box = dynamic_cast< WROIBox* >( rois[ k ].get() );
151
boost::shared_ptr< WGridRegular3D > grid = boost::shared_dynamic_cast< WGridRegular3D >( m_dataSet->getGrid() );
152
WVector3d v = 0.5 * ( box->getMinPos() + box->getMaxPos() );
153
WValue< int > voxel = grid->getVoxelCoord( v );
155
i[ 0 ] = static_cast< int32_t >( voxel[ 0 ] );
156
i[ 1 ] = static_cast< int32_t >( voxel[ 1 ] );
157
i[ 2 ] = static_cast< int32_t >( voxel[ 2 ] );
159
smoothing->SetNumberOfIterations( m_smoothingIter->get( true ) );
160
smoothing->SetTimeStep( 0.0625 );
161
smoothing->SetConductanceParameter( m_conductance->get( true ) );
162
smoothing->SetInput( image );
163
regionGrowing->SetInput( smoothing->GetOutput() );
164
regionGrowing->SetMultiplier( m_multiplier->get( true ) );
165
regionGrowing->SetNumberOfIterations( m_regionGrowingIterations->get( true ) );
166
regionGrowing->SetReplaceValue( 255.0f );
167
regionGrowing->SetInitialNeighborhoodRadius( m_neighborhoodRadius->get( true ) );
168
regionGrowing->SetSeed( i );
169
cast->SetInput( regionGrowing->GetOutput() );
176
throw WException( "Problem in Region Growing Segmentation" );
178
return makeDataSetFromImage< float >( cast->GetOutput() );
188
#endif // WSEGMENTATIONALGOREGIONGROWINGCONFIDENCECONNECTED_H