Inconsistency with findAndGetUint16Array

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
st80rules
Posts: 190
Joined: Tue, 2007-05-08, 17:45

Inconsistency with findAndGetUint16Array

#1 Post by st80rules »

Hi,

I have an image with Rows=512, Columns=512, BitStored=16, and when calling

Uint16* pixelData16 = nullptr;
unsigned long count = 0;
myImage.findAndGetUint16Array(DCM_PixelData, (const Uint16*&)pixelData16, &count);

count is equal to 524288 instead of 262144.

What is wrong here?

Thanks

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

Re: Inconsistency with findAndGetUint16Array

#2 Post by J. Riesmeier »

Two questions: Which version of the DCMTK did you use? What is the VR of the PixelData element?

st80rules
Posts: 190
Joined: Tue, 2007-05-08, 17:45

Re: Inconsistency with findAndGetUint16Array

#3 Post by st80rules »

dcmtk version is 3.6.5, and DCM_PixelData VR is EVR_OB.

Ok does this mean that I should not look at BitsStored? But only us the VR value? I've been using the BitsStored value for a long time and never had an issue like this. Does this mean the image file is not consistent?

I know, lot of questions...

Thank you!

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

Re: Inconsistency with findAndGetUint16Array

#4 Post by J. Riesmeier »

According to the DICOM standard, a value of BitsStored=16 (and BitsAllocated >= 16) is not allowed for PixelData with a VR of "OB" (see PS3.5 Section 8.2). That means, the DICOM dataset is invalid.

Also, DcmItem::findAndGetUint16Array() is not applicable to "OB" data (see API documentation). However, it might also be unexpected to a user of this function that the "count" parameter does not return the number of 16-bit values in the resulting array but the number of 8-bit values (because of VR=OB). I will think about it and come up with a solution.
Ok does this mean that I should not look at BitsStored? But only us the VR value? I've been using the BitsStored value for a long time and never had an issue like this.
You should use findAndGetUint16Array() only for PixelData with a VR of "OW". BitsStored has nothing to do with this encoding level.

st80rules
Posts: 190
Joined: Tue, 2007-05-08, 17:45

Re: Inconsistency with findAndGetUint16Array

#5 Post by st80rules »

Well, shouldn't findAndGetUint16Array() return an error in this case (when VR is "OB")?

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

Re: Inconsistency with findAndGetUint16Array

#6 Post by J. Riesmeier »

Well, internally PixelData is managed by a "polymorph OB/OW" class, so there is an implicit conversion between both encodings.

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

Re: Inconsistency with findAndGetUint16Array

#7 Post by J. Riesmeier »

Could you please check the following patch:

Code: Select all

--- a/dcmdata/libsrc/dcitem.cc
+++ b/dcmdata/libsrc/dcitem.cc
@@ -2555,10 +2555,8 @@ OFCondition DcmItem::findAndGetUint16Array(const DcmTagKey& tagKey,
     {
         if (status.good())
         {
-            *count = elem->getNumberOfValues();
-            /* AT uses two 16-bit integers per value */
-            if (elem->ident() == EVR_AT)
-                *count *= 2;
+            /* don't use getNumberOfValues() because of OB/OW for pixel data */
+            *count = elem->getLength() / sizeof(Uint16);
         } else
             *count = 0;
     }

st80rules
Posts: 190
Joined: Tue, 2007-05-08, 17:45

Re: Inconsistency with findAndGetUint16Array

#8 Post by st80rules »

Hi, apologies for the long delay, I only managed to try your patch today for reasons too long to explain.

The patch works correctly with my test case.

Thank you

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

Re: Inconsistency with findAndGetUint16Array

#9 Post by J. Riesmeier »

Thank you for your feedback. In the meantime, I've committed the required changes and pushed them to the public git repository.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest