DICOM @ OFFIS

Discussion Forum for OFFIS DICOM Tools - For registration, send email with desired user name to the OFFIS DICOM team
It is currently Tue, 2017-10-24, 01:27

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
PostPosted: Tue, 2014-02-25, 11:06 
Offline

Joined: Tue, 2014-02-25, 11:00
Posts: 7
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.


Top
 Profile  
 
PostPosted: Tue, 2014-02-25, 12:42 
Offline
DCMTK Developer

Joined: Tue, 2011-05-03, 14:38
Posts: 1867
Location: Oldenburg, Germany
See the first example in the documentation of the "dcmdata" module. Just use findAndGetFloat64() instead of findAndGetOFString().


Top
 Profile  
 
PostPosted: Tue, 2014-02-25, 12:54 
Offline

Joined: Tue, 2014-02-25, 11:00
Posts: 7
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 = ?????


Top
 Profile  
 
PostPosted: Tue, 2014-02-25, 13:06 
Offline

Joined: Tue, 2014-02-25, 11:00
Posts: 7
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.


Top
 Profile  
 
PostPosted: Tue, 2014-02-25, 13:15 
Offline
DCMTK Developer

Joined: Tue, 2011-05-03, 14:38
Posts: 1867
Location: Oldenburg, Germany
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:


Top
 Profile  
 
PostPosted: Tue, 2014-02-25, 13:49 
Offline

Joined: Tue, 2014-02-25, 11:00
Posts: 7
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;


Top
 Profile  
 
PostPosted: Tue, 2014-02-25, 13:52 
Offline
DCMTK Developer

Joined: Tue, 2011-05-03, 14:38
Posts: 1867
Location: Oldenburg, Germany
Quote:
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()...


Top
 Profile  
 
PostPosted: Tue, 2014-02-25, 14:37 
Offline

Joined: Tue, 2014-02-25, 11:00
Posts: 7
Yes you are right. We can also write as "ref2d_filename[i].c_str()" as ref2d_filename is is a vector of <string>.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

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


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group