[Insight-users] writing out DICOM files instead of png
Luis Ibanez
luis . ibanez at kitware . com
Tue, 09 Dec 2003 14:39:17 -0500
Hi Mark,
None of the DICOM ImageIO classes in ITK are designed
for writing dicom files. Both of them are intended for
reading only .
You can easily check this out by looking at their
"CanWriteFile()" methods, which are returning "false"
in both cases.
Although in principle it is not impossible to write a
DICOM file, the question is whether this is a desirable
thing to have or not. These files are supposed to be the
ones generated from the DICOM stream taken from the
image acquisition systems.
Is there any reason why you couldn't use any of the other
formats supported in ITK ?
for example:. MetaImage, Analyze, GIPL, IPL, VTK... ?
Analyze and MetaImage are probably the most flexible
formats for medical images.
Regards,
Luis
------------------------------------------------------------
markw wrote:
>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;
>}
>
>
>_______________________________________________
>Insight-users mailing list
>Insight-users at itk . org
>http://www . itk . org/mailman/listinfo/insight-users
>
>
>