ITK/Examples/WishList/Segmentation/MultiphaseChanAndVeseSparseFieldLevelSetSegmentation: Difference between revisions
No edit summary |
No edit summary |
||
Line 133: | Line 133: | ||
</source> | </source> | ||
{{ | {{ITKCMakeLists|{{SUBPAGENAME}}}} |
Revision as of 16:30, 25 December 2012
MultiphaseChanAndVeseSparseFieldLevelSetSegmentation.cxx
<source lang="cpp">
- include "itkScalarChanAndVeseSparseLevelSetImageFilter.h"
- include "itkScalarChanAndVeseLevelSetFunction.h"
- include "itkScalarChanAndVeseLevelSetFunctionData.h"
- include "itkConstrainedRegionBasedLevelSetFunctionSharedData.h"
- include "itkImageFileReader.h"
- include "itkImageFileWriter.h"
- include "itkImage.h"
- include "itkAtanRegularizedHeavisideStepFunction.h"
int main(int argc, char**argv) {
if( argc < 10 ) { std::cerr << "Missing arguments" << std::endl; std::cerr << "Usage: " << std::endl; std::cerr << argv[0]; std::cerr << " inputLevelSetImage1 inputLevelSetImage2 inputLevelSetImage3"; std::cerr << " inputFeatureImage outputLevelSetImage"; std::cerr << " CurvatureWeight AreaWeight LaplacianWeight"; std::cerr << " VolumeWeight Volume OverlapWeight" << std::endl; return EXIT_FAILURE; }
unsigned int nb_iteration = 50; double rms = 0.; double epsilon = 1.5; double curvature_weight = atof( argv[6] ); double area_weight = atof( argv[7] ); double volume_weight = atof( argv[8] ); double volume = atof( argv[9] ); double overlap_weight = atof( argv[10] ); double l1 = 1.; double l2 = 1.;
const unsigned int Dimension = 2; typedef float ScalarPixelType;
typedef itk::Image< ScalarPixelType, Dimension > LevelSetImageType; typedef itk::Image< unsigned char, Dimension > FeatureImageType; typedef itk::Image< unsigned char, Dimension > OutputImageType;
typedef itk::ScalarChanAndVeseLevelSetFunctionData< LevelSetImageType, FeatureImageType > DataHelperType;
typedef itk::ConstrainedRegionBasedLevelSetFunctionSharedData< LevelSetImageType, FeatureImageType, DataHelperType > SharedDataHelperType;
typedef itk::ScalarChanAndVeseLevelSetFunction< LevelSetImageType, FeatureImageType, SharedDataHelperType > LevelSetFunctionType;
typedef itk::ScalarChanAndVeseSparseLevelSetImageFilter< LevelSetImageType, FeatureImageType, OutputImageType, LevelSetFunctionType, SharedDataHelperType > MultiLevelSetType;
typedef itk::ImageFileReader< LevelSetImageType > LevelSetReaderType; typedef itk::ImageFileReader< FeatureImageType > FeatureReaderType; typedef itk::ImageFileWriter< OutputImageType > WriterType;
typedef itk::AtanRegularizedHeavisideStepFunction< ScalarPixelType, ScalarPixelType > DomainFunctionType;
DomainFunctionType::Pointer domainFunction = DomainFunctionType::New(); domainFunction->SetEpsilon( epsilon );
LevelSetReaderType::Pointer contourReader1 = LevelSetReaderType::New(); contourReader1->SetFileName( argv[1] ); contourReader1->Update();
LevelSetReaderType::Pointer contourReader2 = LevelSetReaderType::New(); contourReader2->SetFileName( argv[2] ); contourReader2->Update();
LevelSetReaderType::Pointer contourReader3 = LevelSetReaderType::New(); contourReader3->SetFileName( argv[3] ); contourReader3->Update();
FeatureReaderType::Pointer featureReader = FeatureReaderType::New(); featureReader->SetFileName( argv[4] ); featureReader->Update();
FeatureImageType::Pointer featureImage = featureReader->GetOutput(); LevelSetImageType::Pointer contourImage1 = contourReader1->GetOutput(); LevelSetImageType::Pointer contourImage2 = contourReader2->GetOutput(); LevelSetImageType::Pointer contourImage3 = contourReader3->GetOutput();
MultiLevelSetType::Pointer levelSetFilter = MultiLevelSetType::New(); levelSetFilter->SetFunctionCount( 3 ); levelSetFilter->SetFeatureImage( featureImage ); levelSetFilter->SetLevelSet( 0, contourImage1 ); levelSetFilter->SetLevelSet( 1, contourImage2 ); levelSetFilter->SetLevelSet( 2, contourImage3 ); levelSetFilter->SetNumberOfIterations( nb_iteration ); levelSetFilter->SetMaximumRMSError( rms ); levelSetFilter->SetUseImageSpacing( 1 ); levelSetFilter->SetInPlace( false );
for ( unsigned int i = 0; i < 3; i++ ) { levelSetFilter->GetDifferenceFunction(i)->SetDomainFunction( domainFunction ); levelSetFilter->GetDifferenceFunction(i)->SetCurvatureWeight( curvature_weight ); levelSetFilter->GetDifferenceFunction(i)->SetAreaWeight( area_weight ); levelSetFilter->GetDifferenceFunction(i)->SetOverlapPenaltyWeight( overlap_weight ); levelSetFilter->GetDifferenceFunction(i)->SetVolumeMatchingWeight( volume_weight ); levelSetFilter->GetDifferenceFunction(i)->SetVolume( volume ); levelSetFilter->GetDifferenceFunction(i)->SetLambda1( l1 ); levelSetFilter->GetDifferenceFunction(i)->SetLambda2( l2 ); }
levelSetFilter->Update();
WriterType::Pointer writer = WriterType::New(); writer->SetInput( levelSetFilter->GetOutput() ); writer->SetFileName( argv[5] );
try { writer->Update(); } catch( itk::ExceptionObject & excep ) { std::cerr << "Exception caught !" << std::endl; std::cerr << excep << std::endl; return -1; }
return EXIT_SUCCESS;
}
</source>
CMakeLists.txt
<syntaxhighlight lang="cmake"> cmake_minimum_required(VERSION 3.9.5)
project(MultiphaseChanAndVeseSparseFieldLevelSetSegmentation)
find_package(ITK REQUIRED) include(${ITK_USE_FILE}) if (ITKVtkGlue_LOADED)
find_package(VTK REQUIRED) include(${VTK_USE_FILE})
endif()
add_executable(MultiphaseChanAndVeseSparseFieldLevelSetSegmentation MACOSX_BUNDLE MultiphaseChanAndVeseSparseFieldLevelSetSegmentation.cxx)
if( "${ITK_VERSION_MAJOR}" LESS 4 )
target_link_libraries(MultiphaseChanAndVeseSparseFieldLevelSetSegmentation ITKReview ${ITK_LIBRARIES})
else( "${ITK_VERSION_MAJOR}" LESS 4 )
target_link_libraries(MultiphaseChanAndVeseSparseFieldLevelSetSegmentation ${ITK_LIBRARIES})
endif( "${ITK_VERSION_MAJOR}" LESS 4 )
</syntaxhighlight>
Download and Build MultiphaseChanAndVeseSparseFieldLevelSetSegmentation
Click here to download MultiphaseChanAndVeseSparseFieldLevelSetSegmentation and its CMakeLists.txt file. Once the tarball MultiphaseChanAndVeseSparseFieldLevelSetSegmentation.tar has been downloaded and extracted,
cd MultiphaseChanAndVeseSparseFieldLevelSetSegmentation/build
- If ITK is installed:
cmake ..
- If ITK is not installed but compiled on your system, you will need to specify the path to your ITK build:
cmake -DITK_DIR:PATH=/home/me/itk_build ..
Build the project:
make
and run it:
./MultiphaseChanAndVeseSparseFieldLevelSetSegmentation
WINDOWS USERS PLEASE NOTE: Be sure to add the ITK bin directory to your path. This will resolve the ITK dll's at run time.
Building All of the Examples
Many of the examples in the ITK Wiki Examples Collection require VTK. You can build all of the the examples by following these instructions. If you are a new VTK user, you may want to try the Superbuild which will build a proper ITK and VTK.
ItkVtkGlue
ITK >= 4
For examples that use QuickView (which depends on VTK), you must have built ITK with Module_ITKVtkGlue=ON.
ITK < 4
Some of the ITK Examples require VTK to display the images. If you download the entire ITK Wiki Examples Collection, the ItkVtkGlue directory will be included and configured. If you wish to just build a few examples, then you will need to download ItkVtkGlue and build it. When you run cmake it will ask you to specify the location of the ItkVtkGlue binary directory.