[Insight-users] Simple raw to png test
Todd Gable
Todd_Gable at invision.iip.com
Fri Feb 4 19:35:11 EST 2005
I simply want to load one of our raw CT images, then save it to a .png (to verify it loaded ok). When I run it I get the following error:
itk::ExceptionObject (00FCF150)
Location: "Unknown"
File: \Dev\InsightToolkit-1.8.1\InsightToolkit-1.8.1\Code\Io\itkPNGImageIO.cxx
Line: 395
Description: itk::ERROR: PNGImageIO(0022C698): PNG Writer can only write 2-dime
sional images
Can anyone give me a pointer? Thanks.
/******************* Start code ************************/
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkRawImageIO.h"
#include "itkImage.h"
#include <string>
using namespace std;
int main( int argc, char ** argv )
{
typedef unsigned short PixelType;
const unsigned int Dimension = 2;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::RawImageIO<PixelType,Dimension> IOType;
IOType::Pointer io = IOType::New();
io->SetFileTypeToBinary();
io->SetFileDimensionality(Dimension);
io->SetByteOrderToBigEndian();
typedef itk::ImageFileReader<ImageType> ReaderType;
typedef itk::ImageFileWriter<ImageType> WriterType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
string inputFilename = "336.raw";
string outputFilename = "336.png";
cout << "Reading " << inputFilename << endl;
reader->SetFileName( inputFilename.c_str() );
reader->SetImageIO( io );
writer->SetFileName( outputFilename.c_str() );
writer->SetInput( reader->GetOutput() );
cout << "Writing " << outputFilename << endl;
try
{
writer->Update();
}
catch( itk::ExceptionObject & err )
{
std::cout << "ExceptionObject caught !" << std::endl;
std::cout << err << std::endl;
return -1;
}
return 0;
}
/******************* End code ************************/
Todd Gable
More information about the Insight-users
mailing list