0

i tried to convert a dicom image read from a gdcm image reader which has photometric interpretation as 'monochrome2' and pixel format as unsigned int 16 or uint16, i tried the following code over it, but is not giving the required image, please help.

        QVector<QRgb> table(2);
        for(int c=0;c<256;c++)
        {
            table.append(qRgb(c,c,c));
        }
        std::cout << "this is the format UINT16" << std::endl;
        int size = dimX*dimY*2; // length of data in buffer, in bytes
        quint8 * output = reinterpret_cast<quint8*>(buffer);
        const quint16 * input = reinterpret_cast<const quint16*>(buffer);
        do {
            *output++ = (*input) >> 8;
        } while (size -= 2);
        imageQt = new QImage(output, dimX, dimY, QImage::Format_Indexed8);
        imageQt->setColorTable(table);

regards

Goz
  • 61,365
  • 24
  • 124
  • 204
  • 1
    What does your input and output look like? A bit more information would be handy. Obviously you are reducing colour resolution so your final image will not look as good as the original but that shouldn't in itself, be a huge problem (Dithering may help though). – Goz Jun 26 '12 at 09:21

1 Answers1

0

I think I see your problem. You are writing the data to output and incrementing the pointer to output as you go along.

You then create the QImage pointing to the end of the bitmap.

You need to do the following:

imageQt = new QImage( reinterpret_cast< uchar* >( buffer ), dimX, dimY, QImage::Format_Indexed8);

Edit: Also you don't advance the input pointer.

You need to change your inner loop to the following:

*output++ = (*input++) >> 8;
Goz
  • 61,365
  • 24
  • 124
  • 204