[Insight-users] Also problem with MetaDataDictionaryArray

Luis Ibanez luis.ibanez at kitware.com
Thu May 11 08:50:50 EDT 2006


Hi Markus,

You are creating the dictionaries statically inside the scope of
the "if".

 >         if(i>=dictArray->size()){
 >             const DictionaryType* dict = dictArray->at(i-1);
 >             DictionaryType nDict = DictionaryType(*dict);       //copy
 > constructor
 >
 >              //now, how to append the new value???
 >
 > dictArray->push_back(reinterpret_cast<DictionaryType&>(nDict));
 > //doesn't work
 >         }
 >         .....


These variables will be naturally destroyed a the end of the "if" scope.

You should instead create these dictionaries dynamically, and then
delete them once you are done with saving the image.

An example on how to change entries in the metadata dictionary
is presented in the ITK Software Guide

     http://www.itk.org/ItkSoftwareGuide.pdf

in the chapter  "Reading and Writing Images", in section 7.12.7,
"Changing a DICOM Header", in pdf-page 343.



The corresponding source code example is at


           Insight/
              Examples/
                     IO/
                        DicomImageReadChangeHeaderWrite.cxx




    Regards,


       Luis



======================
Markus Weigert wrote:
> Hi once again,
> 
> now that I solved the CT dicom value ranges problem (thanks to
> Mathieu and Wilfred), I already have a new problem.
> 
> After I have resampled an Image (more slices) which comes from a serie of
> dicom files, I want to write it back to a dicom serie.
> 
> Therefore, I need to append some new MetaDataDictionary entries to the 
> MetaDataDictionaryArray
> (via std::Vector::push_back()).
> 
> Unfortunately, I have some problems to do this.
> Also I think, it is perhaps a simple task, but there is a typecasting 
> problem which I couldn't solve
> up to this point.
> 
> My code is as follows (just a few lines):
> 
> typedef itk::MetaDataDictionary                 DictionaryType;
> const std::vector<DictionaryType*>*         dictArray
> 
> for(int i=0;i<nameGenerator->GetFileNames().size();i++){
> 
>         //Check if there are enough MetaDataDictionaries in the 
> MetaDataDictionaryArray.
>         //This may not be the case, if the image from the original Dicom 
> serie has been resampled e.g.
> 
>         if(i>=dictArray->size()){
>             const DictionaryType* dict = dictArray->at(i-1);
>             DictionaryType nDict = DictionaryType(*dict);       //copy 
> constructor
> 
>              //now, how to append the new value???
>             
> dictArray->push_back(reinterpret_cast<DictionaryType&>(nDict));     
> //doesn't work
>         }
>         .....
> 
> I hope, somebody may help me here too, I think it should be not to 
> difficult.
> 
> 
> Regards,
> Markus
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users




More information about the Insight-users mailing list