1 #include "itkImage.h"
2 //这个例子阐述了 SetPixel( )和 GetPixel( )方法的用法
3 //可以直接访问图像中包含的像素数据
4 int main(int, char *[])
5 }; //Size along
11 const ImageType::IndexType start = }; // First index on
12
13 ImageType::RegionType region;
14 region.SetSize( size );
15 region.SetIndex( start );
16
17 // Pixel data is allocated
18 image>SetRegions( region );
19 image>Allocate(true); // initialize buffer to zero
20 //对 index 类型实例的声明并进行初始化
21 const ImageType::IndexType pixelIndex = }; // Position of
22 //GetPixel(pixelIndex)方法将可得到pixelIndex处的像素值pixelValue
23 ImageType::PixelType pixelValue = image>GetPixel( pixelIndex );
24
25 std::cout << "pixelIndex处的像素值:"<<pixelValue << std::endl;//输出pixelIndex索引处的像素值pixelValue
26 //SetPixel( )方法可设定像素值,将pixelIndex索引处的像素值赋值为pixelValue+1
27 image>SetPixel( pixelIndex, pixelValue+12 );
28
29 ImageType::PixelType pixelValue1 = image>GetPixel(pixelIndex);//获取更改后的像素值
30 std::cout << "更改后pixelIndex处的像素值:" << pixelValue1 << std::endl;//输出pixelIndex索引处的像素值
31
32 return EXIT_SUCCESS;
33 }
图像基础:
在这个图表中,圆卷表示像素的中心;
像素间距是像素中心之间的距离;如本图表中,X方向像素间距为20,Y方向上像素间距为30;
图像原点是图像中第一个像素的坐标;如图中原点坐标(60,70);
一个像素就是含有数据值的像素中心周围的矩形区域;
图像大小指的是图像长宽方向像素个数相乘;如图中图像大小为7*6=42(像素);
上一篇:VTK 实例54:封闭性检测下一篇:VTK 实例63:纹理映射
ITK