Constructing a 3D volume from DICOM slices using pixelmed library, - DICOM

This is a discussion on Constructing a 3D volume from DICOM slices using pixelmed library, - DICOM ; 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 ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Constructing a 3D volume from DICOM slices using pixelmed library,

  1. Constructing a 3D volume from DICOM slices using pixelmed library,

    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;
    }










  2. Re: Constructing a 3D volume from DICOM slices using pixelmed library,

    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;
    > }


  3. Re: Constructing a 3D volume from DICOM slices using pixelmed library,

    Thanks Marco,

    I went back to using an older version of the pixelmed library and the code
    worked ok. Thanks for your comments. I think my problem is that I wasn't
    really sure if the images returned by the library already accounted for
    the intercept/slope and the "extend sign" for -ve voxels and "mask"
    unsigned ones.

    At this time I am assuming that I have to do that my self and I am using
    the code that I posted below (sorry I don't like to post as much code, I
    appolojize) and it seems to be working well.

    I keep checking the pixelmed site every couple of days looking for a new
    version. Great library, cannot wait for the book.

    Thanks,
    Ana


    On Wed, 01 Dec 2004 03:50:05 -0800, Marco wrote:

    > 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.
    >
    >



+ Reply to Thread