How to read dicom tags from dicom file?

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
e.can
Posts: 29
Joined: Tue, 2015-11-03, 14:40

How to read dicom tags from dicom file?

#1 Post by e.can »

Hi,

I want to list all dicom tags of a dicom file in a TreeView(Qt) and I found Joergs Riesmeier's example code:

Code: Select all

DcmStack stack;
  DcmObject *dobject = NULL;
  DcmElement *delem = NULL;
  OFCondition status = dataset.nextObject(stack, OFTrue);
  while (status.good())
  {
    dobject = stack.top();
    /* do something useful with the current object, e.g. check
       identifier: dobject->ident() */
    ...
    delem = (DcmElement *)dobject;
    /* do something useful with the current element, e.g. get
       string value: delem->getOFString(string) */
    ...
    status = dataset.nextObject(stack, OFTrue);
  }
How do I apply this code on a specific file? Something like loadFile()???
I want to show the tags in a hierarchical structure...

Regards,

Engin

Michael Onken
DCMTK Developer
Posts: 2051
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: How to read dicom tags from dicom file?

#2 Post by Michael Onken »


e.can
Posts: 29
Joined: Tue, 2015-11-03, 14:40

Re: How to read dicom tags from dicom file?

#3 Post by e.can »

The example you provided doesn't show how to get all tags from a dicom file. It just shows how to get specific tags :S
I really need to show all tags in a dicom file, in a TreeView...

Michael Onken
DCMTK Developer
Posts: 2051
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: How to read dicom tags from dicom file?

#4 Post by Michael Onken »

Get the dataset using the example code from the dcmdata module documentation I posted, and on the dataset use the code that you quoted. 1+1... :)

Best,
Michael

e.can
Posts: 29
Joined: Tue, 2015-11-03, 14:40

Re: How to read dicom tags from dicom file?

#5 Post by e.can »

How do I iterate trough all sequences and their child tags? I tried to use nextObject() in combination with getTag(), but it doesn't contain a hierarchy. I am not sure how to devide parents from children tags.

What I want to display is

Code: Select all

+Parent1
  +Child
  +Child
  .....
+Parent2
  +Child
  +Child
  etc.....
What would be the best way to implement this?

Michael Onken
DCMTK Developer
Posts: 2051
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: How to read dicom tags from dicom file?

#6 Post by Michael Onken »

Hi,

you should be able to use ident() on each element you're iterating over. This returns you the type of object (in form of a DcmEVR enum, all possible values are in dcvr.h). Alternatively, if you just need to know whether the element has a subtree (what you denoted as "parent") or is just a leaf ("child"), you could use isLeaf() instead.

Best,
Michael

e.can
Posts: 29
Joined: Tue, 2015-11-03, 14:40

Re: How to read dicom tags from dicom file?

#7 Post by e.can »

Is there a function to get all leaves of a subtree?

Michael Onken
DCMTK Developer
Posts: 2051
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: How to read dicom tags from dicom file?

#8 Post by Michael Onken »

In terms of getting a flat list a la getChilds() or so? No, you have to iterate. Note that the second parameter of nextObect() determines whether a sequence is entered (ie. the child of the sequence will be the next object) or not (then the element after the sequence is next, with all children being skipped).

Michael

e.can
Posts: 29
Joined: Tue, 2015-11-03, 14:40

Re: How to read dicom tags from dicom file?

#9 Post by e.can »

Hi Michael,

Thank you for your help so far, but unfortunately I have a big problem. I am using DCMTK as part of my schoolproject, but I have no progress for almost a week, because I cannot figure out how to show all tags in an hierarchical tree view. Could you please help me creating some example code in order to iterate over all tags. You would save my life, since the deadline of my project is at the end of this month :(. To be clear, I dont need your help creating Qt "viewing" code.

I would (really)^2 appriciate it....

e.can
Posts: 29
Joined: Tue, 2015-11-03, 14:40

Re: How to read dicom tags from dicom file?

#10 Post by e.can »

I 'managed' to get the following output (this is not the full output):

LEAF: "(0008,0005)"
LEAF: "(0008,0016)"
LEAF: "(0008,0018)"
LEAF: "(0008,0020)"
LEAF: "(0008,0021)"
LEAF: "(0008,0023)"
LEAF: "(0008,0030)"
LEAF: "(0008,0031)"
LEAF: "(0008,0033)"
LEAF: "(0008,0050)"
LEAF: "(0008,0060)"
LEAF: "(0008,0070)"
LEAF: "(0008,0080)"
LEAF: "(0008,0090)"
LEAF: "(0008,1030)"
TREE: "(0008,1032)" <-- Procedure Code Sequence
TREE: "(fffe,e000)" <-- Item
LEAF: "(0008,0100)" <-- Code value
LEAF: "(0008,0102)" <-- Coding Scheme Designator
LEAF: "(0008,0104)" <-- Code Meaning

LEAF: "(0008,103e)"
LEAF: "(0008,1050)"
LEAF: "(0008,1090)"
TREE: "(0008,1111)"
LEAF: "(0010,0010)"
LEAF: "(0010,0020)"
LEAF: "(0010,0030)"

With the following code:

Code: Select all

DcmStack stack;
	DcmObject* pDobject = NULL;
	DcmElement* pDelem = NULL;
	DcmDataset pDataset = m_fileController->loadDataSetFromDICOMFile(qsFilePath);
	OFCondition status = pDataset.nextObject(stack, OFTrue);
	while (status.good())
	{
		pDobject = stack.top();
		pDelem = (DcmElement*)pDobject;
		bool isLeaf = pDelem->isLeaf();
		QString tag = pDelem->getTag().toString().c_str();
		if (isLeaf)
		{
			qDebug() << "LEAF: " << tag;
		} 
		else 
		{
			qDebug() << "TREE: " << tag;
		}		
		status = pDataset.nextObject(stack, OFTrue);
	}
How do I know when a item/sequence ends? How can I get "Item Delimitation Item (fffe),(e00d)" and "Sequence Delimitation Item (fffe),(e00d)" ?
I really need it in order to show it in a treeview.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 1 guest