1

I'm trying to read a number of Siemens DICOM images with DCMTK, some of which are mosaic images. I'm looking for a quick way to find those.

What I can see with mosaic images is that this is specified in the ImageType tag, e.g.

$ dcmdump ${im0} | grep ImageType
(0008,0008) CS [ORIGINAL\PRIMARY\ASL\NONE\ND\NORM\MOSAIC] #  40, 7 ImageType

Most of the tags are easily read with findAndGetOFString() (or similar for floats etc), but if I do

tmpdata->findAndGetOFString(DCM_ImageType, tmpstring);
std::cout << "image type: " << tmpstring << "\n";           

for DcmDataset* tmpdata and OFString tmpstring, then the content of tmpstring is only ORIGINAL so the rest of the value is never printed.

In dcmdump it is printed, but there the value of DCM_ImageType never seems to be stored in a string, which I do need it to be.

Would there be a similar command to findAndGetOFString() for 'code strings'? Maybe I'm missing something obvious!

alle_meije
  • 2,424
  • 1
  • 19
  • 40

1 Answers1

1

Image Type (0008,0008) is a multi-valued attribute. That is, it may include several values which are separated by the backslash character. Note, that "officially", the backslash is not part of the attribute's value. It is a delimiter between several values of the attribute. This is what you have. So in terms of DICOM, there is no "one value" but multiple ones. The DCMTK API allows you to handle this (of course).

findAndGetOFString() has a third parameter ("index") to define which of the multiple values you want to obtain.

The behavior that you probably expect is what findAndGetOFStringArray() does.

As an alternative, you could iterate through the multiple values of the attribute by obtaining the "Value Multiplicity" first and then loop through the values like

DcmElement* element = tmpdata->findAndGetElement(DCM_ImageType);
int numberOfValues = element->getVM();
for(int index = 0; index < numberOfValues; index++)
{
    OFString valueAtIndex;
    element->GetOfString(valueAtIndex, index);
    /// ... your concatenation goes here...
}
Markus Sabin
  • 3,916
  • 14
  • 32
  • Thanks for showing this solution! Using this I quickly managed to put the sub-values in a vector of strings. Thanks also for suggesting `findAndGetOFStringArray()`, I have used that before. But that was when I knew the number of sub-elements -- I guess that if you already need `findAndGetElement()` to get the number of values, it's more efficient to just call `GetOFString()` on the already-available DcmElement. – alle_meije Jan 27 '22 at 08:28
  • If that is what you want to do, you could try to use a combination of element->getVM() and element->getOFStringArray(). Because element->getOfString() will certainly split the attribute content each time that you read one of the values. So in terms of efficiency it is probably better to read the string only once and split is yourself – Markus Sabin Jan 31 '22 at 07:33