1 #include "itkIsolatedConnectedImageFilter.h" 2 #include "itkImage.h" 3 #include "itkCastImageFilter.h" 4 #include "itkCurvatureFlowImageFilter.h" 5 #include "itkImageFileReader.h" 6 #include "itkImageFileWriter.h" 7 8 int main( int argc, char *argv[] ) 9 { 10 /*if( argc < 7 ) 11 { 12 std::cerr << "Missing Parameters " << std::endl; 13 std::cerr << "Usage: " << argv[0]; 14 std::cerr << " inputImage outputImage seedX1 seedY1"; 15 std::cerr << " lowerThreshold seedX2 seedY2" << std::endl; 16 return EXIT_FAILURE; 17 }*/ 18 //我们使用一个像素类型和一个特殊维来定义图像的类型: 19 typedef float InternalPixelType; 20 const unsigned int Dimension = 3; 21 typedef itk::Image< InternalPixelType, Dimension > InternalImageType; 22 23 //下面几行是对 IsolatedConnectedImageFilter 进行实例化的代码 24 typedef unsigned char OutputPixelType; 25 typedef itk::Image< OutputPixelType, Dimension > OutputImageType; 26 typedef itk::CastImageFilter< InternalImageType, OutputImageType > 27 CastingFilterType; 28 CastingFilterType::Pointer caster = CastingFilterType::New(); 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( "Isolated_baizhi.mha" ); 38 39 40 typedef itk::CurvatureFlowImageFilter< InternalImageType, InternalImageType > 41 CurvatureFlowImageFilterType; 42 CurvatureFlowImageFilterType::Pointer smoothing = 43 CurvatureFlowImageFilterType::New(); 44 45 typedef itk::IsolatedConnectedImageFilter<InternalImageType, 46 InternalImageType> ConnectedFilterType; 47 //使用 New( ) 方式对这个类的一个文件进行结构化 48 ConnectedFilterType::Pointer isolatedConnected = ConnectedFilterType::New(); 49 //现在连接管道 50 smoothing->SetInput( reader->GetOutput() ); 51 isolatedConnected->SetInput( smoothing->GetOutput() ); 52 caster->SetInput( isolatedConnected->GetOutput() ); 53 writer->SetInput( caster->GetOutput() ); 54 /*IsolatedConnectedImageFilter 期望用户指定一个门限和两个种子。在这个例子中,我们 55 从命令行得到它们*/ 56 smoothing->SetNumberOfIterations(4); 57 smoothing->SetTimeStep( 0.125 ); 58 59 InternalImageType::IndexType indexSeed1; 60 //白质种子点 61 indexSeed1[0] = atoi( "61" ); 62 indexSeed1[1] = atoi( "140" ); 63 indexSeed1[2] = atoi("2"); 64 //下门限值(要分割的白质的下门限值) 65 const InternalPixelType lowerThreshold = atof( "150" ); 66 67 InternalImageType::IndexType indexSeed2; 68 //灰质种子点 69 indexSeed2[0] = atoi( "63" ); 70 indexSeed2[1] = atoi( "43" ); 71 indexSeed2[2] = atoi("2"); 72 /*由于在 ConnectedThresholdImageFilter 中,现在我们就必须指定在区域中能被输出像素所 73 接受的亮度值以及至少一个种子点来定义最初的区域*/ 74 isolatedConnected->SetLower( lowerThreshold ); 75 isolatedConnected->AddSeed1( indexSeed1 ); 76 isolatedConnected->AddSeed2( indexSeed2 ); 77 78 isolatedConnected->SetReplaceValue( 255 ); 79 /*writer 上的 Updata() 方法触发管道的运行。通常在出现错误和抛出异议时, 从一个 try / catch 80 模块调用 updata*/ 81 try 82 { 83 writer->Update(); 84 } 85 catch( itk::ExceptionObject & excep ) 86 { 87 std::cerr << "Exception caught !" << std::endl; 88 std::cerr << excep << std::endl; 89 } 90 /*这个亮度值允许我们对两个区域进行分割,使用 GetIsolatedValue() 方式可以对区域进行恢复*/ 91 std::cout << "Isolated Value Found = "; 92 std::cout << isolatedConnected->GetIsolatedValue() << std::endl; 93 return EXIT_SUCCESS; 94 }标签:typedef,InternalImageType,itk,isolatedConnected,MHA,New,脑部,include,ITK From: https://www.cnblogs.com/ybqjymy/p/17634940.html