Accessing "child" or "nested" DICOM tags

3,367 views
Skip to first unread message

JR

unread,
Oct 28, 2013, 1:39:45 PM10/28/13
to fo-d...@googlegroups.com
Hi,

I recently found fo-dicom and like it a lot so far. It seems much more user friendly than GDCM.

I need to access the DICOM tag values for tags that are nested sometimes 2 or 3 levels deep in the tree structure. Can someone help me out with how the syntax would look for that? So far I can get top-level tags just fine using:

value = file.Dataset.Get<string>(DicomTag.IonBeamSequence,0);
OR
patientID = file.Dataset.Get<string>(DicomTag.PatientID);

where 0 is the index of the desired element in the list.

I hope the question is clear enough. Thanks!

Matias

unread,
Oct 28, 2013, 2:41:56 PM10/28/13
to fo-d...@googlegroups.com
Hi JR,

can you post an example of what attribute you're trying to access?

thanks,

JR

unread,
Oct 28, 2013, 3:14:13 PM10/28/13
to fo-d...@googlegroups.com
Sure. These are RTPLAN dicoms for radiation therapy treatment. For instance using the pydicom python library I would do this:

import dicom

dicomfile = dicom.read_file('dicom.dcm')

value = dicomfile.IonBeamSequence[0].IonRangeCompensatorSequence[0].CompensatorColumnOffset

Vladimir Tregub

unread,
Oct 29, 2013, 5:29:35 PM10/29/13
to fo-d...@googlegroups.com
First, you cannot call a generic method Get on a dataset with a type parameter <string> and an argument of type DicomSequence. If you look into the library's definition for T Get<T>(DicomTag tag, int n, T defaultValue) (in a source file DicomDataset.cs), you'll find out that for tags with VR="SQ" (dataset items of type DicomSequence), and if type T equals to <string>, this method throws a dicom data exception, and rightfully so.
 
Second, a fo-dicom syntax to access an element in a nested dataset looks similar to that of your reference, except that you should use a generic method Get on a dataset with a type parameter <DicomSequence> and there is no indexer to select a single nested dataset. So you write something like
 
var elementValue =
dicomfile.Dataset.Get<DicomSequence>(DicomTag.IonBeamSequence).Items[0]
                         .Get<DicomSequence>DicomTag.IonRangeCompensatorSequence).Items[0]
                         .Get<float>(DicomTag.CompensatorColumnOffset);
 
(if the type of CompensatorColumnOffset values is float).
 
Verbose, but spares reflection some times.

JR

unread,
Nov 1, 2013, 1:21:15 PM11/1/13
to fo-d...@googlegroups.com
Vladimir,

Thank you very much for your reply. What you said makes perfect sense. I'm a bit new to strongly-typed languages like C#, and now I understand where I went wrong.

Anand Hegde

unread,
Jul 7, 2014, 12:20:11 AM7/7/14
to fo-d...@googlegroups.com
Hi Friends,
Am new to this FO DICOM.

and am trying to access the nested attributes like accumulated dose values, study instance Uid etc

Please suggest me how can i proceed. Am using the following code mentioned in the above post and am getting instituation name.


But    var value = dcmFile.Dataset.Get<DicomSequence>(DicomTag.IonBeamSequence, 0);  giving me null value and even the elementValue giving null.


var dcmFile = DicomFile.Open(@"D:\rdsr's\test_rdsr.dcm");
                        string institutionName = dcmFile.Dataset.Get<string>(DicomTag.InstitutionName);

                        var value = dcmFile.Dataset.Get<DicomSequence>(DicomTag.IonBeamSequence, 0); 

                        var elementValue = dcmFile.Dataset.Get<DicomSequence>(DicomTag.IonBeamSequence).Items[0].Get<DicomSequence>(DicomTag.IonRangeCompensatorSequence).Items[0].Get<string>(DicomTag.IrradiationEventUID);

Please suggest me whats wrong here and how to correct.

Lucy

unread,
Dec 31, 2017, 10:51:04 AM12/31/17
to Fellow Oak DICOM
Hi, can u help me?
This is my code:
            var file = DicomFile.Open("RS1.3.6.1.4.1.2452.6.503803190.1155536865.1617709223.617388255.dcm");
            var elementValue = file.Dataset.Get<DicomSequence>(DicomTag.ROIContourSequence).Items[0].Get<DicomSequence>(DicomTag.ContourSequence).Items[0].Get<string>(DicomTag.ContourData);

I need to get data from tag ContourData, thats contains 3D coordinates. But the code only returns first x-coordinate.
Example: I have these coordinates: -17.173733\-263.064916\-275.000000\-16.633137\-263.035605\-275.000000\-16.098880\-262.948018\-275.000000\
and my code returns only -
17.173733.

How do I get all of them? thanks.

reini....@aon.at

unread,
Jan 1, 2018, 6:41:36 AM1/1/18
to Fellow Oak DICOM
See https://github.com/fo-dicom/fo-dicom/wiki/Getting-data
When the value of the tag is a sequence of floats (meaning it is of type float[]) and you access it with DataSet.Get<float>(DicomTag.ContourData) then fo-dicom cannot return you all the data because it does not match in type, but returns you by default the first one. To have the same behaviour with all the types, the code DataSet.Get<string>(DicomTag.ContourData) does return a string, but since the value is a array it by default returns only the first element.
If you want to access the elements separately then you can do with with an additional parameter, indicating which element you like to access. like
var x = DataSet.Get<float>(DicomTag.ContourData, 0);
var y = DataSet.Get<float>(DicomTag.ContourData, 1);
..

or you can get the whole array with
var coordinatesArray = DataSet.Get<float[]>(DicomTag.ContourData);
var x = coordinatesArray[0];...


Reply all
Reply to author
Forward
0 new messages