retrieve DICOM Tag value and store in a double/int variable.

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
SubhraSundar
Posts: 7
Joined: Tue, 2014-02-25, 11:00

retrieve DICOM Tag value and store in a double/int variable.

#1 Post by SubhraSundar »

I am a new user of DICOM. I want to read a specific DICOM Tag value from a .dcm file and store that value in a variable of type Double. I am using C++ and working on 2D-3D registration. Please help.

J. Riesmeier
DCMTK Developer
Posts: 2496
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: retrieve DICOM Tag value and store in a double/int varia

#2 Post by J. Riesmeier »

See the first example in the documentation of the "dcmdata" module. Just use findAndGetFloat64() instead of findAndGetOFString().

SubhraSundar
Posts: 7
Joined: Tue, 2014-02-25, 11:00

Re: retrieve DICOM Tag value and store in a double/int varia

#3 Post by SubhraSundar »

Thank you Riesmeier.

I wrote a code till this point: But then I am confused. Can you help me?

OFCondition status;
DcmFileFormat fileformat;

status = fileformat.loadFile( ref2d_filename.at(1).c_str(), EXS_Unknown, EGL_noChange, DCM_MaxReadLength, ERM_metaOnly );
DcmElement *element = NULL;
DcmDataset *dataset = fileformat.getDataset();
dataset->findAndGetElement(DcmTagKey(0x0018,0x1510), element);
float p;
p = ?????

SubhraSundar
Posts: 7
Joined: Tue, 2014-02-25, 11:00

Re: retrieve DICOM Tag value and store in a double/int varia

#4 Post by SubhraSundar »

Finally I could write this, as you suggested to use findAndGetFloat64. But I am getting a "0" value while the value is "35.75"


OFCondition status;
DcmFileFormat fileformat;

status = fileformat.loadFile( ref2d_filename.at(1).c_str(), EXS_Unknown, EGL_noChange, DCM_MaxReadLength, ERM_metaOnly );
double x ;
DcmDataset *dataset = fileformat.getDataset();
dataset->findAndGetFloat64(DcmTagKey(0x0018,0x1510), x);
cout<<x;


So, I am confused again.

J. Riesmeier
DCMTK Developer
Posts: 2496
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: retrieve DICOM Tag value and store in a double/int varia

#5 Post by J. Riesmeier »

1. What should "ref2d_filename.at(1).c_str()" represent?
2. Why are you specifying all those loadFile() parameters that have a default value (and you don't seem to understand)?
2.1 The last parameter of loadFile() specifies that you are only interested in the file meta information header.
3. Why do you use "DcmTagKey(0x0018,0x1510)" instead of DCM_PositionerPrimaryAngle?
4. Why don't you check the return value of findAndGetFloat64()?
5. [...]

The reason for your problem is item 2.1 in the above list :wink:

SubhraSundar
Posts: 7
Joined: Tue, 2014-02-25, 11:00

Re: retrieve DICOM Tag value and store in a double/int varia

#6 Post by SubhraSundar »

Now its working fine. Thank you very much Riesmeier. Hope you will like it now
ref2d_filename.at(1).c_str() returns my DICOM file name.

------------------------------

OFCondition status;
DcmFileFormat fileformat;
double value ;
status = fileformat.loadFile( ref2d_filename.at(1).c_str());

if (status.good())
{
DcmDataset *dataset = fileformat.getDataset();
status = dataset->findAndGetFloat64(DCM_PositionerPrimaryAngle, value);
if( status.good() )
cout<<value;
else
cerr<<"Error: Couldn't get the value of PositionerPrimaryAngle ( "<<status.text()<<" )"<<endl;
}
else
cerr<<"Error: Couldn't read DICOM file ( "<<status.text()<<" )"<<endl;

J. Riesmeier
DCMTK Developer
Posts: 2496
Joined: Tue, 2011-05-03, 14:38
Location: Oldenburg, Germany
Contact:

Re: retrieve DICOM Tag value and store in a double/int varia

#7 Post by J. Riesmeier »

ref2d_filename.at(1).c_str() returns my DICOM file name.
If ref2d_filename is of type "std::string" or "OFString", then the ".at(1)" shouldn't be required -- this looks really strange.
If you are using a recent snapshot of the DCMTK, you could even pass the original string to loadFile()...

SubhraSundar
Posts: 7
Joined: Tue, 2014-02-25, 11:00

Re: retrieve DICOM Tag value and store in a double/int varia

#8 Post by SubhraSundar »

Yes you are right. We can also write as "ref2d_filename.c_str()" as ref2d_filename is is a vector of <string>.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest