[Insight-users] writing out DICOM files instead of png

markw markw at 3tp . net
Tue, 9 Dec 2003 14:13:45 -0500


Hi Luis,

Thanks for your help with the compilation of ITK, everything works fine
now. The example programs are great. I had one remaining question about
writing out DICOM files after image processing. The image processing
examples seem to read DICOM files without problems, but they cannot
write over the original DICOM file or write a new one. I tried using the
itkDICOMImageIO2.h because it seems it will enable you to write DICOM
files out, but I think my implementation is incorrect. I created a small
image filter program to test it out which is below, the part of
importance I suppose is here:

typedef itk::DICOMImageIO2 DicomHelp;
DicomHelp::Pointer         dicomhelp    = DicomHelp::New();
dicomhelp->SetFileName( argv[3] );
dicomhelp->Write( caster->GetOutput() );

but this seems to do nothing when I execute the program. Can you offer
any clues? The full test program is below, thanks for your help,

Mark


#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"

#include "itkMedianImageFilter.h"
#include "itkCastImageFilter.h"

// to try and work with dicoms
#include "itkDICOMImageIO2.h"


int main( int argc, char *argv[] )
{
  if (argc < 3) {
	std::cout << "You need to enter the input and output image
names." << std::endl;
    return 1;
  }

  typedef itk::Image< unsigned char, 2 >
InputImageType;
  typedef itk::Image< unsigned char, 2 >
OutputImageType;
  typedef itk::CastImageFilter< InputImageType, OutputImageType >
CastFilterType;
  typedef itk::ImageFileWriter< OutputImageType >
WriterType;
  typedef itk::ImageFileReader< InputImageType >
ReaderType;

  typedef itk::MedianImageFilter<InputImageType, OutputImageType >
MedianFilterType;
  typedef itk::DICOMImageIO2 DicomHelp;

  DicomHelp::Pointer        dicomhelp    = DicomHelp::New();
  ReaderType::Pointer       reader       = ReaderType::New();
  WriterType::Pointer       writer       = WriterType::New();
  CastFilterType::Pointer   caster       = CastFilterType::New();
  MedianFilterType::Pointer medianfilter = MedianFilterType::New();

  
  bool b = dicomhelp->CanWriteFile( "test.dcm" );

  // always returns true for read, false for write..
  if (b == true)
    std::cout << "true" << std::endl;
  else
    std::cout << "false" << std::endl;

  reader->SetFileName( argv[1] );
  medianfilter->SetInput( reader->GetOutput() );
  reader->Update();
  
  writer->SetFileName( argv[2] );
  caster->SetInput( medianfilter->GetOutput() );
  writer->SetInput( caster->GetOutput() );

  writer->Update();
  
  // Can we also write the output to a DICOM file now?
  // Seems to never want to do this..
  dicomhelp->SetFileName( argv[3] );
  dicomhelp->Write( caster->GetOutput() );

  std::cout << std::endl << "Finished successfully." << std::endl;
  return 0;
}