retrieve DICOM Tag value and store in a double/int variable.
Moderator: Moderator Team
-
- Posts: 7
- Joined: Tue, 2014-02-25, 11:00
retrieve DICOM Tag value and store in a double/int variable.
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.
-
- DCMTK Developer
- Posts: 2504
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
Re: retrieve DICOM Tag value and store in a double/int varia
See the first example in the documentation of the "dcmdata" module. Just use findAndGetFloat64() instead of findAndGetOFString().
-
- Posts: 7
- Joined: Tue, 2014-02-25, 11:00
Re: retrieve DICOM Tag value and store in a double/int varia
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 = ?????
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 = ?????
-
- Posts: 7
- Joined: Tue, 2014-02-25, 11:00
Re: retrieve DICOM Tag value and store in a double/int varia
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.
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.
-
- DCMTK Developer
- Posts: 2504
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
Re: retrieve DICOM Tag value and store in a double/int varia
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 :wink:](./images/smilies/icon_e_wink.gif)
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 :wink:](./images/smilies/icon_e_wink.gif)
-
- Posts: 7
- Joined: Tue, 2014-02-25, 11:00
Re: retrieve DICOM Tag value and store in a double/int varia
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;
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;
-
- DCMTK Developer
- Posts: 2504
- Joined: Tue, 2011-05-03, 14:38
- Location: Oldenburg, Germany
- Contact:
Re: retrieve DICOM Tag value and store in a double/int varia
If ref2d_filename is of type "std::string" or "OFString", then the ".at(1)" shouldn't be required -- this looks really strange.ref2d_filename.at(1).c_str() returns my DICOM file name.
If you are using a recent snapshot of the DCMTK, you could even pass the original string to loadFile()...
-
- Posts: 7
- Joined: Tue, 2014-02-25, 11:00
Re: retrieve DICOM Tag value and store in a double/int varia
Yes you are right. We can also write as "ref2d_filename.c_str()" as ref2d_filename is is a vector of <string>.
Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 1 guest