PNG, BMP, JPG image reading and display
Read and display.jpg images: vtkJPEGReader
VS15+VTK7.0 Console instance:
Read and display.jpg images: vtkJPEGReader
VS15+VTK7.0 Console instance:
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2);
#include <vtkSmartPointer.h>
#include <vtkImageViewer2.h>
#include <vtkJPEGReader.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
int main()
{
//Verify input arguments
/*
Filename(.jpeg)"
*/
//Read the image
vtkSmartPointer<vtkJPEGReader> jpegReader =vtkSmartPointer<vtkJPEGReader>::New();
jpegReader->SetFileName("F:\\vtkshuju\\lena.jpg");
// Visualize
vtkSmartPointer<vtkImageViewer2> imageViewer = vtkSmartPointer<vtkImageViewer2>::New();
imageViewer->SetInputConnection(jpegReader->GetOutputPort());
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =vtkSmartPointer<vtkRenderWindowInteractor>::New();
imageViewer->SetupInteractor(renderWindowInteractor);
imageViewer->Render();
imageViewer->GetRenderer()->ResetCamera();
imageViewer->Render();
imageViewer->GetRenderWindow()->SetWindowName("read and show jpg test");
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
p>
Console instance under VS15+VTK7.0:
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2);
//read and show .mha
#include <vtkImageData.h>
#include <vtkMetaImageReader.h>
#include <vtkSmartPointer.h>
#include <vtkInteractorStyleImage.h>
#include <vtkRenderer.h>
#include <vtkImageActor.h>
#include <vtkImageMapper3D.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
int main()
{
// image.mha
vtkSmartPointer<vtkMetaImageReader> reader =
vtkSmartPointer<vtkMetaImageReader>::New();
reader->SetFileName("F:\\vtkshuju\\itkBrainSliceComplex.mha");
reader->Update();
// Visualize
vtkSmartPointer<vtkImageActor> actor =
vtkSmartPointer<vtkImageActor>::New();
actor->GetMapper()->SetInputConnection(reader->GetOutputPort());
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
renderer->ResetCamera();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
vtkSmartPointer<vtkInteractorStyleImage> style =
vtkSmartPointer<vtkInteractorStyleImage>::New();
renderWindowInteractor->SetInteractorStyle(style);
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindowInteractor->Initialize();
renderWindowInteractor->GetRenderWindow()->SetWindowName(".mha pic test");
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
PNG image read and display: vtkPNGReader:
Console instance under VS15+VTK7.0:
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2);
//read and show png
#include <vtkSmartPointer.h>
#include <vtkImageViewer2.h>
#include <vtkPNGReader.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
int main()
{
// Verify input arguments
// << " Filename(.png)" << std::endl;
// Read the image
vtkSmartPointer<vtkPNGReader> reader =
vtkSmartPointer<vtkPNGReader>::New();
reader->SetFileName("F:\\vtkshuju\\BrainProtonDensitySlice.png");
// Visualize
vtkSmartPointer<vtkImageViewer2> imageViewer =
vtkSmartPointer<vtkImageViewer2>::New();
imageViewer->SetInputConnection(reader->GetOutputPort());
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
imageViewer->SetupInteractor(renderWindowInteractor);
imageViewer->Render();
imageViewer->GetRenderer()->ResetCamera();
imageViewer->Render();
imageViewer->GetRenderWindow()->SetWindowName("read and show png test");
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
Console instance under VS15+VTK7.0:
#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2);
VTK_MODULE_INIT(vtkInteractionStyle);
VTK_MODULE_INIT(vtkRenderingFreeType);
VTK_MODULE_INIT(vtkRenderingVolumeOpenGL2);
#include <vtkSmartPointer.h>
#include <vtkImageViewer2.h>
#include <vtkBMPReader.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
int main(int argc, char* argv[])
{
//Verify input arguments
// << " Filename(.bmp)" << std::endl;
//Read the image
vtkSmartPointer<vtkBMPReader> reader =
vtkSmartPointer<vtkBMPReader>::New();
reader->SetFileName("F:\\vtkshuju\\masonry.bmp");
// Visualize
vtkSmartPointer<vtkImageViewer2> imageViewer =
vtkSmartPointer<vtkImageViewer2>::New();
imageViewer->SetInputConnection(reader->GetOutputPort());
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
imageViewer->SetupInteractor(renderWindowInteractor);
imageViewer->Render();
imageViewer->GetRenderer()->ResetCamera();
imageViewer->Render();
imageViewer->GetRenderWindow()->SetWindowName("read and show bmp test");
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
Read More:
- Reading and display of various image formats in VTK
- VTK cultivation 26: basic operation of image_ Three dimensional image slice extraction
- ImageIO.read () unsupported image type when reading picture_ exception Unsupported Image Type
- [debug notes] pointer error when STD:: vector is used in VTK “access conflict when reading location XXX”
- Record a problem of no module named ‘tensorflow. Examples’ and’ tensorflow. Examples. Tutorials’ in tensorflow 2.0
- VTK notes — texture mapping
- VTK: VTK error problem set
- Using vtk8.1 in qcreator
- Solutions to several VTK compilation errors (vtk5.8 + VS2010)
- Ueditor paste word image and upload image file automatically
- Regarding [java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Boolean], combined with examples
- VTK series: installation and introduction of VTK
- Ant Design upload listtype = “picture card” realizes multi image upload and click preview image encapsulation
- [docker] error in deleting image: image is referenced in multiple repositories
- Win10 desktop right click display settings MS- settings:display Or Ms- settings:personalization-background resolvent
- Usage and examples of three important functions of tidyr package in R language: gather, spread and separate
- [Python] numpy library array splicing np.concatenate Detailed explanation and examples of official documents
- [VTK] header file and lib file name often used in VTK
- Using qvtk renderwindoninteractor to load VTK widget
- Can’t open display: can’t open display: localhost:10.0