1 #include "itkImage.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 //定义浮点像素类型 InternalPixelType
10 typedef float InternalPixelType;
11 const unsigned int Dimension = 3;
12 //定义浮点、维数2的图像类型 InternalImageType
13 typedef itk::Image< InternalPixelType, Dimension > InternalImageType;
14 //定义无符号字符 输出像素类型 OutputPixelType
15 typedef unsigned char OutputPixelType;
16 //定义无符号字符、维数2 输出图像类型 OutputImageType
17 typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
18 //定义滤波输入图像类型InternalImageType 滤波输出图像类型OutputImageType
19 typedef itk::CastImageFilter< InternalImageType, OutputImageType >
20 CastingFilterType;
21 //实例化滤波器对象caster
22 CastingFilterType::Pointer caster = CastingFilterType::New();
23 //定义图像读取类型ReaderType
24 typedef itk::ImageFileReader< InternalImageType > ReaderType;
25 //定义图像写类型WriterType
26 typedef itk::ImageFileWriter< OutputImageType > WriterType;
27
28 ReaderType::Pointer reader = ReaderType::New();
29 WriterType::Pointer writer = WriterType::New();
30
31 reader->SetFileName("BrainProtonDensity3Slices.mha");
32 writer->SetFileName("lvbo_CastingFilter.mha");
33
34 //实例化滤波对象smoothing
35 typedef itk::CurvatureFlowImageFilter< InternalImageType, InternalImageType >
36 CurvatureFlowImageFilterType;
37 CurvatureFlowImageFilterType::Pointer smoothing =
38 CurvatureFlowImageFilterType::New();
39
40 现在连接管道
41 smoothing->SetInput(reader->GetOutput());
42 //输出滤波后的效果图
43 caster->SetInput(smoothing->GetOutput());
44 writer->SetInput(caster->GetOutput());
45
46 /*IsolatedConnectedImageFilter 期望用户指定一个门限和两个种子。在这个例子中,我们
47 从命令行得到它们*/
48 smoothing->SetNumberOfIterations(12);
49 smoothing->SetTimeStep(0.125);
50
51 try
52 {
53 writer->Update();
54 }
55 catch (itk::ExceptionObject & excep)
56 {
57 std::cerr << "Exception caught !" << std::endl;
58 std::cerr << excep << std::endl;
59 }
60
61 return EXIT_SUCCESS;
62 }