Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

dcmtk: parsing DICOM files

2,581 views
Skip to first unread message

Tobias Wissmüller

unread,
Jan 29, 2003, 11:04:08 AM1/29/03
to
Hi,

I want to store the header of a DICOM file (images, dicomdir, etc.) in a
data structure I have created for my own.
I already have the DcmFileStream and the DcmFileFormat. The next logical
step would be to get a sequence with the attributes of the header from the
DcmFileFormat, but there is not such a possibility in dcmtk. I tried many
other ways but couldn't find one.
Could anyone give me a hint, an example or something? I would appreciate
everything. Thank you :-)

Bye,
Tobi


Thomas Wilkens

unread,
Jan 30, 2003, 2:20:34 AM1/30/03
to
Tobias,

You should've understood correctly that each DICOM file consists of two
parts:
1) a meta header (contais information that describes and identifies the
dataset which is captured
in the file (file preamble, DICOM prefix, group lenght, file meta
information version, media storage
SOP class UID, etc.) and
2) the actual DICOM object that contains the actual data which shall be
transmitted using the file

After a call to DcmFileFormat::loadFile(...), the information
which is encapsulated in the file will be available through the
DcmFileFormat object.
In detail, it will be available through calls to
DcmFileFormat::getMetaInfo() (for
meta header information) and DcmFileFormat::getDataset() (for data set
information,
i.e. DICOM object information).

Look out for these functions in dcmtk's source code and you will find an
example of how
to extract certain attribute values from DICOM files.

Regards,
Thomas Wilkens
OFFIS

Tobias Wissmüller schrieb in Nachricht ...

Joerg Riesmeier

unread,
Jan 30, 2003, 3:41:51 AM1/30/03
to
Tobi,

> I want to store the header of a DICOM file (images, dicomdir, etc.) in
> a data structure I have created for my own.

my colleague Thomas already explained the principles of how to access the
data stored in a DICOM file. As soon as you've loaded the fileformat you
can retrieve particular attributes by calling the findAndgetXXX() methods
defined in dcitem.h, e.g.:

OFString string;
DcmDataset *dataset = fileformat.getDataset();
if (dataset->findAndGetOFString(DCM_PatientsName, string).good())
cout << "Patient's Name: " << string << endl;

In case you're interested to traverse the complete dataset, e.g. in
order to copy its elements into your own data structure, you should take
a closer look at the nextObject() method also defined in dcitem.h.

Regards,
Joerg Riesmeier
OFFIS

Tobias Wissmüller

unread,
Feb 1, 2003, 12:02:45 PM2/1/03
to
Thank you Joerg and Thomas for your answers.

> In case you're interested to traverse the complete dataset, e.g. in
> order to copy its elements into your own data structure, you should take
> a closer look at the nextObject() method also defined in dcitem.h.

I'm doing it now with the nextObject() method and it's working. But there is
one thing I don't really understand.
Consider the following:

DcmStack stack;
metainfo -> nextObject(stack, 1);

Whereas metainfo is of DcmMetaInfo and gathered from a DcmFileFormat and so
on. Now, the cardinality of the stack should be 1 logically, but it is 2!
The two elements on the stack are the same: the first attribute of the
meta-header.

And with:
metainfo -> nextObject(stack, 0);
the stack cardinality is 0.

Why is it like that?

I am still having trouble to get the Attribute-Name and Attribute-Value. How
can I get these, e.g. as a string? There is nothing in DcmObject I could
use, because I do have everything as DcmObjects now after

DcmObject* dobj = stack.elem(0);

Do I have to do type checking or something like that?

Bye,
Tobias


Joerg Riesmeier

unread,
Feb 3, 2003, 4:34:25 AM2/3/03
to
Tobias,

> I'm doing it now with the nextObject() method and it's working.
> But there is one thing I don't really understand.

I know that the DcmStack and nextObject stuff is hard to understand.
The main reason for this is that the relevant methods are not yet
documented (very well). However, if you look into the implementation
of the nextObject method - preferably in dcitem.cc - you'll find out
that the stack is used for both input and output. If the stack is
empty the current object is pushed to it automatically, otherwise the
top element is used as the reference object.

To shorten things, here's a typical code fragment to traverse a
dataset (untested pseudo code):

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);
}

> I am still having trouble to get the Attribute-Name and Attribute-
> Value. How can I get these, e.g. as a string?

You have to typecast the DcmObject pointer to a DcmElement pointer
in order to get the attribute value (see above). The attribute tag
is available via getTag() returning a reference to the DcmTag object
which holds the name of the tag and the like.

I hope this helps ...

Regards,
Joerg Riesmeier
OFFIS


Tobias Wissmüller

unread,
Feb 5, 2003, 3:17:29 AM2/5/03
to
Hi Joerg,

thanks a lot for your help, it's working! :-) I do have a complete
fileformat parser now, that checks for every type and converts the values to
my data structure accordingly. I'll put it in my library of "useful dcmtk
adapter classes" someday :-)

Regards,
Tobi


"Joerg Riesmeier" <ne...@riesmeier.de> schrieb im Newsbeitrag
news:b1ld4n$8...@news.Informatik.Uni-Oldenburg.DE...

0 new messages