在这个例子中使用前面例子中的代码,并设置图像的维数为 3 。应用梯度各向异性扩散来平滑图像。这个滤波器使用两个迭代器、一个值为 0.05 的 time step 和一个值为 3 的conductance 值,然后使用置信连接方式对平滑后的图像进行分割。使用的五个种子点的坐标分别为( 118 , 85 , 92 )、( 63 , 87 , 94 )、( 63 , 157 , 90 )、( 111 , 188 , 90 )、( 111 , 50 , 88 )。置信连接滤波器使用的参数:邻域范围是 2 ; 迭代器数目为5;和 f 值 为2.5( 跟前面的例子中一样 ) 。然后使VolView 来显示结果。
1 #include "itkConfidenceConnectedImageFilter.h" 2 #include "itkCastImageFilter.h" 3 #include "itkCurvatureFlowImageFilter.h" 4 #include "itkImageFileReader.h" 5 #include "itkImageFileWriter.h" 6 7 int main( int argc, char *argv[] ) 8 { 9 //if( argc < 3 ) 10 // { 11 // std::cerr << "Missing Parameters " << std::endl; 12 // std::cerr << "Usage: " << argv[0]; 13 // std::cerr << " inputImage outputImage " << std::endl; 14 // return EXIT_FAILURE; 15 // } 16 17 18 typedef float InternalPixelType; 19 const unsigned int Dimension = 3; 20 typedef itk::Image< InternalPixelType, Dimension > InternalImageType; 21 22 typedef unsigned char OutputPixelType; 23 typedef itk::Image< OutputPixelType, Dimension > OutputImageType; 24 25 typedef itk::CastImageFilter< InternalImageType, OutputImageType > 26 CastingFilterType; 27 CastingFilterType::Pointer caster = CastingFilterType::New(); 28 29 30 typedef itk::ImageFileReader< InternalImageType > ReaderType; 31 typedef itk::ImageFileWriter< OutputImageType > WriterType; 32 33 ReaderType::Pointer reader = ReaderType::New(); 34 WriterType::Pointer writer = WriterType::New(); 35 36 reader->SetFileName( "BrainProtonDensity3Slices.mha" ); 37 writer->SetFileName( "BrainProtonDensity3Slices_3.mha" ); 38 39 typedef itk::CurvatureFlowImageFilter< InternalImageType, InternalImageType > 40 CurvatureFlowImageFilterType; 41 CurvatureFlowImageFilterType::Pointer smoothing = 42 CurvatureFlowImageFilterType::New(); 43 44 typedef itk::ConfidenceConnectedImageFilter<InternalImageType, InternalImageType> 45 ConnectedFilterType; 46 ConnectedFilterType::Pointer confidenceConnected = ConnectedFilterType::New(); 47 48 smoothing->SetInput( reader->GetOutput() ); 49 confidenceConnected->SetInput( smoothing->GetOutput() ); 50 caster->SetInput( confidenceConnected->GetOutput() ); 51 writer->SetInput( caster->GetOutput() ); 52 53 smoothing->SetNumberOfIterations( 2 );// 54 smoothing->SetTimeStep(0.05);//每步迭代时间 55 56 confidenceConnected->SetMultiplier( 2.5 );//;设置乘法因子f 2.5 可调 57 confidenceConnected->SetNumberOfIterations( 5 );//设置迭代次数为5(迭代器数目) 58 confidenceConnected->SetInitialNeighborhoodRadius( 2 );//设置领域范围为2 59 confidenceConnected->SetReplaceValue( 255 ); 60 61 //设置种子点1 62 InternalImageType::IndexType index1; 63 index1[0] = 63;//X 轴 64 index1[1] = 67;//Y 轴 65 index1[2] = 1;//Z 轴 (第几个切片) 66 confidenceConnected->AddSeed(index1); 67 68 /* InternalImageType::IndexType index1; 69 index1[0] = 118; 70 index1[1] = 133; 71 index1[2] = 92; 72 confidenceConnected->AddSeed( index1 );*/ 73 74 try 75 { 76 writer->Update(); 77 } 78 catch( itk::ExceptionObject & excep ) 79 { 80 std::cerr << "Exception caught !" << std::endl; 81 std::cerr << excep << std::endl; 82 return EXIT_FAILURE; 83 } 84 85 86 return EXIT_SUCCESS; 87 }标签:typedef,InternalImageType,itk,置信,MHA,include,confidenceConnected,index1,ITK From: https://www.cnblogs.com/ybqjymy/p/17634850.html