[Insight-users] Simple raw to png test
Karthik Krishnan
Karthik.Krishnan at kitware.com
Sat Feb 5 19:25:50 EST 2005
Hi Todd,
I believe you forgot to add the line:
io->SetDimensions(0,XSizeOfTheFile);
io->SetDimensions(1,YSizeOfTheFile);
You need to specify that explicitly for RAW files unless you have a
header, which I am assuming you don't.
Thanks
kk
Todd Gable wrote:
>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
>
>_______________________________________________
>Insight-users mailing list
>Insight-users at itk.org
>http://www.itk.org/mailman/listinfo/insight-users
>
>
>
More information about the Insight-users
mailing list