[Insight-users] Retrieving DICOM header information

Stéphane CALANDE scalande at gmail.com
Wed Nov 5 08:07:02 EST 2008


Hi John,


I had the same problem a few days ago.
I used gdcm to do what I want.

The following program print all the DICOM header information you want. You
just have to specify the [Group,Element] of the tags.


#include <string.h>
#include "gdcmStringFilter.h"
#include "gdcmReader.h"
#include "gdcmSequenceOfItems.h"
#include "gdcmTesting.h"
#include "gdcmTag.h"

int main(int argc, char *argv[])
{
  if( argc == 2 )
    {
    const char *filename = argv[1];

    gdcm::StringFilter sf;
  gdcm::Reader r;
  r.SetFileName( filename );
  if( !r.Read() )
    {
    return 1;
    }
  gdcm::DataSet const& ds = r.GetFile().GetDataSet();
  sf.SetFile( r.GetFile() );

  int ret = 0;
  gdcm::DataSet::ConstIterator it = ds.Begin();
  for( ; it != ds.End(); ++it)
    {
    const gdcm::DataElement &ref = *it;
    std::pair<std::string, std::string> s = sf.ToStringPair( ref.GetTag() );

    gdcm::Tag tag = ref.GetTag();

    // HERE you select de tags you want....

    gdcm::Tag seriesDesc(0x0008,0x103e); //  =tag of "Series description" =>
[0008,103E]
    gdcm::Tag seriesInstUID(0x0020,0x000e); //  =tag of "Series Instance
UID" => [0020,000E]
    gdcm::Tag nbSlices(0x0054,0x0081); //  =tag of "Number of Slices" =>
[0054,0081]


    if(tag == seriesDesc || tag == seriesInstUID || tag == nbSlices){

    if( !s.second.empty() == 0)
      {
      std::cout << /*s.first << " -> "*/ tag << " " << s.second <<
std::endl;
      }}
    }
  return ret;

    }
    return 0;
}



But to use this program it is necessary to install gdcm (in the same way as
ITK)



Regards,


Stéphane




2008/11/5 John Smith <af3113 at yahoo.com>

> Hi,
>
> Is there a way to retrieve DICOM header information like: Time point (in
> case of 4D), Patient position, Study description, Protocol, etc. I use for
> the moment "itkGDCMImageIO", but it looks like I cannot do this job or may
> be I don't know how to do it. Is there a way to retrieve all of this
> information via that mentioned class, or do you recommend another class? or
> there no such a class which does that job at all?
>
> Thanks,
>
> J.
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20081105/091f877f/attachment.htm>


More information about the Insight-users mailing list