首页 > 其他分享 >VTK 实例39:拉普拉斯算子(边缘检测)

VTK 实例39:拉普拉斯算子(边缘检测)

时间:2023-08-15 11:56:33浏览次数:58  
标签:ShiftScale 39 1.0 VTK vtkSmartPointer 算子 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 <vtkImageCanvasSource2D.h>
 8 #include <vtkImageShiftScale.h>
 9 #include <vtkRenderWindow.h>
10 #include <vtkRenderWindowInteractor.h>
11 #include <vtkInteractorStyleImage.h>
12 #include <vtkRenderer.h>
13 #include <vtkImageActor.h>
14 #include <vtkJPEGReader.h>
15 #include <vtkImageLaplacian.h>
16 
17 //测试图像:../data/lena-gray.jpg
18 int main(int argc, char* argv[])
19 {
20     vtkSmartPointer<vtkJPEGReader> reader =
21         vtkSmartPointer<vtkJPEGReader>::New();
22     reader->SetFileName("lena-gray.jpg");
23     reader->Update();
24 
25     vtkSmartPointer<vtkImageLaplacian> lapFilter =
26         vtkSmartPointer<vtkImageLaplacian>::New();
27     lapFilter->SetInputConnection(reader->GetOutputPort());
28     lapFilter->SetDimensionality(2);
29 
30     double range[2];
31     lapFilter->GetOutput()->GetScalarRange(range);
32 
33     vtkSmartPointer<vtkImageShiftScale> ShiftScale =
34         vtkSmartPointer<vtkImageShiftScale>::New();
35     ShiftScale->SetOutputScalarTypeToUnsignedChar();
36     ShiftScale->SetScale( 255 / (range[1]-range[0]) );
37     ShiftScale->SetShift(-range[0]);
38     ShiftScale->SetInputConnection(lapFilter->GetOutputPort());
39     ShiftScale->Update();
40 
41     vtkSmartPointer<vtkImageActor> originalActor =
42         vtkSmartPointer<vtkImageActor>::New();
43     originalActor->SetInputData(reader->GetOutput());
44 
45     vtkSmartPointer<vtkImageActor> gradActor =
46         vtkSmartPointer<vtkImageActor>::New();
47     gradActor->SetInputData(ShiftScale->GetOutput());
48 
49     double originalViewport[4] = {0.0, 0.0, 0.5, 1.0};
50     double gradviewport[4] = {0.5, 0.0, 1.0, 1.0};
51 
52     vtkSmartPointer<vtkRenderer> originalRenderer =
53         vtkSmartPointer<vtkRenderer>::New();
54     originalRenderer->SetViewport(originalViewport);
55     originalRenderer->AddActor(originalActor);
56     originalRenderer->ResetCamera();
57     originalRenderer->SetBackground(1.0, 1.0, 1.0);
58 
59     vtkSmartPointer<vtkRenderer> gradRenderer =
60         vtkSmartPointer<vtkRenderer>::New();
61     gradRenderer->SetViewport(gradviewport);
62     gradRenderer->AddActor(gradActor);
63     gradRenderer->ResetCamera();
64     gradRenderer->SetBackground(1.0, 1.0, 1.0);
65 
66     vtkSmartPointer<vtkRenderWindow> renderWindow =
67         vtkSmartPointer<vtkRenderWindow>::New();
68     renderWindow->AddRenderer(originalRenderer);
69     renderWindow->AddRenderer(gradRenderer);
70     renderWindow->SetSize(640, 320);
71     renderWindow->Render();
72     renderWindow->SetWindowName("LaplacianExample");
73 
74     vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
75         vtkSmartPointer<vtkRenderWindowInteractor>::New();
76     vtkSmartPointer<vtkInteractorStyleImage> style =
77         vtkSmartPointer<vtkInteractorStyleImage>::New();
78 
79     renderWindowInteractor->SetInteractorStyle(style);
80     renderWindowInteractor->SetRenderWindow(renderWindow);
81     renderWindowInteractor->Initialize();
82     renderWindowInteractor->Start();
83 
84     return EXIT_SUCCESS;
85 }

标签:ShiftScale,39,1.0,VTK,vtkSmartPointer,算子,renderWindow,New,include
From: https://www.cnblogs.com/ybqjymy/p/17630966.html

相关文章

  • VTK 实例40:均值滤波(图像光滑)
    1#include"vtkAutoInit.h"2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkInteractionStyle);45#include<vtkSmartPointer.h>6#include<vtkImageData.h>7#include<vtkImageConvolve.h>8#include<vt......
  • VTK 实例31:灰度图像直方图
    1#include"vtkAutoInit.h"2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkInteractionStyle);45#include<vtkActor.h>6#include<vtkBarChartActor.h>7#include<vtkFieldData.h>8#include<v......
  • VTK 实例32:图像重采样(降采样)
    1#include"vtkAutoInit.h"2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkInteractionStyle);45#include<vtkSmartPointer.h>6#include<vtkImageData.h>7#include<vtkImageShiftScale.h>8#include<......
  • i7 13650hx和i9 13900h差距 酷睿i713650hx和i913900h对比
    i713650hx采用10nm工艺最高睿频4.9GHz十四核心二十线程三级缓存24MB热设计功耗(TDP)55W支持最大内存128GB内存类型DDR43200MHzDDR54800MHz集成显卡IntelUHDGraphics选i713650HX是i913900h这些点很重要 http://www.adiannao.cn/dyi913900h采用10纳米制作工艺......
  • 评测 i7 13700hx和i9 13900h差距 酷睿i713700hx和i913900h对比
    i913900h采用10纳米制作工艺最高睿频5.4GHz十四核心二十线程三级缓存36MB热设计功耗(TDP)115W支持最大内存64GB内存类型DDR43200MHzDDR55200MHz集成显卡IntelIrisXeGraphics选i713700hx还是i913900H这些点很重要看过你就懂了 http://www.adiannao.cn/dyi71......
  • 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......
  • 评测i9 13900hx和​​R9 7940HS选哪个 酷睿i913900hx和​​锐龙R97940HS对比
    i913900Hx采用10nm制作工艺最高睿频5.4GHz二十四核心三十二线程三级缓存36MB热设计功耗(TDP)157W选i913900hx和R97940HS这些点很重要看过你就懂了 http://www.adiannao.cn/dy​​R97940HS采用了4nm工艺,采用8核Zen4CPU,并且搭载最新的锐龙AI引擎,CPU频率可达5.2GHz......
  • 达人评测i9 13900h和i5 12500h选哪个好 i913900h和i512500h对比
    i913900h采用10纳米制作工艺最高睿频5.4GHz十四核心二十线程三级缓存36MB热设计功耗(TDP)115W支持最大内存64GB内存类型DDR43200MHzDDR55200MHz集成显卡IntelIrisXeGraphics笔记本cpu选i512500H还是i913900H这些点很重要看过你就懂了 http://www.adiannao.cn......
  • i913900h和i913900hx区别 i9 13900h和i9 13900hx差距
    i913900h采用10纳米制作工艺最高睿频5.4GHz十四核心二十线程三级缓存36MB热设计功耗(TDP)115W支持最大内存64GB内存类型DDR43200MHzDDR55200MHz集成显卡IntelIrisXeGraphics笔记本cpu选i913900hx还是i913900H这些点很重要看过你就懂了 http://www.adiannao.c......