Dear Ana,

I only took a superficial look at your code and I do not know the

details of the pixelmed library, but it looks like, for the

computation of the _signBit and _signMask, you are assuming that

images which do not have a sample mode with DataType = TYPE_BYTE are

always 16-bit images (_signBit = 0x8000, _signMask = 0xffff8000).

If the samples stored in your BufferedImage respect the original Pixel

Data samples, you may also have, for instance, 10-bit or 12-bit

images. If this was the case, the sign bit and the sign mask should be

different (starting not at bit 15, but at bit 9 or 11...).

Hope these considerations may help you.

Regards,

Marco.

"ana65"wrote in message news:<41a908fd$1_3@news.bluewin.ch>...

> hello,

>

> I am using the pixelmed library to construct a 3D volume given a set of MRI

> and CT slices.

> I am using the excellent pixelmed library, but unfortunatly I am a little

> lost. I would appreciate your comments on what I could be doing wrong. I

> have spent many hours going over the DICOM group emails with a colleague of

> mine, and could only find bits and pieces and was not able to put it all

> together (so it seems).

>

> My problem in short is how to decode the value of the pixels correctly for

> signed and unsigned images. In the messages I read it indicates that I need

> to do the following steps:

>

> 1 - get the stored values

> 2 - mask unsigned pixels

> or sign extend negative pixles for ImageRepresentation = 1

> 3 - Scale the resulting value using the slope and intercept.

>

> I am assuming the above holds for both MR and CT, but it doesn't seem to

> work.

> The main problem seems to be that I am not handeling the signed images well

> and

> some of the values of the pixels are not in the expected range (what to

> expect

> with the given bits stored).

>

> sorry for putting code in my email, I think it would be very easy to follow

> though. Thanks.

>

> Ana,

>

> ------------------------------------

>

> To read the pixels from each slice I do the following:

>

> // Obtain the buffered image for the slice

> img = new com.pixelmed.display.SourceImage(list);

> ibuff = img.getBufferedImage();

>

> for all rows

> for all columns

>

> // Get the stored sample values (assuming 1 sample images).

> int[] sv = ibuff.getSampleModel().getPixel(x, y, (int[]) null,

> ibuff.getRaster().getDataBuffer());

>

> // Reading 0th band sample and mask unsigned pixels (see below what _valMask

> is equal to)

> val = (_signed) ? sv[0]: sv[0] & _valMask;

>

> // Sign extend negative pixels

> if (_signed && (val & _signBit) != 0)

> val |= _signMask;

>

> // Rescale slope & intercept

> val = (int) Math.round(_slope * val + _intercept);

>

> // Calculate min/max for histogram calculation

> if (_vmin > val)

> _vmin = val;

> if (_vmax < val)

> _vmax = val;

>

> // Voxel value

> _volume[z * _nxy + y * _nx + x] = val;

>

> end of colums

> end of rows

>

> The _signBit and _signMask are calculated as follow:

>

> if (_signed == true) {

>

> if (img.getBufferedImage().getSampleModel().getDataTy pe()

> == java.awt.image.DataBuffer.TYPE_BYTE) {

>

> _signBit = 0x0080;

> _signMask = 0xffffff80;

>

> } else { // assume short or ushort

>

> _signBit = 0x8000;

> _signMask = 0xffff8000;

>

> }

>

> }

>

>

> The _valMask used to mask the unsiged pixels is calculated using the bits

> stored as follows (from the pixelmed library):

>

> _valMask = 0;

> int stored = _bitpix; // bits stored

> while (stored-- > 0) {

> _valMask = (_valMask << 1) | 1;

> }