[Insight-users] convert raw data to ITK

LeeWoojin lwj0616 at naver.com
Mon Jul 28 01:34:01 EDT 2008


Hi all.
 
I have a problem with itkImage.
 
I want to convert raw data to itkImageType.
 
I've loaded .png file using ATL::CImage class(MFC 2003). 
 
and I want to convert this memory data to itkImageType.
 
My code is follow:
 
///////////////////////////////
 typedef itk::ImportImageFilter< BytePixelType, Dimension > ImportFilterType;
 ImportFilterType::Pointer importer = ImportFilterType::New();
 image = ImageType::New();
 
 int nx = imgBase.GetWidth();
 int ny = imgBase.GetHeight();
 ImageType::SizeType size;
 size[0] = nx;
 size[1] = ny;
 ImageType::IndexType start;
 start.Fill(0);
 ImageType::RegionType region;
 region.SetSize( size );
 region.SetIndex( start );
 importer->SetRegion( region );
 double origin[2];
 origin[0] = 0; //originX;
 origin[1] = 0; //originY;
 importer->SetOrigin( origin );
 double spacing[2];
 spacing[0] = 1; //dx;
 spacing[1] = 1; //dy;
 importer->SetSpacing( spacing );
 const int totalNumberOfPixels = nx * ny;
 BytePixelType *pixelData = static_cast< BytePixelType * >( (BYTE *)imgBase.GetBits() );
// BytePixelType *pixelData = new BytePixelType[totalNumberOfPixels];
// pixelData = static_cast< BytePixelType * >( (BYTE *)imgBase.GetBits() );
 const bool importFilterWillDeleteTheInputBuffer = false;
 importer->SetImportPointer( pixelData,
 totalNumberOfPixels,
 importFilterWillDeleteTheInputBuffer );
 importer->Update();
 image->GetInput( importer->GetOutput() );
 typedef itk::ImageFileWriter WriterType;
 WriterType::Pointer writer = WriterType::New();
// writer->SetInput( filter->GetOutput() );
 writer->SetInput( image );
 writer->SetFileName("output.bmp");
 try
 {
 writer->Update();
 }
 catch( itk::ExceptionObject & exp ) 
 {
 std::cerr << "Exception caught !" << std::endl;
 std::cerr << exp << std::endl;
 }
///////////////
 
width and height is same. but image data is nothing
 
help me..
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20080728/0deedbab/attachment.htm>


More information about the Insight-users mailing list