首页 > 其他分享 >VTK 实例44:二维图像快速傅里叶变换(频域处理)

VTK 实例44:二维图像快速傅里叶变换(频域处理)

时间:2023-08-15 12:29:18浏览次数:44  
标签:ShiftScale 1.0 VTK 频域 vtkSmartPointer renderWindow New include 44

  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 <vtkImageFFT.h>
  8 #include <vtkImageRFFT.h>
  9 #include <vtkRenderWindow.h>
 10 #include <vtkRenderWindowInteractor.h>
 11 #include <vtkInteractorStyleImage.h>
 12 #include <vtkRenderer.h>
 13 #include <vtkImageActor.h>
 14 #include <vtkImageCast.h>
 15 #include <vtkJPEGReader.h>
 16 #include <vtkImageExtractComponents.h>
 17 #include <vtkImageFourierCenter.h>
 18 #include <vtkImageMagnitude.h>
 19 #include <vtkImageShiftScale.h>
 20 
 21 //测试图像:../data/lena-gray.jpg
 22 int main(int argc, char* argv[])
 23 {
 24     vtkSmartPointer<vtkJPEGReader> reader =
 25         vtkSmartPointer<vtkJPEGReader>::New();
 26     reader->SetFileName ("lena-gray.jpg");
 27     reader->Update();
 28 
 29     vtkSmartPointer<vtkImageFFT> fftFilter = 
 30         vtkSmartPointer<vtkImageFFT>::New();
 31     fftFilter->SetInputConnection(reader->GetOutputPort());
 32     fftFilter->SetDimensionality(2);
 33     fftFilter->Update();
 34 
 35     vtkSmartPointer<vtkImageExtractComponents> fftExtractReal =
 36         vtkSmartPointer<vtkImageExtractComponents>::New();
 37     fftExtractReal->SetInputConnection(fftFilter->GetOutputPort());
 38     fftExtractReal->SetComponents(0);
 39 
 40     double range[2];
 41     fftExtractReal->GetOutput()->GetScalarRange(range);
 42 
 43     vtkSmartPointer<vtkImageShiftScale> ShiftScale =
 44         vtkSmartPointer<vtkImageShiftScale>::New();
 45     ShiftScale->SetOutputScalarTypeToUnsignedChar();
 46     ShiftScale->SetScale( 255.0 / (range[1]-range[0]) );
 47     ShiftScale->SetShift(-range[0]);
 48     ShiftScale->SetInputConnection(fftExtractReal->GetOutputPort());
 49     ShiftScale->Update();
 50 
 51     vtkSmartPointer<vtkImageRFFT> rfftFilter =
 52         vtkSmartPointer<vtkImageRFFT>::New();
 53     rfftFilter->SetInputConnection(fftFilter->GetOutputPort());
 54     rfftFilter->SetDimensionality(2);
 55     rfftFilter->Update();
 56 
 57     vtkSmartPointer<vtkImageExtractComponents> ifftExtractReal =
 58         vtkSmartPointer<vtkImageExtractComponents>::New();
 59     ifftExtractReal->SetInputConnection(rfftFilter->GetOutputPort());
 60     ifftExtractReal->SetComponents(0);
 61 
 62     vtkSmartPointer<vtkImageCast> rfftCastFilter =
 63         vtkSmartPointer<vtkImageCast>::New();
 64     rfftCastFilter->SetInputConnection(ifftExtractReal->GetOutputPort());
 65     rfftCastFilter->SetOutputScalarTypeToUnsignedChar();
 66     rfftCastFilter->Update();
 67 
 68     vtkSmartPointer<vtkImageActor> originalActor =
 69         vtkSmartPointer<vtkImageActor>::New();
 70     originalActor->SetInputData(reader->GetOutput());
 71 
 72     vtkSmartPointer<vtkImageActor> fftActor =
 73         vtkSmartPointer<vtkImageActor>::New();
 74     fftActor->SetInputData(ShiftScale->GetOutput());
 75 
 76     vtkSmartPointer<vtkImageActor> rfftActor =
 77         vtkSmartPointer<vtkImageActor>::New();
 78     rfftActor->SetInputData(rfftCastFilter->GetOutput());
 79 
 80     double originalViewport[4] = {0.0, 0.0, 0.33, 1.0};
 81     double fftViewport[4] = {0.33, 0.0, 0.66, 1.0};
 82     double rfftViewport[4] = {0.66, 0.0, 1.0, 1.0};
 83 
 84     vtkSmartPointer<vtkRenderer> originalRenderer =
 85         vtkSmartPointer<vtkRenderer>::New();
 86     originalRenderer->SetViewport(originalViewport);
 87     originalRenderer->AddActor(originalActor);
 88     originalRenderer->ResetCamera();
 89     originalRenderer->SetBackground(1.0, 1.0, 1.0);
 90 
 91     vtkSmartPointer<vtkRenderer> fftRenderer =
 92         vtkSmartPointer<vtkRenderer>::New();
 93     fftRenderer->SetViewport(fftViewport);
 94     fftRenderer->AddActor(fftActor);
 95     fftRenderer->ResetCamera();
 96     fftRenderer->SetBackground(1.0, 1.0, 1.0);
 97 
 98     vtkSmartPointer<vtkRenderer> rfftRenderer =
 99         vtkSmartPointer<vtkRenderer>::New();
100     rfftRenderer->SetViewport(rfftViewport);
101     rfftRenderer->AddActor(rfftActor);
102     rfftRenderer->ResetCamera();
103     rfftRenderer->SetBackground(1.0, 1.0, 1.0);
104 
105     vtkSmartPointer<vtkRenderWindow> renderWindow =
106         vtkSmartPointer<vtkRenderWindow>::New();
107     renderWindow->AddRenderer(originalRenderer);
108     renderWindow->AddRenderer(fftRenderer);
109     renderWindow->AddRenderer(rfftRenderer);
110     renderWindow->SetSize(640, 320);
111     renderWindow->Render();
112     renderWindow->SetWindowName("FFTAndRFFTExample");
113 
114     vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
115         vtkSmartPointer<vtkRenderWindowInteractor>::New();
116     vtkSmartPointer<vtkInteractorStyleImage> style =
117         vtkSmartPointer<vtkInteractorStyleImage>::New();
118 
119     renderWindowInteractor->SetInteractorStyle(style);
120     renderWindowInteractor->SetRenderWindow(renderWindow);
121     renderWindowInteractor->Initialize();
122     renderWindowInteractor->Start();
123 
124     return EXIT_SUCCESS;
125 }

标签:ShiftScale,1.0,VTK,频域,vtkSmartPointer,renderWindow,New,include,44
From: https://www.cnblogs.com/ybqjymy/p/17631006.html

相关文章

  • VTK 实例35:图像运算(逻辑运算)
    1#include"vtkAutoInit.h"2VTK_MODULE_INIT(vtkRenderingOpenGL2);3VTK_MODULE_INIT(vtkInteractionStyle);45#include<vtkSmartPointer.h>6#include<vtkMath.h>7#include<vtkImageData.h>8#include<vtk......
  • 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<......
  • 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......