[Insight-users] How to read a dicom series and write it as a new series??

Sachin Jambawalikar sachinjam at gmail.com
Mon Jun 9 15:00:04 EDT 2008


Hi Mathieu,

Thanks for your reply.
I looked into the dicom tags to see why the dicom viewers  didnot read
some of the dicom files (for example only 153 of 160 generated files)
generated
keeping the gdcmIO->KeepOriginalUIDOn(). This is because some files
get the same SOPInstance UID.
I use  the following code to generate new instance UID's

 ReaderType::DictionaryArrayType outputArray;


  ReaderType::DictionaryRawPointer dict = new ReaderType::DictionaryType;

for (int i=0;i<numfiles;i++)
{
std::string sopInstanceUID =
gdcm::Util::CreateUniqueUID(gdcmIO->GetUIDPrefix());
  itk::EncapsulateMetaData<std::string>(*dict,"0008|0018", sopInstanceUID);
   itk::EncapsulateMetaData<std::string>(*dict,"0002|0003", sopInstanceUID);

....

outputArray.pushback();
}


The problem is  the for loop is faster than the time resolution gdcm
uses to generate new uid and as a result some of the SOPinstance uids
are repeated.
When I used the C++ clock() function in the loop to wait for 30
milliseconds correct (unique) UID's were generated and everything
worked fine.

Thanks again for solving both my issues with the DICOM header.

Regards
--sachin

On Mon, Jun 9, 2008 at 10:39 AM, Mathieu Malaterre
<mathieu.malaterre at gmail.com> wrote:
> Hi Sachin,
>
> On Sun, Jun 8, 2008 at 9:19 AM, Sachin Jambawalikar <sachinjam at gmail.com> wrote:
>> Hi all,
>>
>> I wanted to know how to read a dicom series and write it as a new
>> series with a different series number and  series UID.
>> I  tried using Bill lorensen's code posted in the mailing list
>> http://www.itk.org/pipermail/insight-users/2008-May/025965.html
>>  It generates dicom files adds a new sereis however when I view
>> through Pacs or a dicom viewer they skip some of the slices(for
>> example if there are 160 dicom files in the series  only 153 are
>> loaded)
>
> I do not understand what is going on here. You should print the output
> of whatever filter you are using and make sure the size is correct:
>
>  filter->Update()
>  filter->GetOutput()->Print( std::cout );
>
> If the dimension along which you are running your SeriesWriter is 153,
> then you found your problem :)
>
>> If I comment  the line  gdcmIO->KeepOriginalUIDOn() in the code  then
>> dicom viewer loads the generated file correctly (nothing skipped) but
>> pacs thinks of it as a new study and doesnot include this new series
>> with the original study.
>>
>> I've used the exact code of Bill Lorensen from the link but with
>> resample parameters  0.0 0.0 0.0
>
> Ok, so you are trying to create another Series, while trying to
> preserve it's Study information, correct ?
> this is not a scenario I have thought of before, so it will require
> some hand coding.
>
> You will need to keep:
>
>  gdcmIO->KeepOriginalUIDOn()
>
>  And then get the reader meta data dict array:
>
>   dicts = reader->GetMetaDataDictionaryArray()
>
>  for each array there will a value for key "0020|000e" (Series
> Instance UID) that should be identical in all the individual dict. You
> need to set it to something else (it needs to be identical for each
> dict).:
>
> Create ONE new uid to declare a new Study:
>    std::string myseriesuid = gdcm::Util::CreateUniqueUID( myUIDPrefix );
>
> then iterate over all dicts and change manually the Series Instance UID:
>
>  for each dict in dicts:
>    itk::MetaDataDictionary & dict = dicts[i]
>    itk::EncapsulateMetaData<std::string>( dict, "0020|000e", myseriesuid );
>
> HTH
> --
> Mathieu
>


More information about the Insight-users mailing list