首页 > 其他分享 >VTK 实例35:图像运算(逻辑运算)

VTK 实例35:图像运算(逻辑运算)

时间:2023-08-15 11:59:47浏览次数:47  
标签:逻辑运算 VTK imageSource1 35 vtkSmartPointer imageSource2 New 100 include

  1 #include "vtkAutoInit.h" 
  2 VTK_MODULE_INIT(vtkRenderingOpenGL2);
  3 VTK_MODULE_INIT(vtkInteractionStyle);
  4 
  5 #include <vtkSmartPointer.h>
  6 #include <vtkMath.h>
  7 #include <vtkImageData.h>
  8 #include <vtkImageCanvasSource2D.h>
  9 #include <vtkImageLogic.h>
 10 #include <vtkRenderWindow.h>
 11 #include <vtkRenderWindowInteractor.h>
 12 #include <vtkInteractorStyleImage.h>
 13 #include <vtkRenderer.h>
 14 #include <vtkImageActor.h>
 15 
 16 int main(int, char *[])
 17 {
 18     vtkSmartPointer<vtkImageCanvasSource2D> imageSource1 =
 19         vtkSmartPointer<vtkImageCanvasSource2D>::New();
 20     imageSource1->SetScalarTypeToUnsignedChar();
 21     imageSource1->SetNumberOfScalarComponents(1);
 22     imageSource1->SetExtent(0, 100, 0, 100, 0, 0);
 23     imageSource1->SetDrawColor(0.0);
 24     imageSource1->FillBox(0,100,0,100);
 25     imageSource1->SetDrawColor(255);
 26     imageSource1->FillBox(20,60,20,60);
 27     imageSource1->Update();
 28 
 29     vtkSmartPointer<vtkImageCanvasSource2D> imageSource2 = 
 30         vtkSmartPointer<vtkImageCanvasSource2D>::New();
 31     imageSource2->SetNumberOfScalarComponents(1);
 32     imageSource2->SetScalarTypeToUnsignedChar();
 33     imageSource2->SetExtent(0, 100, 0, 100, 0, 0);
 34     imageSource2->SetDrawColor(0.0);
 35     imageSource2->FillBox(0,100,0,100);
 36     imageSource2->SetDrawColor(255.0);
 37     imageSource2->FillBox(40,80,40,80);
 38     imageSource2->Update();
 39 
 40     vtkSmartPointer<vtkImageLogic> imageLogic = 
 41         vtkSmartPointer<vtkImageLogic>::New();
 42     imageLogic->SetInputData(imageSource1->GetOutput());
 43     imageLogic->SetInputData(imageSource2->GetOutput());
 44     imageLogic->SetOperationToXor();
 45     imageLogic->SetOutputTrueValue(128);
 46     imageLogic->Update();
 47 
 48     vtkSmartPointer<vtkImageActor> originalActor1 =
 49         vtkSmartPointer<vtkImageActor>::New();
 50     originalActor1->SetInputData(imageSource1->GetOutput());
 51 
 52     vtkSmartPointer<vtkImageActor> originalActor2 =
 53         vtkSmartPointer<vtkImageActor>::New();
 54     originalActor2->SetInputData(imageSource2->GetOutput());
 55 
 56     vtkSmartPointer<vtkImageActor> logicActor =
 57         vtkSmartPointer<vtkImageActor>::New();
 58     logicActor->SetInputData(imageLogic->GetOutput());
 59 
 60     double leftViewport[4] = {0.0, 0.0, 0.33, 1.0};
 61     double midViewport[4] = {0.33, 0.0, 0.66, 1.0};
 62     double rightViewport[4] = {0.66, 0.0, 1.0, 1.0};
 63 
 64     vtkSmartPointer<vtkRenderer> originalRenderer1 =
 65         vtkSmartPointer<vtkRenderer>::New();
 66     originalRenderer1->SetViewport(leftViewport);
 67     originalRenderer1->AddActor(originalActor1);
 68     originalRenderer1->ResetCamera();
 69     originalRenderer1->SetBackground(1.0, 1.0, 1.0);
 70 
 71     vtkSmartPointer<vtkRenderer> originalRenderer2 =
 72         vtkSmartPointer<vtkRenderer>::New();
 73     originalRenderer2->SetViewport(midViewport);
 74     originalRenderer2->AddActor(originalActor2);
 75     originalRenderer2->ResetCamera();
 76     originalRenderer2->SetBackground(0.8, 0.8, 0.8);
 77 
 78     vtkSmartPointer<vtkRenderer> logicRenderer =
 79         vtkSmartPointer<vtkRenderer>::New();
 80     logicRenderer->SetViewport(rightViewport);
 81     logicRenderer->AddActor(logicActor);
 82     logicRenderer->ResetCamera();
 83     logicRenderer->SetBackground(0.6, 0.6, 0.6);
 84 
 85     vtkSmartPointer<vtkRenderWindow> renderWindow =
 86         vtkSmartPointer<vtkRenderWindow>::New();
 87     renderWindow->AddRenderer(originalRenderer1);
 88     renderWindow->AddRenderer(originalRenderer2);
 89     renderWindow->AddRenderer(logicRenderer);
 90     renderWindow->SetSize(640, 320);
 91     renderWindow->Render();
 92     renderWindow->SetWindowName("ImageLogicExample");
 93 
 94     vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
 95         vtkSmartPointer<vtkRenderWindowInteractor>::New();
 96     vtkSmartPointer<vtkInteractorStyleImage> style =
 97         vtkSmartPointer<vtkInteractorStyleImage>::New();
 98 
 99     renderWindowInteractor->SetInteractorStyle(style);
100     renderWindowInteractor->SetRenderWindow(renderWindow);
101     renderWindowInteractor->Initialize();
102     renderWindowInteractor->Start();
103 
104     return EXIT_SUCCESS;
105 }

标签:逻辑运算,VTK,imageSource1,35,vtkSmartPointer,imageSource2,New,100,include
From: https://www.cnblogs.com/ybqjymy/p/17630949.html

相关文章

  • VTK 实例36:图像二值化
    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 实例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 13500hx参数 酷睿i713500hx性能怎么样相当于什么水平
    i713500hx采用10nm工艺最高睿频4.7GHz十四核心二十线程三级缓存24MB热设计功耗(TDP)55W支持最大内存128GB内存类型DDR43200MHzDDR54800MHz集成显卡IntelUHDGraphicsi713500hx性能怎么样这些点很重要看过你就懂了 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......
  • iTOP-RK3588开发板单独编译Android固件-打包update.img
    在ubootkernelandroid都编译完成的情况下,才可以打包update.img,所以一般在完整编译的时候用。输入以下命令:./build.sh-u打包完成会在rockdev/Image-rk3588_s目录下生成update.img镜像。更多内容:B站搜索迅为RK3588开发板......