[Insight-users] Writing new DICOM files.

Robert Haase robert_haase at gmx.de
Wed Nov 12 09:02:38 EST 2008


Hi Todd,

I had the same problem like you using ITK 3.8. The source documentation in utilities/gdcm/src/gdcmFileHelper.cxx (at line 356) tells us:

--------------------------------------------------------
4) When user *knows* he didn't modified the pixels, he may ask the writer to keep some
informations unchanged :
'Media Storage SOP Class UID' (0x0002,0x0002)
'SOP Class UID'               (0x0008,0x0016)
'Image Type'                  (0x0008,0x0008)
'Conversion Type'             (0x0008,0x0064)
He has to use gdcm::FileHelper::SetKeepMediaStorageSOPClassUID(true)
(probabely name has to be changed)
-------------------------------------------------------

But this simply didn't work, because there is no function like SetKeepMediaStorageSOPClassUID.
Worse than no comment in source code is a wrong one. 

I couldn't fix this problem in the itk/gdcm code because I'm a new ITK-user and not so familiar with coding rules. 

But I found a solution to get my program working (a dirty dirty workaround):

I wrote my own MyFileHelper class, inheriting from gdcm::FileHelper. 

class GDCM_EXPORT MyFileHelper : public gdcm::FileHelper
{...}

It has an overwritten function  Write(std::string const &fileName), which does NOT call CheckMandatoryElements(). So in this function I'm doing my own mandatory-checks and there I'm absolutly free in defining which tags should be changed and which not.

To get this work, I also had to implement an own DicomIO, which uses MyFileHelper, not the gdcm one

class ITK_EXPORT myDicomImageIO : public itk::GDCMImageIO
{...}

Maybe this helps you. If you wish, I could send you my 'dirty' implementation of this.

Regards,
Robert Haase








-------- Original-Nachricht --------
> Datum: Wed, 12 Nov 2008 05:01:44 -0800 (PST)
> Von: Todd Jensen <todd.jensen at ieee.org>
> An: Mathieu Malaterre <mathieu.malaterre at gmail.com>
> CC: insight-users at itk.org
> Betreff: Re: [Insight-users] Writing new DICOM files.

> Hello, Mathieu,
> 
> > > Media Storage SOP Instance UID (0002,0003) is set to a newly generated
> UID
> > > Image Type is set to DERIVED\PRIMARY
> > 
> > I think what you are looking for is: itk::GDCMImageIO::KeepOriginalUID(
> true )
> 
> I am using this.
> 
> > > And since the 0002,0003 element is set to a new unique UID, it never
> matches 
> > the SOP Instance UID which is an error.
> > 
> > what ? 0002,0003 should match the value from the dataset. If you found
> > an issue, please report, a simple way to reproduce it. Thank you.
> 
> Here is how to reproduce, using ITK 3.6:
> 
> 1) Set the SOP Instance UID in meta data:
> 
> itk::MetaDataDictionary outMetaData;
> 
> // Assign values to required DICOM elements for SC SOP class UID in meta
> data...
> //
> [...removed for brevity...] (I have verified the requirement elements are
> all set using the standard documentation and David Clunie's verification
> tools)
> 
> // Assign SOP Instance UID with a defined prefix...
> //
> vcl_string instanceUID = gdcm::Util::CreateUniqueUID( uidPrefix );
> itk::EncapsulateMetaData< vcl_string >( outMetaData, "0008|0018",
> instanceUID );
> itk::EncapsulateMetaData< vcl_string >( outMetaData, "0002|0003",
> instanceUID );
> 
> 2) Attach meta data to GDCM:
> 
> itk::GDCMImageIO::Pointer dicomIO = itk::GDCMImageIO::New();
> typedef itk::ImageFileWriter< ImageType2D > WriterType;
> WriterType::Pointer dcmWriter = WriterType::New();
> 
> outputImage->SetMetaDataDictionary( outMetaData );
> dicomIO->SetKeepOriginalUID( true );
> dcmWriter->SetFileName( outputFile.str() );
> dcmWriter->SetInput( outputImage );
> dcmWriter->SetImageIO( dicomIO );
> dcmWriter->Update();
> 
> gdcm::FileHelper::CheckMandatoryElements() will regenerate the media
> storage SOP instance UID even though KeepOriginalUID is set to true.
> 
> I hope this helps explain the issue. Also, it would be nice if I could
> keep the image type I set (it is forced to DERIVED\\PRIMARY) 
> 
> Regards,
> 
> Todd Jensen
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users

-- 
"Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail


More information about the Insight-users mailing list