首页 > 其他分享 >VTK 实例32:图像重采样(降采样)

VTK 实例32:图像重采样(降采样)

时间:2023-08-15 11:47:45浏览次数:41  
标签:采样 1.0 32 VTK vtkSmartPointer reader renderWindow New include

 1 #include "vtkAutoInit.h" 
 2 VTK_MODULE_INIT(vtkRenderingOpenGL2);
 3 VTK_MODULE_INIT(vtkInteractionStyle);
 4 
 5 #include <vtkSmartPointer.h>
 6 #include <vtkImageData.h>
 7 #include <vtkImageShiftScale.h>
 8 #include <vtkRenderWindow.h>
 9 #include <vtkRenderWindowInteractor.h>
10 #include <vtkInteractorStyleImage.h>
11 #include <vtkRenderer.h>
12 #include <vtkImageActor.h>
13 #include <vtkBMPReader.h>
14 #include <vtkImageShrink3D.h>
15 
16 //测试图像:../data/lena.bmp
17 int main(int argc, char* argv[])
18 {
19     vtkSmartPointer<vtkBMPReader> reader =
20         vtkSmartPointer<vtkBMPReader>::New();
21     reader->SetFileName("lena.bmp");
22     reader->Update();
23 
24     vtkSmartPointer<vtkImageShrink3D> shrinkFilter = 
25         vtkSmartPointer<vtkImageShrink3D>::New();
26     shrinkFilter->SetInputConnection(reader->GetOutputPort());
27     shrinkFilter->SetShrinkFactors(20,20,1);
28     shrinkFilter->Update();
29 
30     int originalDims[3];
31     reader->GetOutput()->GetDimensions(originalDims);
32 
33     double originalSpace[3];
34     reader->GetOutput()->GetSpacing(originalSpace);
35 
36     int shrinkDims[3];
37     shrinkFilter->GetOutput()->GetDimensions(shrinkDims);
38 
39     double shrinkSpace[3];
40     shrinkFilter->GetOutput()->GetSpacing(shrinkSpace);
41 
42     std::cout<<"原图图像维数      :"<<originalDims[0] << " "<<originalDims[1]<<" "<<originalDims[2]<<std::endl;
43     std::cout<<"原图图像像素间隔  :"<<originalSpace[0] << " "<<originalSpace[1]<<" "<<originalSpace[2]<<std::endl;
44     std::cout<<"重采样图像维数    :"<<shrinkDims[0] << " "<<shrinkDims[1]<<" "<<shrinkDims[2]<<std::endl;
45     std::cout<<"重采样图像像素间隔:"<<shrinkSpace[0] << " "<<shrinkSpace[1]<<" "<<shrinkSpace[2]<<std::endl;
46 
47     vtkSmartPointer<vtkImageActor> originalActor =
48         vtkSmartPointer<vtkImageActor>::New();
49     originalActor->SetInputData( reader->GetOutput());
50 
51     vtkSmartPointer<vtkImageActor> shrinkActor =
52         vtkSmartPointer<vtkImageActor>::New();
53     shrinkActor->SetInputData(shrinkFilter->GetOutput());
54 
55     double originalViewport[4] = {0.0, 0.0, 0.5, 1.0};
56     double shrinkViewport[4] = {0.5, 0.0, 1.0, 1.0};
57 
58     vtkSmartPointer<vtkRenderer> originalRenderer =
59         vtkSmartPointer<vtkRenderer>::New();
60     originalRenderer->SetViewport(originalViewport);
61     originalRenderer->AddActor(originalActor);
62     originalRenderer->ResetCamera();
63     originalRenderer->SetBackground(1.0, 1.0, 1.0);
64 
65     vtkSmartPointer<vtkRenderer> shrinkRenderer =
66         vtkSmartPointer<vtkRenderer>::New();
67     shrinkRenderer->SetViewport(shrinkViewport);
68     shrinkRenderer->AddActor(shrinkActor);
69     shrinkRenderer->ResetCamera();
70     shrinkRenderer->SetBackground(1.0, 1.0, 1.0);
71 
72     vtkSmartPointer<vtkRenderWindow> renderWindow =
73         vtkSmartPointer<vtkRenderWindow>::New();
74     renderWindow->AddRenderer(originalRenderer);
75     renderWindow->AddRenderer(shrinkRenderer);
76     renderWindow->SetSize(640, 480);
77     renderWindow->Render();
78     renderWindow->SetWindowName("ImageShrink3DExample");
79 
80     vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
81         vtkSmartPointer<vtkRenderWindowInteractor>::New();
82     vtkSmartPointer<vtkInteractorStyleImage> style =
83         vtkSmartPointer<vtkInteractorStyleImage>::New();
84 
85     renderWindowInteractor->SetInteractorStyle(style);
86     renderWindowInteractor->SetRenderWindow(renderWindow);
87     renderWindowInteractor->Initialize();
88     renderWindowInteractor->Start();
89 
90     return EXIT_SUCCESS;
91 }

标签:采样,1.0,32,VTK,vtkSmartPointer,reader,renderWindow,New,include
From: https://www.cnblogs.com/ybqjymy/p/17630919.html

相关文章

  • VTK 实例33:图像重采样(降和升采样)
    1#include"vtkAutoInit.h"2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkInteractionStyle);45#include<vtkSmartPointer.h>6#include<vtkImageData.h>7#include<vtkRenderWindow.h>8#include......
  • VTK 实例26:将BMP类型的RGB图像转换为灰度图像
    1#include"vtkAutoInit.h"2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkInteractionStyle);45#include<vtkSmartPointer.h>6#include<vtkImageData.h>7#include<vtkRenderWindow.h>8#include<vtk......
  • stm32cubemx 配置波特率
    1、参考链接:https://www.cnblogs.com/forever-youth/p/15807690.html 2、步骤:   1、先算出连接can总线的PCLK1时钟频率   2、再根据公式:can波特率=pclk1/((tbs1+tbs2+sync_seg)*brp)     其中PCLK1就是时钟频率,sync_seg一般默认固定为1   ......
  • 删数问题 洛谷p1323
    决定做一系列贪心,贪心真的,最早学的算法,到现在还有时候不太敢贪,还贪不来,一直挺逃避贪心问题的。。 删除前的数字可以先用优先队列对所有数字进行预处理,数据范围是3e4,也不是很大,直接全部处理了吧。constintN=1e5+10,inf=0x3f3f3f3f3f3f3f3f,MAX=3e4+10;inta[N]......
  • VTK 实例20:用vtkImageViewer2显示三维医学图像mhd的某个切面
    1#include"vtkAutoInit.h"2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkInteractionStyle);45#include<vtkSmartPointer.h>6#include<vtkImageViewer2.h>7#include<vtkRenderWindow.h>8#include<......
  • VTK 实例6:加入灯光(蓝色背景+白色演员+红色环境光)
    1#include"vtkAutoInit.h"2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkInteractionStyle);45#include<vtkConeSource.h>//源数据6#include<vtkPolyDataMapper.h>//数据映射7#include<vtkRenderer.h>//绘制器8#......
  • VTK 实例5:设置椎体颜色属性
    1#include"vtkAutoInit.h"2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkInteractionStyle);45#include<vtkConeSource.h>//源数据6#include<vtkPolyDataMapper.h>//数据映射7#include<vtkRenderer.h>//绘制器8#......
  • VTK 实例7:相机控制
    未加入相机控制时演员位置: 加入相机控制时演员位置(视角为x轴负方向):1#include"vtkAutoInit.h"2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkInteractionStyle);45#include<vtkConeSource.h>//源数据6#include<vtkPolyDataMapper.h>//数据......
  • VTK 实例8:command与observe设计模式(当交互使相机变化时打印出当前相机的坐标,当发生拾
    1#include"vtkAutoInit.h"2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkInteractionStyle);4#include<vtkConeSource.h>5#include<vtkPolyDataMapper.h>6#include<vtkRenderer.h>7#include<vtkRende......
  • VTK 实例9:坐标系统1
    1#include"vtkAutoInit.h"2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkInteractionStyle);4#include<vtkConeSource.h>//源数据5#include<vtkCubeSource.h>//立方体6#include<vtkPolyDataMapper.h>//数据映射7#in......