ITK image data reading and writing and display

Source: Internet
Author: User
Tags doxygen

ITK image Data read:

1: Set image data types such as common BMP, JPG, JPEG, dicom, RAW, etc.

2: Data read

The following example is the read and write of PNG image data implemented under the console:

#include "itkRGBPixel.h" #include "itkImage.h" #include "itkImageFileReader.h" #include "itkImageFileWriter.h" #  Include "ItkPNGImageIOFactory.h"//ITK file reader and writer Test int main () {//Verify the number of parameters in the command line//software Guide:beginlatex/////The \doxygen{rgbpixel} class was templated over the type used to/ /represent each one of the red, green and blue components.
	A Typical//instantiation of the RGB image class might be as follows. \index{itk::rgbpixel! Instantiation}////software Guide:endlatex//software guide:begincodesnippet typedef itk::rgbpixel< Unsigne
	D char > Pixeltype; typedef itk::image< PIXELTYPE, 2 > Imagetype;//set the type of pic//software Guide:endcodesnippet//S Oftware Guide:beginlatex////The image type is used as a template parameter to instantiate//the reader and writer
	. \index{itk::imagefilereader! RGB Image}//\index{itk::imagefilewriter! RGB Image}////software Guide:endlatex//software guide:begincodesnippet typedef itk::imagefilereader< IMAGETYPE  ;
	Readertype;

	typedef itk::imagefilewriter< IMAGETYPE > Writertype;
	Readertype::P ointer reader = readertype::new ();
	Writertype::P ointer writer = writertype::new ();
Software guide:endcodesnippet ITK::P ngimageiofactory::registeronefactory ();
const char * inputfilename = argv[1];


	const char * outputfilename = argv[2]; Software Guide:beginlatex////The filenames of the input and output files must be provided to the//reader A
	nd writer respectively.
	Software Guide:endlatex//software Guide:begincodesnippet reader->setfilename ("1.png");
	Writer->setfilename ("2.png");
	Software guide:endcodesnippet ImageType::P ointer image = Reader->getoutput ();


	Writer->setinput (image); Software Guide:beginlatex////Finally, execution of the pipeline can be triggered by invoking the//Update () Method in the writer.
	Software Guide:endlatex//software Guide:begincodesnippet writer->update (); Software Guide:endcodesnippet//software Guide:beginlatex/////may have noticed this apart from the DEC Laration of the//\code{pixeltype} There is nothing in this code specific to RGB//images.
	All of the actions required to support color images is implemented//internally in the \doxygen{imageio} objects.
Software Guide:endlatex return exit_success; }
ITK and VTK realize the display of the image:

Using ITK to realize the reading of image data, and then through the connector to the ITK read image data transfer to VTK and then display;

Below is an implementation of the ITK and VTK hybrid programming implemented in the console to realize the display of the image:

#include "itkImage.h" #include "itkImageFileReader.h" #include "itkImageToVTKImageFilter.h" #include " 
ItkPNGImageIOFactory.h "#include" vtkImageViewer.h "#include" vtkRenderWindowInteractor.h "#include" vtkAutoInit.h " Vtk_module_init (vtkRenderingOpenGL2);
VTK was built with VtkRenderingOpenGL2 Vtk_module_init (Vtkinteractionstyle); ITK and VTK to show picture test int main (int argc, char **argv) {typedef itk::image<unsigned char, 2> ImageType   ;//the type of pic typedef itk::imagefilereader<imagetype> READERTYPE;  The class of read pic typedef itk::imagetovtkimagefilter<imagetype> CONNECTORTYPE;
	Connenct ITK and VTK readertype::P ointer reader = readertype::new ();
	Connectortype::P ointer connector = connectortype::new ();

	Reader->setfilename ("1.png");

	ITK::P ngimageiofactory::registeronefactory ();
	Connector->setinput (Reader->getoutput ());

	Connector->update ();
	Vtkimageviewer *viewer = Vtkimageviewer::new (); Vtkrenderwindowinteractor *inTeractor = Vtkrenderwindowinteractor::new ();
	Viewer->setinputdata (Connector->getoutput ());
	Viewer->setupinteractor (interactor); Viewer->getrenderwindow (->setsize),//set window size Viewer->setcolorwindow (255);   Set Window Color Viewer->setcolorlevel (128);
	
	Set the level of window Viewer->render ();
	Interactor->initialize ();
	Interactor->start ();
return exit_success; }



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.