How to calculate the pixel data size of dicom image

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
angad
Posts: 112
Joined: Thu, 2010-02-18, 09:54

How to calculate the pixel data size of dicom image

#1 Post by angad »

Dear all,

I want to calculate the pixel data size and compare with the getLength() api of DcmPixelData object.

I am calculating as follows.

TotalPixelDataSize = FrameCount * SamplesPerPixel * rows * Col

TotalLength = getLength() from DcmPixelData element.

Could this getLegth() value equal to TotalPixelDataSize?

OR
How can I calculate the getLength() value from the dicom headers for the pixelDataSize?

Thanks and regards
Angad

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#2 Post by Jörg Riesmeier »

This is not that easy, even in the uncompressed case. E.g., you also have to consider the value of BitsAllocated.

Btw, what is the background of your question?

angad
Posts: 112
Joined: Thu, 2010-02-18, 09:54

#3 Post by angad »

Hi,

Thanks for the reply.

The background is that,

I have some dicom files (Corrupted) where pixel data size is not there completely.

So when I try to read them my viewer, it crashes.

I thought that by calculating and comparing this way, I can avoid reading such files if they are not equal.

This worked for some of my corrupted dicom cases, but as you said, there could be many more scenarios where correct dicom file could be treated as corrupted.

BTW, I am using findAndGetxxxArray api and count returned by the getLength() inside the above api ( as I can see in the DCMTK 3.5.4 source code).


Bottom line :
How can I avoid reading corrupted dicom files pixel data?

What is the unit of getLength() ?
Is it bytes or no of pixels it read.

Jörg Riesmeier
ICSMED DICOM Services
ICSMED DICOM Services
Posts: 2217
Joined: Fri, 2004-10-29, 21:38
Location: Oldenburg, Germany

#4 Post by Jörg Riesmeier »

The method getLength() returns the length (in bytes) of the stored value, which might be padded to an even length (according to the requirements of the DICOM standard).
I now understand your use case, and in fact we've implemented something similar in the dcmimgle/dcmimage class library. So, why are you not using the DicomImage class?

Post Reply

Who is online

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