[Insight-users] write out all dicom header info
Mathieu Malaterre
mathieu.malaterre at kitware.com
Mon Dec 18 17:05:41 EST 2006
Hi Clemens,
Writing DICOM can become quickly complex. I believe for your question
you need to re-read the ITK Software Guide, I have tried to describe
most cases
Q: Why some data elements are not loaded ?
A: By default we do not load some binary elements that are considered
too long. See for example: DicomImageReadPrintTags.cxx. To override this
default behavior:
<quote>
// Software Guide : BeginLatex
//
// Here we override the gdcm default value of 0xfff with a value of 0xffff
// to allow the loading of long binary stream in the DICOM file.
// This is particularly useful when reading the private tag: 0029,1010
// from Siemens as it allows to completely specify the imaging parameters
//
// Software Guide : EndLatex
dicomIO->SetMaxSizeLoadEntry(0xffff);
<quote>
Q: How can I write a DICOM image using a DICOM header read from a
previous operation ?
A: You should have a look at DicomImageReadChangeHeaderWrite. In this
example we read in a DICOM file, and change some info found in the
header so that we rewrite the image with the header info changed.
Writer1Type::Pointer writer1 = Writer1Type::New();
writer1->SetInput( reader->GetOutput() );
writer1->SetFileName( argv[2] );
writer1->SetImageIO( gdcmImageIO ); // reuse the same GDCM IO
HTH
Mathieu
Eric Claus wrote:
> Hi Mathieu,
> I still have not been able to all the private tags written out. I tried
> making a custom dictionary of the private tags, although this still
> misses a few tags (haven't been able to figure out why). There was also
> an earlier post to the list in which the header tags were printed out to
> a text file
> (http://public.kitware.com/pipermail/insight-users/2006-October/019862.html),
> and I was thinking that I could apply a similar method for writing out
> the header, but I couldn't figure it out.
>
> I am curious about your comment though. What would reusing the same
> ImageIO look like? I thought I was doing this already, although I have
> to admit that I am pretty novice at programming in c, so I could be wrong.
>
> Thanks,
> Eric
>
> Mathieu Malaterre wrote:
>> Hi Eric,
>>
>> Did you ever solve your issue ? I believe this is just a matter of
>> reusing the same ImageIO used for reading for writing.
>>
>> HTH
>> -M
>>
>> Eric Claus wrote:
>>> Hi,
>>> I am trying to use ITK to read in 2 different DICOM images, combine
>>> the images by taking the sqrt(image1^2 + image2^2) and then writing
>>> out the image with the header from image1. I have been successful in
>>> reading and writing the images, but have been unable to figure out
>>> how to write the entire header. Is there any easy way to just copy
>>> all the header info from one image to another? The current program
>>> appears to only write out the information that is part of the
>>> MetaDictionary??? I pasted my code below if that is of any use to
>>> anyone.
>>>
>>> Thanks in advance,
>>> Eric
>>>
>>>
>>> #include "itkImageFileReader.h"
>>> #include "itkImageFileWriter.h"
>>> #include "itkRescaleIntensityImageFilter.h"
>>> #include "itkGDCMImageIO.h"
>>> #include "itkImageRegionConstIterator.h"
>>> #include "itkImageRegionIterator.h"
>>>
>>> #include <list>
>>> #include <fstream>
>>>
>>> int main( int argc, char* argv[] )
>>> {
>>>
>>> // Verify the number of parameters in the command line
>>> // Should have nonzshim, zshim, outputname
>>> if( argc < 3 )
>>> {
>>> std::cerr << "Usage: " << std::endl;
>>> std::cerr << argv[0] << " nonzshimImage zshimImage outputImage\n";
>>> return EXIT_FAILURE;
>>> }
>>>
>>> typedef signed short InputPixelType;
>>> const unsigned int InputDimension = 2;
>>>
>>> typedef itk::Image< InputPixelType, InputDimension > InputImageType;
>>>
>>>
>>> typedef itk::ImageFileReader< InputImageType > ReaderType;
>>>
>>> ReaderType::Pointer reader = ReaderType::New();
>>> reader->SetFileName( argv[1] );
>>>
>>> ReaderType::Pointer reader2 = ReaderType::New();
>>> reader2->SetFileName( argv[2] );
>>>
>>> try
>>> {
>>> reader->Update();
>>> reader2->Update();
>>> }
>>> catch (itk::ExceptionObject & e)
>>> {
>>> std::cerr << "exception in file reader " << std::endl;
>>> std::cerr << e << std::endl;
>>> return EXIT_FAILURE;
>>> }
>>>
>>>
>>> typedef itk::Image<InputPixelType, InputDimension> InputImageType;
>>> typedef itk::ImageRegionConstIterator< InputImageType >
>>> ConstIteratorType;
>>> typedef itk::ImageRegionIterator< InputImageType > IteratorType;
>>>
>>>
>>> InputImageType::Pointer image = reader->GetOutput();
>>> ConstIteratorType constIterator1( image, image->GetRequestedRegion() );
>>> IteratorType iterator1( image, image->GetRequestedRegion() );
>>> InputImageType::Pointer image2 = reader2->GetOutput();
>>> ConstIteratorType constIterator2( image2,
>>> image2->GetRequestedRegion() );
>>> IteratorType iterator2( image2, image2->GetRequestedRegion() );
>>>
>>>
>>> ConstIteratorType in1( image, image->GetRequestedRegion() );
>>> ConstIteratorType in2( image2, image2->GetRequestedRegion() );
>>>
>>> IteratorType out( image2, image->GetRequestedRegion() );
>>>
>>> for ( in1.GoToBegin(), out.GoToBegin(), in2.GoToBegin();
>>> !in1.IsAtEnd(); ++in1, ++out, ++in2 )
>>> {
>>> out.Set( 0.5 + (1.33 * sqrt( (in1.Get()) * (in1.Get()) + (in2.Get())
>>> * (in2.Get()) )));
>>> }
>>>
>>> typedef itk::ImageFileWriter< InputImageType > Writer1Type;
>>>
>>> Writer1Type::Pointer writer1 = Writer1Type::New();
>>>
>>> writer1->SetFileName( argv[3] );
>>> writer1->SetInput( image2 );
>>>
>>> try
>>> {
>>> writer1->Update();
>>> }
>>> catch (itk::ExceptionObject & e)
>>> {
>>> std::cerr << "exception in file writer " << std::endl;
>>> std::cerr << e << std::endl;
>>> return EXIT_FAILURE;
>>> }
>>>
>>> return EXIT_SUCCESS;
>>>
>>> }
>>>
>>>
>
More information about the Insight-users
mailing list