[Insight-users] how can I convert the image type

Guorong Wu grwu at sjtu.edu.cn
Thu Jul 1 03:03:12 EDT 2004


hello:
     I want to convert one type of image to another type, for example, I will convert RatLungSlice1.mha to RatLungSlice.png. I write a simple program as follows but it doesn't work. The output is all black. I guess it is wrong to simply link the imagefilereader and imagefilewriter without doing anything. Can you tell me what work I should do or which section I shuold refer to the document of  ITKSoftwareGuide? Thanks.

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkImage.h"
#include "itkPNGImageIO.h"
main(int argc, char **argv)
{
	typedef unsigned short PixelType;
	const unsigned int Dimension=2;
	typedef itk::Image<PixelType, Dimension> ImageType;
	typedef itk::ImageFileReader<ImageType> ReaderType;
	typedef itk::ImageFileWriter<ImageType> WriterType;
	typedef itk::PNGImageIO ImageIOType;
	ReaderType::Pointer reader=ReaderType::New();
	WriterType::Pointer writer=WriterType::New();
	ImageIOType::Pointer pngIO=ImageIOType::New();
	//const char *InputFilename=argv[1];
	//const char *OutputFilename=argv[2];
	reader->SetFileName("RatLungSlice1.mha);
	writer->SetFileName("RatLungSlice1.png");
	writer->SetInput(reader->GetOutput());
	writer->SetImageIO(pngIO);
	writer->Update();
	return 0;

} 
 				

        Guorong Wu
        grwu at sjtu.edu.cn
          2004-07-01

=============================================================
Guorong Wu	
The Department of Computer Science and Technology
Shanghai Jiao Tong University
1954 Huashan RD
Shanghai China    
200030
Tel:  +86 21 3226 1236  , 6293 2089
=============================================================
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fox.gif
Type: image/gif
Size: 9519 bytes
Desc: not available
Url : http://public.kitware.com/pipermail/insight-users/attachments/20040701/9c045e51/fox-0001.gif


More information about the Insight-users mailing list