首页 > 其他分享 >VTK 实例36:图像二值化

VTK 实例36:图像二值化

时间:2023-08-15 11:59:03浏览次数:52  
标签:thresholdFilter 1.0 VTK 36 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 <vtkRenderWindow.h>
 8 #include <vtkRenderWindowInteractor.h>
 9 #include <vtkInteractorStyleImage.h>
10 #include <vtkRenderer.h>
11 #include <vtkImageActor.h>
12 #include <vtkJPEGReader.h>
13 #include <vtkImageThreshold.h>
14 #include <vtkImageCast.h>
15 
16 //测试图像:../data/lena-gray.jpg
17 int main(int argc, char* argv[])
18 {
19     vtkSmartPointer<vtkJPEGReader> reader =
20         vtkSmartPointer<vtkJPEGReader>::New();
21     reader->SetFileName("lena-gray.jpg");
22     reader->Update();
23 
24     vtkSmartPointer<vtkImageThreshold> thresholdFilter =
25         vtkSmartPointer<vtkImageThreshold>::New();
26     thresholdFilter->SetInputConnection(reader->GetOutputPort());
27     thresholdFilter->ThresholdByUpper(100);//设置阈值为100
28     thresholdFilter->SetInValue(255);//大于100的设置为255
29     thresholdFilter->SetOutValue(0);//小于100的设置为0
30     thresholdFilter->Update();//算法执行后必须添加更新消息
31 
32     vtkSmartPointer<vtkImageActor> originalActor =
33         vtkSmartPointer<vtkImageActor>::New();
34     originalActor->SetInputData(reader->GetOutput());
35 
36     vtkSmartPointer<vtkImageActor> binaryActor =
37         vtkSmartPointer<vtkImageActor>::New();
38     binaryActor->SetInputData(thresholdFilter->GetOutput());
39 
40     double originalViewport[4] = {0.0, 0.0, 0.5, 1.0};
41     double binaryviewport[4] = {0.5, 0.0, 1.0, 1.0};
42 
43     vtkSmartPointer<vtkRenderer> originalRenderer =
44         vtkSmartPointer<vtkRenderer>::New();
45     originalRenderer->SetViewport(originalViewport);
46     originalRenderer->AddActor(originalActor);
47     originalRenderer->ResetCamera();
48     originalRenderer->SetBackground(1.0, 1.0, 1.0);
49 
50     vtkSmartPointer<vtkRenderer> binaryRenderer =
51         vtkSmartPointer<vtkRenderer>::New();
52     binaryRenderer->SetViewport(binaryviewport);
53     binaryRenderer->AddActor(binaryActor);
54     binaryRenderer->ResetCamera();
55     binaryRenderer->SetBackground(1.0, 1.0, 1.0);
56 
57     vtkSmartPointer<vtkRenderWindow> renderWindow =
58         vtkSmartPointer<vtkRenderWindow>::New();
59     renderWindow->AddRenderer(originalRenderer);
60     renderWindow->AddRenderer(binaryRenderer);
61     renderWindow->SetSize(640, 320);
62     renderWindow->Render();
63     renderWindow->SetWindowName("ImageBinaryExample");
64 
65     vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
66         vtkSmartPointer<vtkRenderWindowInteractor>::New();
67     vtkSmartPointer<vtkInteractorStyleImage> style =
68         vtkSmartPointer<vtkInteractorStyleImage>::New();
69 
70     renderWindowInteractor->SetInteractorStyle(style);
71     renderWindowInteractor->SetRenderWindow(renderWindow);
72     renderWindowInteractor->Initialize();
73     renderWindowInteractor->Start();
74 
75     return EXIT_SUCCESS;
76 }

标签:thresholdFilter,1.0,VTK,36,vtkSmartPointer,renderWindow,New,include,二值化
From: https://www.cnblogs.com/ybqjymy/p/17630954.html

相关文章

  • VTK 实例37:梯度算子(边缘检测)
    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......
  • VTK 实例38:Sobel梯度算子(边缘检测)
    1#include"vtkAutoInit.h"2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkInteractionStyle);45#include<vtkSmartPointer.h>6#include<vtkImageMathematics.h>7#include<vtkImageData.h>8#inc......
  • VTK 实例39:拉普拉斯算子(边缘检测)
    1#include"vtkAutoInit.h"2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkInteractionStyle);45#include<vtkSmartPointer.h>6#include<vtkImageData.h>7#include<vtkImageCanvasSource2D.h>8#include......
  • 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和13700h 差距 i713650hx和13700h对比
    i713650hx采用10nm工艺最高睿频4.9GHz十四核心二十线程三级缓存24MB热设计功耗(TDP)55W支持最大内存128GB内存类型DDR43200MHzDDR54800MHz集成显卡IntelUHDGraphics笔记本cpu选i713650hx还是i713700h这些点很重要看过你就懂了 http://www.adiannao.cn/dyi7......
  • 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 13650hx参数 酷睿i713650hx性能怎么样相当于什么水平
    i713650hx采用10nm工艺最高睿频4.9GHz十四核心二十线程三级缓存24MB热设计功耗(TDP)55W支持最大内存128GB内存类型DDR43200MHzDDR54800MHz集成显卡IntelUHDGraphicsi713650hx性能怎么样这些点很重要看过你就懂了 http://www.adiannao.cn/dy ......
  • 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......