VTK修炼之道22:图像基本操作_彩色图像成分提取
生活随笔
收集整理的這篇文章主要介紹了
VTK修炼之道22:图像基本操作_彩色图像成分提取
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.彩色圖像RGB成分提取
VTK中利用vtkImageExtractComponents可以方便的提取出彩色圖像的各個顏色分量,該類的使用比較簡單,只需要設置要提取的分量序號即可。下面代碼說明了怎樣提取彩色圖像的某個顏色分量。 #include <vtkAutoInit.h> VTK_MODULE_INIT(vtkRenderingOpenGL);#include <vtkSmartPointer.h> #include <vtkBMPReader.h> #include <vtkImageExtractComponents.h> #include <vtkImageActor.h> #include <vtkRenderer.h> #include <vtkRenderWindow.h> #include <vtkRenderWindowInteractor.h> #include <vtkInteractorStyleImage.h>int main() {vtkSmartPointer<vtkBMPReader> reader =vtkSmartPointer<vtkBMPReader>::New();reader->SetFileName("lena.bmp");vtkSmartPointer<vtkImageExtractComponents> redComponent =vtkSmartPointer<vtkImageExtractComponents>::New();redComponent->SetInputConnection(reader->GetOutputPort());redComponent->SetComponents(0);redComponent->Update();vtkSmartPointer<vtkImageExtractComponents> greenComponent =vtkSmartPointer<vtkImageExtractComponents>::New();greenComponent->SetInputConnection(reader->GetOutputPort());greenComponent->SetComponents(1);greenComponent->Update();vtkSmartPointer<vtkImageExtractComponents> blueComponent =vtkSmartPointer<vtkImageExtractComponents>::New();blueComponent->SetInputConnection(reader->GetOutputPort());blueComponent->SetComponents(2);blueComponent->Update();//創建演員vtkSmartPointer<vtkImageActor> origActor =vtkSmartPointer<vtkImageActor>::New();origActor->SetInputData(reader->GetOutput());vtkSmartPointer<vtkImageActor> redActor =vtkSmartPointer<vtkImageActor>::New();redActor->SetInputData(redComponent->GetOutput());vtkSmartPointer<vtkImageActor> greenActor =vtkSmartPointer<vtkImageActor>::New();greenActor->SetInputData(greenComponent->GetOutput());vtkSmartPointer<vtkImageActor> blueActor =vtkSmartPointer<vtkImageActor>::New();blueActor->SetInputData(blueComponent->GetOutput());//定義窗口 并化妝double origView[4] = { 0.0, 0.0, 0.25, 1.0 };double redView[4] = { 0.25, 0.0, 0.5, 1.0 };double greenView[4] = { 0.5, 0.0, 0.75, 1.0 };double blueView[4] = { 0.75, 0.0, 1.0, 1.0 };vtkSmartPointer<vtkRenderer> origRender =vtkSmartPointer<vtkRenderer>::New();origRender->SetViewport(origView);origRender->AddActor(origActor);origRender->ResetCamera();origRender->SetBackground(1.0, 1.0, 1.0);vtkSmartPointer<vtkRenderer> redRender =vtkSmartPointer<vtkRenderer>::New();redRender->SetViewport(redView);redRender->AddActor(redActor);redRender->ResetCamera();redRender->SetBackground(1.0, 1.0, 1.0);vtkSmartPointer<vtkRenderer> greenRender =vtkSmartPointer<vtkRenderer>::New();greenRender->SetViewport(greenView);greenRender->AddActor(greenActor);greenRender->ResetCamera();greenRender->SetBackground(1.0, 1.0, 1.0);vtkSmartPointer<vtkRenderer> blueRender =vtkSmartPointer<vtkRenderer>::New();blueRender->SetViewport(blueView);blueRender->AddActor(blueActor);blueRender->ResetCamera();blueRender->SetBackground(1.0, 1.0, 1.0);//上舞臺vtkSmartPointer<vtkRenderWindow> renderwindow =vtkSmartPointer<vtkRenderWindow>::New();renderwindow->AddRenderer(origRender);renderwindow->AddRenderer(redRender);renderwindow->AddRenderer(greenRender);renderwindow->AddRenderer(blueRender);renderwindow->SetSize(960, 320);renderwindow->Render();renderwindow->SetWindowName("ExtraImageColorComponents");//設置交互vtkSmartPointer<vtkRenderWindowInteractor> rwi =vtkSmartPointer<vtkRenderWindowInteractor>::New();vtkSmartPointer<vtkInteractorStyleImage> style =vtkSmartPointer<vtkInteractorStyleImage>::New();rwi->SetInteractorStyle(style);rwi->SetRenderWindow(renderwindow);rwi->Initialize();rwi->Start(); return 0; }2.參看資料
1.《C++ primer》2.《The VTK User’s Guide – 11thEdition》
3.《The Visualization Toolkit – AnObject-Oriented Approach To 3D Graphics (4th Edition)》
4. ?張曉東, 羅火靈. VTK圖形圖像開發進階[M]. 機械工業出版社, 2015.
總結
以上是生活随笔為你收集整理的VTK修炼之道22:图像基本操作_彩色图像成分提取的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 谈谈我的程序人生程序生涯-飞鸽传书
- 下一篇: “XEIM”国内开源即时通讯XEIM