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 = 2; 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( "BrainProtonDensitySlice.png" ); 37 writer->SetFileName( " Isolated_baizhi.png" ); 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( 5 ); 57 smoothing->SetTimeStep( 0.125 ); 58 59 InternalImageType::IndexType indexSeed1; 60 //白质种子点 61 indexSeed1[0] = atoi( "61" ); 62 indexSeed1[1] = atoi( "140" ); 63 //下门限值(要分割的白质的下门限值) 64 const InternalPixelType lowerThreshold = atof( "150" ); 65 66 InternalImageType::IndexType indexSeed2; 67 //灰质种子点 68 indexSeed2[0] = atoi( "63" ); 69 indexSeed2[1] = atoi( "43" ); 70 /*由于在 ConnectedThresholdImageFilter 中,现在我们就必须指定在区域中能被输出像素所 71 接受的亮度值以及至少一个种子点来定义最初的区域*/ 72 isolatedConnected->SetLower( lowerThreshold ); 73 isolatedConnected->AddSeed1( indexSeed1 ); 74 isolatedConnected->AddSeed2( indexSeed2 ); 75 76 isolatedConnected->SetReplaceValue( 255 ); 77 /*writer 上的 Updata() 方法触发管道的运行。通常在出现错误和抛出异议时, 从一个 try / catch 78 模块调用 updata*/ 79 try 80 { 81 writer->Update(); 82 } 83 catch( itk::ExceptionObject & excep ) 84 { 85 std::cerr << "Exception caught !" << std::endl; 86 std::cerr << excep << std::endl; 87 } 88 /*这个亮度值允许我们对两个区域进行分割,使用 GetIsolatedValue() 方式可以对区域进行恢复*/ 89 std::cout << "Isolated Value Found = "; 90 std::cout << isolatedConnected->GetIsolatedValue() << std::endl; 91 return EXIT_SUCCESS; 92 }标签:typedef,InternalImageType,ITK,isolatedConnected,New,脑部,include,PNG,itk From: https://www.cnblogs.com/ybqjymy/p/17634893.html