VTK 实例21:BMP图像信息的访问(图像维数、原点坐标和像素间隔)


1 #include "vtkAutoInit.h" 2 VTK_MODULE_INIT(vtkRenderingOpenGL2); 3 VTK_MODULE_INIT(vtkInteractionStyle); 4 5 #include <vtkSmartPointer.h> 6 #include <vtkImageViewer2.h> 7 #include <vtkRenderWindoh> 8 #include <vtkRenderWindowInteractor.h> 9 #include <vtkRenderer.h> 10 #include <vtkImageReader2Factory.h> 11 #include <vtkImageReader2.h> 12 #include <vtkBMPReader.h> 13 #include <vtkImageData.h> 14 15 //测试图像:../data/lena.bmp 16 int main(int argc, char* argv[]) 17 */ 23 vtkSmartPointer<vtkBMPReader> reader = 24 vtkSmartPointer<vtkBMPReader>::New(); 25 //reader>SetFileName ( argv[1] ); 26 reader>SetFileName("1234.bmp");//读取图片 27 reader>Update(); 28 29 int dims[3]; 30 reader>GetOutput()>GetDimensions(dims); 31 std::cout<<"图像维数:" <<dims[0]<<" "<<dims[1]<<" "<<dims[2]<<std::endl; 32 33 double origin[3]; 34 reader>GetOutput()>GetOrigin(origin); 35 std::cout<<"图像原点:" <<origin[0]<<" "<<origin[1]<<" "<<origin[2]<<std::endl; 36 37 double spaceing[3]; 38 reader>GetOutput()>GetSpacing(spaceing); 39 std::cout<<"像素间隔:" <<spaceing[0]<<" "<<spaceing[1]<<" "<<spaceing[2]<<std::endl; 40 41 vtkSmartPointer<vtkImageViewer2> imageViewer = 42 vtkSmartPointer<vtkImageViewer2>::New(); 43 imageViewer>SetInputConnection(reader>GetOutputPort()); 44 45 vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor = 46 vtkSmartPointer<vtkRenderWindowInteractor>::New(); 47 imageViewer>SetupInteractor(renderWindowInteractor); 48 imageViewer>Render(); 49 imageViewer>GetRenderer()>ResetCamera(); 50 imageViewer>Render(); 51 52 imageViewer>GetRenderer()>SetBackground(1.0, 1.0, 1.0); 53 imageViewer>SetSize(640, 480); 54 imageViewer>GetRenderWindow()>SetWindowName("GetImageInformationExample"); 55 56 renderWindowInteractor>Start(); 57 58 return EXIT_SUCCESS; 59 }



上一篇:VTK 实例20:用vtkImageViewer2显示三维医学图像mhd的某个切面

下一篇:VTK 实例22:JPG图像信息的访问(图像维数、原点坐标和像素间隔)


VTK
Copyright © 2002-2019 k262电脑网 www.k262.cn 皖ICP备2020016292号
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!QQ:251442993 热门搜索 网站地图