1 #include "itkImage.h"//图像类的头文件
2
3 //这个例子阐述了如何人为地创建一个 itk::Image 类,下面是对图像类进行实例化、声明
4 //和创建的最简单程序代码。
5
6 int main(int, char *[])
7 {
8 //创建 一个三维、像素是无符号短字符数据类型的图像
9 typedef itk::Image< unsigned short, 3 > ImageType;
10 //调用 New( )操作创建图像image,并将结果分配到 itk::SmartPointer
11 ImageType::Pointer image = ImageType::New();
12 //图像的起始点是由一个Index类定义的,这个类中存放了一个n维数列
13 //表示图像中各维上最初的像素值
14 ImageType::IndexType start;
15
16 start[0] = 0; // first index on X 图像X维最初的像素值
17 start[1] = 0; // first index on Y 图像Y维最初的像素值
18 start[2] = 0; // first index on Z 图像Z维最初的像素值
19
20 //区域大小是用一个相同大小的图像数列来表示的(使用 Size 类),数列中的元素是无符号
21 //整数,表示图像像素在各个方向上的延伸。
22 ImageType::SizeType size;
23
24 size[0] = 200; // size along X 图像像素在X方向上的大小
25 size[1] = 200; // size along Y 图像像素在Y方向上的大小
26 size[2] = 200; // size along Z 图像像素在Z方向上的大小
27
28 //创建一个 ImageRegion 对象,这个region区域是用图像的起始地址和大小来初始化的
29 ImageType::RegionType region;
30
31 region.SetSize( size );//初始化图像大小
32 region.SetIndex( start );//初始化图像起始地址
33 //这个区域传递给图像对象来定义其延伸和初始地址
34 image->SetRegions( region );
35 //调用 Allocate( )来进行分配内存
36 image->Allocate();
37
38 return EXIT_SUCCESS;
39 }