VTK修炼之道42:频域处理_高通滤波(理想+巴特沃兹)
生活随笔
收集整理的這篇文章主要介紹了
VTK修炼之道42:频域处理_高通滤波(理想+巴特沃兹)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.理想高通濾波器
高通濾波與低通濾波正好相反,是頻域圖像的高頻部分通過而抑制低頻部分。在圖像中圖像的邊緣對應高頻分量,因此高通濾波的效果是圖像銳化。同樣最簡單的高通濾波器是理想高通濾波器。通過設置一個頻率閾值,將高于該閾值的頻率部分通過,而低于閾值的低頻部分設置為0。
VTK中理想高通濾波的實例如下:
#include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRenderingOpenGL);#include <vtkSmartPointer.h> #include <vtkJPEGReader.h> #include <vtkImageFFT.h> #include <vtkImageIdealHighPass.h> #include <vtkImageRFFT.h> #include <vtkImageCast.h> #include <vtkImageExtractComponents.h> #include <vtkRenderer.h> #include <vtkImageActor.h> #include <vtkRenderWindow.h> #include <vtkRenderWindowInteractor.h> #include <vtkInteractorStyleImage.h>int main(int argc, char* argv[]) {vtkSmartPointer<vtkJPEGReader> reader =vtkSmartPointer<vtkJPEGReader>::New();reader->SetFileName("lena.jpg");reader->Update();vtkSmartPointer<vtkImageFFT> fftFilter =vtkSmartPointer<vtkImageFFT>::New();fftFilter->SetInputConnection(reader->GetOutputPort());fftFilter->Update();vtkSmartPointer<vtkImageIdealHighPass> highPassFilter =vtkSmartPointer<vtkImageIdealHighPass>::New();highPassFilter->SetInputConnection(fftFilter->GetOutputPort());highPassFilter->SetXCutOff(0.1);highPassFilter->SetYCutOff(0.1);highPassFilter->Update();vtkSmartPointer<vtkImageRFFT> rfftFilter =vtkSmartPointer<vtkImageRFFT>::New();rfftFilter->SetInputConnection(highPassFilter->GetOutputPort());rfftFilter->Update();vtkSmartPointer<vtkImageExtractComponents> ifftExtractReal =vtkSmartPointer<vtkImageExtractComponents>::New();ifftExtractReal->SetInputConnection(rfftFilter->GetOutputPort());ifftExtractReal->SetComponents(0);vtkSmartPointer<vtkImageCast> castFilter =vtkSmartPointer<vtkImageCast>::New();castFilter->SetInputConnection(ifftExtractReal->GetOutputPort());castFilter->SetOutputScalarTypeToUnsignedChar();castFilter->Update();/vtkSmartPointer<vtkImageActor> originalActor =vtkSmartPointer<vtkImageActor>::New();originalActor->SetInputData(reader->GetOutput());vtkSmartPointer<vtkImageActor> erodedActor =vtkSmartPointer<vtkImageActor>::New();erodedActor->SetInputData(castFilter->GetOutput());/double leftViewport[4] = { 0.0, 0.0, 0.5, 1.0 };double rightViewport[4] = { 0.5, 0.0, 1.0, 1.0 };vtkSmartPointer<vtkRenderer> leftRenderer =vtkSmartPointer<vtkRenderer>::New();leftRenderer->AddActor(originalActor);leftRenderer->SetViewport(leftViewport);leftRenderer->SetBackground(1.0, 1.0, 1.0);leftRenderer->ResetCamera();vtkSmartPointer<vtkRenderer> rightRenderer =vtkSmartPointer<vtkRenderer>::New();rightRenderer->AddActor(erodedActor);rightRenderer->SetViewport(rightViewport);rightRenderer->SetBackground(1.0, 1.0, 1.0);rightRenderer->ResetCamera();/vtkSmartPointer<vtkRenderWindow> rw =vtkSmartPointer<vtkRenderWindow>::New();rw->SetSize(640, 320);rw->AddRenderer(leftRenderer);rw->AddRenderer(rightRenderer);rw->SetWindowName("IdealHighPassExample");vtkSmartPointer<vtkRenderWindowInteractor> rwi =vtkSmartPointer<vtkRenderWindowInteractor>::New();vtkSmartPointer<vtkInteractorStyleImage> style =vtkSmartPointer<vtkInteractorStyleImage>::New();rwi->SetInteractorStyle(style);rwi->SetRenderWindow(rw);rwi->Start();return 0; }
下面是理想高通濾波的執行結果:
從結果看出高通濾波后圖像得到銳化處理,圖像中僅剩下邊緣。
2.巴特沃茲高通濾波
理想高通濾波器不能通過電子元器件來實現,而且存在振鈴現象。在實際中最常使用的高通濾波器是巴特沃斯高通濾波器。該濾波器的轉移函數是:
D(u,v)表示頻域中點到頻域平面的距離,是截止頻率。當D(u,v)大于時,對應的H(u,v)逐漸接近1,從而使得高頻部分得以通過;而當D(u,v)小于時,H(u,v)逐漸接近0,實現低頻部分過濾。巴特沃斯高通濾波器在VTK中對應vtkImageButterworthHighPass類。
下面代碼說明了vtkImageButterworthHighPass對圖像進行高通濾波:
#include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRenderingOpenGL);#include <vtkSmartPointer.h> #include <vtkJPEGReader.h> #include <vtkImageFFT.h> #include <vtkImageButterworthHighPass.h> #include <vtkImageRFFT.h> #include <vtkImageExtractComponents.h> #include <vtkImageCast.h> #include <vtkRenderer.h> #include <vtkImageActor.h> #include <vtkRenderWindow.h> #include <vtkRenderWindowInteractor.h> #include <vtkInteractorStyleImage.h>int main(int argc, char* argv[]) {vtkSmartPointer<vtkJPEGReader> reader =vtkSmartPointer<vtkJPEGReader>::New();reader->SetFileName("lena.jpg");reader->Update();vtkSmartPointer<vtkImageFFT> fftFilter =vtkSmartPointer<vtkImageFFT>::New();fftFilter->SetInputConnection(reader->GetOutputPort());fftFilter->Update();vtkSmartPointer<vtkImageButterworthHighPass> highPassFilter =vtkSmartPointer<vtkImageButterworthHighPass>::New();highPassFilter->SetInputConnection(fftFilter->GetOutputPort());highPassFilter->SetXCutOff(0.1);highPassFilter->SetYCutOff(0.1);highPassFilter->Update();vtkSmartPointer<vtkImageRFFT> rfftFilter =vtkSmartPointer<vtkImageRFFT>::New();rfftFilter->SetInputConnection(highPassFilter->GetOutputPort());rfftFilter->Update();vtkSmartPointer<vtkImageExtractComponents> ifftExtractReal =vtkSmartPointer<vtkImageExtractComponents>::New();ifftExtractReal->SetInputConnection(rfftFilter->GetOutputPort());ifftExtractReal->SetComponents(0);vtkSmartPointer<vtkImageCast> castFilter =vtkSmartPointer<vtkImageCast>::New();castFilter->SetInputConnection(ifftExtractReal->GetOutputPort());castFilter->SetOutputScalarTypeToUnsignedChar();castFilter->Update();vtkSmartPointer<vtkImageActor> originalActor =vtkSmartPointer<vtkImageActor>::New();originalActor->SetInputData(reader->GetOutput());vtkSmartPointer<vtkImageActor> erodedActor =vtkSmartPointer<vtkImageActor>::New();erodedActor->SetInputData(castFilter->GetOutput());//double leftViewport[4] = { 0.0, 0.0, 0.5, 1.0 };double rightViewport[4] = { 0.5, 0.0, 1.0, 1.0 };vtkSmartPointer<vtkRenderer> leftRenderer =vtkSmartPointer<vtkRenderer>::New();leftRenderer->AddActor(originalActor);leftRenderer->ResetCamera();leftRenderer->SetViewport(leftViewport);leftRenderer->SetBackground(1.0, 1.0, 1.0);vtkSmartPointer<vtkRenderer> rightRenderer =vtkSmartPointer<vtkRenderer>::New();rightRenderer->AddActor(erodedActor);rightRenderer->SetViewport(rightViewport);rightRenderer->SetBackground(1.0, 1.0, 1.0);rightRenderer->ResetCamera();vtkSmartPointer<vtkRenderWindow> rw =vtkSmartPointer<vtkRenderWindow>::New();rw->AddRenderer(leftRenderer);rw->AddRenderer(rightRenderer);rw->SetSize(640, 320);rw->Render();rw->SetWindowName("Frequency_ButterworthHighPass");/vtkSmartPointer<vtkRenderWindowInteractor> rwi =vtkSmartPointer<vtkRenderWindowInteractor>::New();vtkSmartPointer<vtkInteractorStyleImage> style =vtkSmartPointer<vtkInteractorStyleImage>::New();rwi->SetInteractorStyle(style);rwi->SetRenderWindow(rw);rwi->Start();return 0; }
下圖是執行結果:
3.參看資料
1.《C++ primer》
2.《The VTK User’s Guide – 11thEdition》
3. ?張曉東, 羅火靈. VTK圖形圖像開發進階[M]. 機械工業出版社, 2015.
總結
以上是生活随笔為你收集整理的VTK修炼之道42:频域处理_高通滤波(理想+巴特沃兹)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: eNet 软件发布要求多多
- 下一篇: 程序员啊程序员...济南昊锐科技