[Insight-users] read a meta image and write a volume to DICOM

wordon m9421001 at gmail.com
Tue Sep 20 10:32:01 EDT 2005


 Hi,Bill :

Thanks for your code.
I test it under VC6.0 and winXP command line,but has some problem.
1)It sometimes has error execution when I run the program.
  ex:  
     >irdw headmrvolume.mhd t1
       numberOfSlices: 42
       file: t1.dcm1.dcm
       file: t1.dcm2.dcm
              .
              .
              .
       file: t1.dcm32.dcm
       file: t1.dcm33.dcm
     -->In this time,the program has error execution.
  
  My question is : Has any restrain in this program?


2)sometimes,the program can be run correctly.
  ex:
     >D:\play>irdw vhfcolor.mhd t11
       numberOfSlices: 10
       file: t111.dcm
       file: t112.dcm
              .
              . 
       file: t119.dcm
       file: t1110.dcm
                        (this step can run correctly)
      But the series can not transform to a volume(.dcm) using fixed program 
     'DicomSeriesReadImageWrite2.cxx'.

 The code for DicomSeriesReadImageWrite2.cxx is :

==================================================================

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

  if( argc < 3 )
    {
    std::cerr << "Usage: " << argv[0] << " DicomDirectory 
outputFileName  [seriesName]" << std::endl;
    return EXIT_FAILURE;
    }

  typedef itk::Image<unsigned short,3>            ImageType;
  typedef itk::ImageSeriesReader< ImageType >     ReaderType;

  typedef itk::GDCMImageIO                        ImageIOType;
    
  ImageIOType::Pointer dicomIO = ImageIOType::New();

  // Get the DICOM filenames from the directory
  typedef itk::GDCMSeriesFileNames NamesGeneratorType;
  NamesGeneratorType::Pointer nameGenerator = NamesGeneratorType::New();
  nameGenerator->SetInputDirectory( argv[1] );
  

  try
    {
    typedef std::vector<std::string> fileNamesContainer;
    fileNamesContainer fileNames;
    fileNames = nameGenerator->GetInputFileNames();
    ReaderType::Pointer reader = ReaderType::New();
    reader->SetFileNames( fileNames );
    reader->SetImageIO( dicomIO );

    try
      {
      reader->Update();
      }
    catch (itk::ExceptionObject &ex)
      {
      std::cout << ex << std::endl;
      return EXIT_FAILURE;
      }

    typedef itk::ImageFileWriter< ImageType > WriterType;
    WriterType::Pointer writer = WriterType::New();

    std::cout  << "Writing the image as " << std::endl << std::endl;
    std::cout  << argv[2] << std::endl << std::endl;

    writer->SetFileName( argv[2] );
    
    writer->SetInput( reader->GetOutput() );
	writer->SetImageIO( dicomIO );

    try
      {
      writer->Update();
      }
    catch (itk::ExceptionObject &ex)
      {
      std::cout << ex;
      return EXIT_FAILURE;
      }
    }
  catch (itk::ExceptionObject &ex)
    {
    std::cout << ex;
    return EXIT_FAILURE;
    }

  return EXIT_SUCCESS;

}
   
=================================================================

  Here,my question is :  Has any loss information in the series?
  Another,when I want to display the series or volume in VolView.
  It has some error.
  ex:
     ERROR: In C:\kitware\VolView\VolView20\VolView\KWCommonPro\vtkDICOMCollector.cxx,
line 765
     vtkDICOMCollector (0x0635D330): DICOM file [D:/play/tv]
     => missing required elements!

  why is it?

                                        Thanks a lot :-)   

                                                                     Wordon

在 2005/9/20,Lorensen, William E (Research) <lorensen at crd.ge.com> 撰寫:
> 
> 
> -----Original Message-----
> From: wordon [mailto:m9421001 at gmail.com]
> Sent: Monday, September 19, 2005 6:02 PM
> To: Lorensen, William E (Research)
> Cc: Andinet Enquobahrie; insight-users at itk.org
> Subject: Re: [Insight-users] read a meta image and write a volume to DICOM
> 
> 
> Hi,Bill:
> 
> I need this code so immediately.
> Can you send me this code?
> 
>                                         Thank you very much.   ; - )
> 
>             Wordon
> 
> 
> 2005/9/19, Lorensen, William E (Research) <lorensen at crd.ge.com>:
> > I have an Example that creates a valid dicom from a meta file. I still want to refine it before checking it into itk. If you have a need immediately, I can e-mail the code. It populates the meta dictionary with enough dicom to be acceptable for a GE Advantage Windows workstation. It also accepts tag/value pairs on the command line.
> >
> > Bill
> >
> > -----Original Message-----
> > From: insight-users-bounces+lorensen=crd.ge.com at itk.org
> > [mailto:insight-users-bounces+lorensen=crd.ge.com at itk.org]On Behalf Of
> > Andinet Enquobahrie
> > Sent: Monday, September 19, 2005 10:10 AM
> > To: m9421001 at gmail.com
> > Cc: insight-users at itk.org
> > Subject: Re: [Insight-users] read a meta image and write a volume to
> > DICOM
> >
> >
> > Hello Wordon,
> >
> > >1)if I want to read image using ImageFileReader<> directly,the
> > >GetMetaDataDictionaryArray can't use in writer.In this situation,how
> > >should I write the meta image to DICOM series as Luis said previously?
> > >
> > >
> > GetMetaDataDictionaryArray() function is not available for image readers
> > "not" pointing to an ImageIO class with MetaDataDictionary handling
> > capability. For example, if you had a DICOM input image and you were
> > using ImageSeriesReader pointing to GDCMImageIO, then you can access the
> > MetaData array using GetMetaDataDictionaryArray function.
> >
> > Anyways, for your situation, one thing you can do is to define an array
> > of MetaDataDicitionary containing all DICOM relevant data and pass it to
> > the ImagSeries writer using
> >
> > ImageSeriesWriter::SetMetaDataDictionaryArray(YourMetaDataArray)
> >
> >
> > >2)If I can get the DICOM series,can I use the code as
> > >DicomSeriesReadImageWrite2.cxx to read series and write it to DICOM
> > >volume?
> > >
> > >
> > >
> > Yes, you can use the example with a small modifcation to the image
> > writing part of the code. "DicomSeriesReadImgeWrite2" writes out the
> > image in a different format other than DICOM. All you need to do is to
> > use an image series file writer with a pointer to GDCMImageIO.
> >
> > typedef itk::ImageSeriesWriter< ImageType, Image2DType > WriterType;
> > WriterType::Pointer writer = WriterType::New();
> >
> > typedef itk::GDCMImageIO        ImageIOType;
> > ImageIOType::Pointer gdcmImageIO=ImageIOType::New();
> >
> > writer->SetImageIO(gdcmImageIO);
> > writer->SetInput( reader->GetOutput() );
> >
> > ...then specify filenames to the image series writer...
> >
> >
> > -Andinet
> >
> >
> >
> >
> >
> > typedef itk::Image
> >
> > >
> > >
> > >
> >
> >
> >
> >
> > -Andinet
> >
> > >
> > >2005/9/16, Luis Ibanez <luis.ibanez at kitware.com>:
> > >
> > >
> > >>Hi Wordon,
> > >>
> > >>1) Yes, it is correct to read a MetaImage with just an ImageFileReader<>
> > >>
> > >>2) No, it is not right to write a volume as a DICOM file by using only
> > >>    the ImageFileWriter.  You MUST use the ImageSeriesWriter as explained
> > >>    in detail in the ITK Software Guide
> > >>
> > >>        http://www.itk.org/ItkSoftwareGuide.pdf
> > >>
> > >>    in the Chapter "Reading and Writing Images".
> > >>
> > >>    Note that you must also connect the GDCMImageIO.
> > >>
> > >>    You will find the relevant source code examples in the directory
> > >>
> > >>                 Insight/Examples/IO
> > >>
> > >>
> > >>3) A Series is when you store an N-Dimensional image by using
> > >>    multiple files that have dimensions inferior to N.
> > >>    The typical case is to use many 2D files for saving the slices
> > >>    of a 3D volume.
> > >>
> > >>    It is also common to have many 3D files for saving a 4D image,
> > >>    like for functional MRI, or PET studies, or Cardiac CT
> > >>
> > >>    With ITK you can write an N-Dimensional image as a series of
> > >>    files with image of Dimension M, where M < N.
> > >>
> > >>
> > >>4) If you store a volume (a 3D image) in DICOM, it will be stored
> > >>    in a series of 2D images.
> > >>
> > >>
> > >>Please read the ITK Software Guide,
> > >>
> > >>
> > >>    Regards,
> > >>
> > >>
> > >>       Luis
> > >>
> > >>
> > >>----------------------------
> > >>陳政煒 wrote:
> > >>
> > >>
> > >>>Hi,Luis and all ITK user:
> > >>>
> > >>>I want to read a meta image and use the data '
> > >>>BrainProtonDensity3Slices.mha' & ' BrainProtonDensity3Slices.raw ' in
> > >>>Insight\Examples\Data.
> > >>>( I want to read a 3D raw image )
> > >>>
> > >>>And then wirte the meta image  into a volume of DICOM format.
> > >>>(.mhd or .mha --> .dcm)
> > >>>
> > >>>
> > >>>My code as follows :
> > >>>
> > >>>#include "itkImageFileReader.h"
> > >>>#include "itkImageFileWriter.h"
> > >>>#include "itkImage.h"
> > >>>#include "itkRescaleIntensityImageFilter.h"
> > >>>#include "itkMetaDataDictionary.h"
> > >>>#include "itkMetaDataObject.h"
> > >>>#include "itkGDCMImageIO.h"
> > >>>
> > >>>#include <list>
> > >>>#include <fstream>
> > >>>
> > >>>int main(int ac, char* av[])
> > >>>{
> > >>>
> > >>>  if(ac < 3)
> > >>>    {
> > >>>    std::cerr << "Usage: " << av[0] << " InputMETAFile OutputDICOM\n";
> > >>>    return EXIT_FAILURE;
> > >>>    }
> > >>>
> > >>>  typedef itk::Image<unsigned char, 3> ImageType;
> > >>>
> > >>>  typedef itk::ImageFileReader< ImageType > VolumeReaderType;
> > >>>
> > >>>  VolumeReaderType::Pointer reader = VolumeReaderType::New();
> > >>>
> > >>>  reader->SetFileName( av[1] );
> > >>>
> > >>>  try
> > >>>    {
> > >>>    reader->Update();
> > >>>    }
> > >>>  catch (itk::ExceptionObject & e)
> > >>>    {
> > >>>    std::cerr << "exception in file reader " << std::endl;
> > >>>    std::cerr << e.GetDescription() << std::endl;
> > >>>    std::cerr << e.GetLocation() << std::endl;
> > >>>    return EXIT_FAILURE;
> > >>>    }
> > >>>
> > >>>
> > >>>  typedef itk::GDCMImageIO        ImageIOType;
> > >>>
> > >>>  ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
> > >>>
> > >>>
> > >>>  typedef itk::Image<unsigned char, 3> WriteType;
> > >>>  typedef itk::ImageFileWriter<WriteType>     Writer1Type;
> > >>>  Writer1Type::Pointer writer1=Writer1Type::New();
> > >>>
> > >>>  writer1->SetFileName( av[2] );
> > >>>  writer1->SetImageIO( gdcmImageIO );
> > >>>  writer1->SetInput( reader->GetOutput() );
> > >>>
> > >>>
> > >>>  try
> > >>>    {
> > >>>    writer1->Update();
> > >>>    }
> > >>>  catch (itk::ExceptionObject & e)
> > >>>    {
> > >>>    std::cerr << "exception in file writer " << std::endl;
> > >>>    std::cerr << e.GetDescription() << std::endl;
> > >>>    std::cerr << e.GetLocation() << std::endl;
> > >>>    return EXIT_FAILURE;
> > >>>    }
> > >>>
> > >>>
> > >>>
> > >>>  return EXIT_SUCCESS;
> > >>>
> > >>>}
> > >>>
> > >>>My code can run,but the DICOM image in output is not correctly.
> > >>>It has a problem like loss some information in output file.
> > >>>
> > >>>My questions:
> > >>>1)Is it right to read the 3D meta image use ImageFileReader directly?
> > >>>2)Is it right to write the data into a volume of DICOM use
> > >>>ImageFileWriter directly?
> > >>>3)What are difference between series and volume?
> > >>>4)If I want to get a 3D DICOM file in one file.Is it a volume?
> > >>>
> > >>>Thanks a lot. : -)
> > >>>                                                              Wordon
> > >>>_______________________________________________
> > >>>Insight-users mailing list
> > >>>Insight-users at itk.org
> > >>>http://www.itk.org/mailman/listinfo/insight-users
> > >>>
> > >>>
> > >>>
> > >>>
> > >>
> > >>
> > >>
> > >>------------------------------------------------------------------------
> > >>
> > >>_______________________________________________
> > >>Insight-users mailing list
> > >>Insight-users at itk.org
> > >>http://www.itk.org/mailman/listinfo/insight-users
> > >>
> > >>
> >
> >
> > _______________________________________________
> > 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