[Insight-users] convert unsign int pixel type dicom file into MetaImage with gdcm

Hsiang-Chi Kuo kuoxgx at gmail.com
Sun Apr 26 03:29:11 EDT 2009


Hi,
I am tring to read a Dicom RT file (unsign int pixel type) and convert it to
mhd file.
The Dicom file is a muti fram format with "Grid Frame Offset Vector tag:
(3004,000C)". I used gdcm (1.2) to read the size, spacing, and origin, and
pixel data. Then comvert the pixel format into MetaImage.
The line of "  unsigned int *imageData = fh->GetImageDataRaw(); "  output
the error message: 'initializing' : cannot convert from 'uint8_t *' to
'unsigned short *'.
The line of "  itk::ImageRegionIterator< ImageType > it(im,
im->GetLargestPossibleRegion());
" returned : cannot convert from 'unsigned short *' to 'const unsigned int .
Can anyone give me an idea how to resolve the error?
Thanks a lot.
Howard


#include "itkImageFileReader.h"

#include "itkImageFileWriter.h"

#include "gdcmFileHelper.h"

#include "gdcmFile.h"

#include <itkImage.h>

#include <itkMetaImageIO.h>

#include <itkImageRegionIterator.h>

#include <stdio.h>  //sscanf



int main( int argc, char* argv[] )

{

  if( argc < 2 )

    {

    std::cerr << "Usage: " << std::endl;

    std::cerr << argv[0] << " DicomImage OutputDicomImage ";

    //std::cerr << " OutputImage RescaleDicomImage\n";

    return EXIT_FAILURE;

    }



  typedef unsigned int InputPixelType;

  const unsigned int   InputDimension = 3;



  typedef itk::Image< InputPixelType, InputDimension > InputImageType;

  typedef itk::ImageFileReader< InputImageType > ReaderType;



  gdcm::File *f1 = new gdcm::File();

   f1->SetFileName( argv[1] );

   f1->Load();



   int linesNumber   = f1->GetYSize();

   int rawsNumber    = f1->GetXSize();

   int framesNumber  = f1->GetZSize();// defaulted to 1 if not found



            float xs = f1->GetXSpacing();

   float ys = f1->GetYSpacing();

   float zs = f1->GetZSpacing();// defaulted to 1.0 if not found strSpacing
(0x3004,0x000c)



            const std::string strSpacing = f1->GetEntryValue(0x3004,0x000c);


            const int MaxZ = 256;

     float sp[MaxZ] ;

               if ( strSpacing != gdcm::GDCM_UNFOUND )

                        {

                                    if ( sscanf( strSpacing.c_str(), "%f \\
%f ", &sp[0], &sp[1]) > 0 )

                                    zs = sp[1]-sp[0];

                        }



   float xo = f1->GetXOrigin();

   float yo = f1->GetYOrigin();

   float zo = f1->GetZOrigin();



            gdcm::FileHelper *fh = new gdcm::FileHelper();

            unsigned int *imageData = fh->GetImageDataRaw();



            typedef itk::Image<unsigned int, 3> ImageType;



  ImageType::SizeType imSize = {{linesNumber, rawsNumber, framesNumber}};

  ImageType::Pointer im = ImageType::New();

  im->SetRegions(imSize);

  im->Allocate();



  // Set some values in the image

  itk::ImageRegionIterator< ImageType > it(im,

        im->GetLargestPossibleRegion());



  it.GoToBegin();

  while(imageData)

    {

    it.Set(imageData );

    ++it;

    }



  typedef itk::ImageFileWriter< ImageType > VolumeWriterType;

  VolumeWriterType::Pointer writer = VolumeWriterType::New();



  itk::MetaImageIO::Pointer metaWriter = itk::MetaImageIO::New();

  writer->SetImageIO( metaWriter );



  writer->SetFileName( "test.mhd" );



  writer->SetInput( im );

  writer->Update();



  delete f1;

  delete fh;



  return EXIT_SUCCESS;

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090426/e33fadc0/attachment-0001.htm>


More information about the Insight-users mailing list