quick question re. calling findAndGetSint16Array

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
nalexander
Posts: 7
Joined: Thu, 2008-03-20, 23:55

quick question re. calling findAndGetSint16Array

#1 Post by nalexander »

Hi,
I'm just wondering if anyone can help me write the correct parameters in the call to findAndGetSint16Array below. I get an error reading pixel data: "Illegal call, perhaps wrong parameters".
I'm also pretty sure the number of elements in the buffer shouldn't be 262144 (which I chose because the image is 512x512). I don't know what it should be. Here is how my image is encoded:
- pixel representation = 1 (16-bit signed short)
- bits allocated = 16
- bits stored = 16
- high bit = 15
- value representation = OW

Here is the code where I try to read the pixel data:

Code: Select all

         unsigned long pdatacount = 262144;
	  const Sint16* pdata; // short or Sint16??
	  status = fileformat.getDataset()->findAndGetSint16Array(DCM_PixelData, pdata, &pdatacount, false);
	  if (status.bad()) {
		cout << "\n\nError reading pixel data: (" << status.text() << ")." << endl;
		}
I will appreciate any help very much.

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

#2 Post by st80rules »

I'm not an authority on DCMTK, but I always read the pixel data with findAndGetUint16Array, and interpret the data myself (thus casting to Sint16 if necessary).

Normand

nalexander
Posts: 7
Joined: Thu, 2008-03-20, 23:55

#3 Post by nalexander »

Thanks for responding. Does everything else look okay to you (specifically the number of elements, 262144)?
I'm a novice, so I'm not sure how to interpret/handle signed numbers read as unsigned. (And I'm additionally confused by the fact that my image depth is supposedly 17 bits/sample -- I figured it would be 16 since it is already in 2's complement.)
Could you please paste a couple of lines of code you've written that does this? I'd really appreciate it.

N. Alexander

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

#4 Post by st80rules »

Hmm, I don't quite follow you.

512x512 is indeed 262144, so where's the problem? And I don't see why you expect 17 bits/sample.

It can be as simple as this:

unsigned long pcount; // Leave it empty, it's a placeholder for a return value
const Uint16* pdata;
status = fileformat.getDataset()->findAndGetUint16Array(DCM_PixelData, pdata, &pcount;

pcount should be equal to 262144 if the DICOM file is indeed 512x512.

You can just cast the data to Sint16* to get signed results.

Normand

nalexander
Posts: 7
Joined: Thu, 2008-03-20, 23:55

#5 Post by nalexander »

Ah, thank you for that bit of code. I'm not getting the error any more! I will probably post questions as I run into more problems soon :p

As for the 17 bits/sample, that is not what I expect. It is what getDepth (from DicomImage) tells me the depth is.. That is what's confusing me.

Thanks again.

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

#6 Post by Jörg Riesmeier »

As for the 17 bits/sample, that is not what I expect. It is what getDepth (from DicomImage) tells me the depth is.. That is what's confusing me.
This is probably because of the Modality LUT Transformation that is stored in the image file. DicomImage::getDepth() returns the number of bits of the internal intermediate pixel representation.

nalexander
Posts: 7
Joined: Thu, 2008-03-20, 23:55

#7 Post by nalexander »

Ahh, I see. Thank you.
If I need the pixel data for segmentation purposes (so initially for making histograms of different regions in the image), is this (findAndGet....) the correct way to obtain pixel values? Or should I be using intermediate values of the pixels?

And, Normand, is this correct for the type casting? (outputting the values is useless, I know):

Code: Select all

for (int counter=0; counter<pdatacount; counter++) {
			  cout << "pixel #" << counter << ": " << (Sint16)pdata[counter];
}
Thanks again!

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

#8 Post by Jörg Riesmeier »

... is this (findAndGet....) the correct way to obtain pixel values? Or should I be using intermediate values of the pixels?
This depends on whether you need raw pixel data (as stored in the image file) or pixel data where the Modality LUT transformation (if present) is already applied. The latter (using DicomImage's internal representation provided by DicomImage::getInterData()) has also the advantage that alignment and sign extension of the pixel values is already performed.

Post Reply

Who is online

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