[Insight-users] Basic Read/Write of DICOM Image - Wrong Metadata
Mathieu Malaterre
mathieu.malaterre at gmail.com
Tue Sep 9 12:57:04 EDT 2008
Hi Michael,
I am looking at the example and I can see that you are setting the
UseMetaDataDictionary to Off. Which means that the outupt will be a
Secondary Capture Image Storage, correct ? If so I do not understand
what you mean by 'voxel size' on an SC object ?
thanks
On Tue, Sep 9, 2008 at 6:42 PM, M. Wirtzfeld <wirtzfeld at rogers.com> wrote:
>
>
> Hello,
>
> I am working with DICOM images and presently need to read and write these
> image types (only in 2-dimensions) directly using ITK. I am following the
> code verbatim shown in Section 7.12.2, "Reading and Writing a 2D Image", of
> "The ITK Software Guide, Second Edition (Update for ITK Version 2.4)".
>
> The DICOM meta-data for both saved images (direct and rescaled) is not
> correct with respect to the voxel-size (verified using MicroView and MIPAV).
> I have not tried to validate all meta-data fields in the newly saved images
> given this initial inconsistency.
>
> The source-code directly from the text of the respective section is shown
> below. It is compiled against version 3.4 of the ITK project.
>
> I do not understand why this basic example is not working. For the first
> image saved, the text says, "We need to explicitly set the proper image IO
> (GDCMImageIO) to the writer filter since the input DICOM dictionary is being
> passed along the writing process. The dictionary contains all necessary
> information that a valid DICOM file should contain, like Patient Name,
> Patient ID, Institution Name, etc.". But the results are not correct.
>
> Suggestions?
>
>
> Thank you,
>
> Michael.
>
>
> ---------------------------------------------
>
> #include "itkImage.h"
>
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkRescaleIntensityImageFilter.h"
> #include "itkGDCMImageIO.h"
>
>
>
> int main( int argc, char * argv[] ) {
>
> if( argc < 3 ) {
>
> std::cerr << "Usage: " << std::endl;
> std::cerr << argv[0] << " < argument_1 > <argument_2>
> <argument_3> <argument_4> " << std::endl;
>
> /* argument_1 -> Input-image filename.
> * argument_2 -> Direct-save of given input-image filename.
> * argument_3 -> Intermediate - n/a.
> * argument_4 -> Rescaled with passed along Meta-data
> filename.
> */
>
>
> return EXIT_FAILURE;
> }
>
>
> typedef short InputPixelType;
> typedef float OutputPixelType;
>
> typedef itk::Image< InputPixelType, 2 > InputImageType;
> typedef itk::Image< OutputPixelType, 2 > OutputImageType;
>
> typedef itk::ImageFileReader< InputImageType > ReaderType;
>
> typedef itk::GDCMImageIO ImageIOType;
> ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
>
>
> ReaderType::Pointer reader = ReaderType::New();
> reader->SetFileName( argv[1] );
> reader->SetImageIO( gdcmImageIO );
>
>
> try {
> reader->Update();
> }
> catch ( itk::ExceptionObject & anException ) {
>
> std::cerr << "\n\n** Exception in File Reader: " <<
> anException << " **\n\n" << std::endl;
> return EXIT_FAILURE;
>
> };
>
>
> typedef itk::ImageFileWriter < InputImageType > Writer1Type;
>
> Writer1Type::Pointer writer1 = Writer1Type::New();
>
> writer1->SetFileName( argv[2] );
> writer1->SetInput( reader->GetOutput() );
> writer1->SetImageIO( gdcmImageIO );
>
> try {
> writer1->Update();
> }
> catch ( itk::ExceptionObject & anException ) {
>
> std::cerr << "\n\n** Exception in File Writer1: " <<
> anException << " **\n\n" << std::endl;
> return EXIT_FAILURE;
>
> };
>
>
>
> typedef unsigned char WritePixelType;
> typedef itk::Image < WritePixelType, 2 > WriteImageType;
> typedef itk::RescaleIntensityImageFilter < InputImageType,
> WriteImageType > RescaleFilterType;
>
> RescaleFilterType::Pointer rescaler = RescaleFilterType::New();
>
> rescaler->SetOutputMinimum( 0 );
> rescaler->SetOutputMaximum( 255 );
>
> typedef itk::ImageFileWriter < WriteImageType > Writer2Type;
>
> Writer2Type::Pointer writer2 = Writer2Type::New();
>
> writer2->SetFileName( argv[3] );
>
> rescaler->SetInput( reader->GetOutput() );
> writer2->SetInput( rescaler->GetOutput() );
>
>
> typedef itk::ImageFileWriter < WriteImageType > Writer3Type;
>
> Writer3Type::Pointer writer3 = Writer3Type::New();
>
> writer3->SetFileName( argv[4] );
> writer3->SetInput( rescaler->GetOutput() );
>
> writer3->UseInputMetaDataDictionaryOff();
> writer3->SetImageIO( gdcmImageIO );
>
>
> try {
> writer3->Update();
> }
> catch ( itk::ExceptionObject & anException ) {
>
> std::cerr << "\n\n** Exception in File Writer3: " <<
> anException << " **\n\n" << std::endl;
> return EXIT_FAILURE;
>
> };
>
>
> return EXIT_SUCCESS;
> }
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
--
Mathieu
More information about the Insight-users
mailing list