How to override incorrectly labeled VR values

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
spencermanwell
Posts: 4
Joined: Thu, 2023-11-09, 17:46

How to override incorrectly labeled VR values

#1 Post by spencermanwell »

I've recently come across a PET series for which the VR for a date time (DT) attribute is was set to unknown (UN) by the scanner that acquired it. Note that the transfer syntax for this data set is Little Endian - Explicit.

I am using code like following to extract the Radiopharmaceutical Start Date Time attribute (0018,1078) from one of these files.

Code: Select all

DcmFileFormat fileFormat;
fileFormat.loadFile( fileName );
DcmDataset* datasetItem = fileFormat.getDataset();
OFString dminDateTimeStr = "";
datasetItem->findAndGetOFString( DCM_RadiopharmaceuticalStartDateTime, adminDateTimeStr, 0, OFTrue );
I've inspected the DICOM header for the file that is used in the block above and confirmed that there is a valid date time value for this attribute, but the value that gets returned to the OFString is nonsensical.

From reading other post about similar issues, I get the impression that if the VR is set to "UN" then the underlying getOFString(...) call will interpret the element as containing binary data. Which is consistent with the value that is being inserted in the OFString input argument to the call to findAndGetOFString(...).

Since I have no control over how these DICOM images are being created, I would like to be able to handle issues like these if/when they occur.

Can anyone propose a way in which I can override the VR value for this field prior to retrieve its value so that it can be interpreted correctly?

Any help would be greatly appreciated!

Spencer

Michael Onken
DCMTK Developer
Posts: 2067
Joined: Fri, 2004-11-05, 13:47
Location: Oldenburg, Germany
Contact:

Re: How to override incorrectly labeled VR values

#2 Post by Michael Onken »

Hi Spencer,

it should not matter if the attribute is stored with data type UN in the file as long DCMTK knows it and fix the VR by looking it up in the dictionary when loading it into memory. Maybe something with the dictionary is wrong, or you haven't loaded one. Let's try to find out what happens.
  • Are you on Windows or a Unix-like system?
  • What happens if you read other string values, like the Patient Name?
  • What value is shown when you print the "binary data" that you received? (e.g. std::cout << dminDateTimeStr << std::endl)
  • Try to use findAndGetOFStringArray() instead and get all values, maybe the attribute value is multi-valued (though it is not permitted) and you only get the first value (0) right now. findAndGetOFStringArray() will give you all values.
  • Have you tried dcmdump on the file? Preferably a downloaded version. Then use also datasetItem->print() to print a dump from your own application. Check for differences and in general whether the datetime and the rest of the values look fine in both printed versions.
Best regards,
Michael

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

Re: How to override incorrectly labeled VR values

#3 Post by J. Riesmeier »

I've recently come across a PET series for which the VR for a date time (DT) attribute is was set to unknown (UN) by the scanner that acquired it.
[...]
Can anyone propose a way in which I can override the VR value for this field prior to retrieve its value so that it can be interpreted correctly?
You need to enable a specific global flag for this purpose. This is done by adding the following line to your code:

Code: Select all

dcmEnableUnknownVRConversion.set(OFTrue);
Here is the explanation from DCMTK's source code:

Code: Select all

/** Global flag to enable/disable the automatic re-conversion of defined
 *  length UN elements read in an explicit VR transfer syntax, if the real
 *  VR is defined in the data dictionary.
 */

spencermanwell
Posts: 4
Joined: Thu, 2023-11-09, 17:46

Re: How to override incorrectly labeled VR values

#4 Post by spencermanwell »

@Michael Onken

Thanks for your reply!

I've responded to your questions below. Sorry for the delay.
Are you on Windows or a Unix-like system?
- Windows
What happens if you read other string values, like the Patient Name?
- Almost all fields, including the Patient Name are being interpreted the way I'd expect.
What value is shown when you print the "binary data" that you received? (e.g. std::cout << dminDateTimeStr << std::endl)
- "32"
Try to use findAndGetOFStringArray() instead and get all values, maybe the attribute value is multi-valued (though it is not permitted) and you only get the first value (0) right now. findAndGetOFStringArray() will give you all values.
- Results in the string: "32\30\32\33\31\31\30\37\31\31\30\36\30\30\2e\30\30\20"
Have you tried dcmdump on the file? Preferably a downloaded version. Then use also datasetItem->print() to print a dump from your own application. Check for differences and in general whether the datetime and the rest of the values look fine in both printed versions.
- datasetItem->print(), produces this: " (0018,1078) UN 32\30\32\33\31\31\30\37\31\31\30\36\30\30\2e\30\30\20 # 18, 1 RadiopharmaceuticalStartDateTime"
- I don't have the dcmdump exectuable, but the I've used the DVTk DICOM Editor exe to examine the file and it displays correctly as:
-- >(0018,1078) Radiopharmaceutical Start Datetime DT 1 20231107110600.00
- Note the VRs are different between these two.
- I've also examined the file using a HEX Editor and I can see that the file clearly indicates that the VR is UN for this field and the the HEX elements that follow the tag in the match those shown in the output of datasetItem->print(): 32 30 32 33 31 31 30 37 31 31 30 36 30 30 2e 30 30 20

I am not sure if there is a specific dictionary that is being specified. I have always assumed that default tag definitions (inclusive of VR) were being referenced. Does the dcmtk source get distributed with a dictionary file? Can you comment on how to reference it when loading a DICOM file? A quick look online suggested to me that when dcmtk is built on windows system the default behaviour is to use a built-in DICOM dict.

@J. Riesmeier

Thanks for your reply as well.

In which scope should the call to

Code: Select all

dcmEnableUnknownVRConversion.set(OFTrue);
be made? Does this function belong so a certain class?

spencermanwell
Posts: 4
Joined: Thu, 2023-11-09, 17:46

Re: How to override incorrectly labeled VR values

#5 Post by spencermanwell »

J. Riesmeier wrote: Fri, 2023-11-10, 09:30 You need to enable a specific global flag for this purpose. This is done by adding the following line to your code:

Code: Select all

dcmEnableUnknownVRConversion.set(OFTrue);
I just confirmed that this resolved the issue by making the call in the same function noted in my original post.

My application will instantiate numerous DcmFileFormat objects, does this call need to made for each instance? Or does it set a a global flag within the dcmtk environment that I am linking to my source code?

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

Re: How to override incorrectly labeled VR values

#6 Post by J. Riesmeier »

This is a global flag, so it has a global scope. It is, therefore, sufficient so set it to "OFTrue" once, e.g. at program start.

spencermanwell
Posts: 4
Joined: Thu, 2023-11-09, 17:46

Re: How to override incorrectly labeled VR values

#7 Post by spencermanwell »

Excellent, thank you very much for your help.

Post Reply

Who is online

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