0

我试图转换从 gdcm 图像阅读器读取的 dicom 图像,该图像阅读器具有光度解释为“单色 2”和像素格式为无符号整数 16 或 uint16,我尝试了以下代码,但没有提供所需的图像,请帮忙。

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

问候

4

1 回答 1

0

我想我看到了你的问题。您正在将数据写入输出并在进行过程中递增指向输出的指针。

然后创建指向位图末尾的 QImage。

您需要执行以下操作:

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

编辑:你也不要推进输入指针。

您需要将内部循环更改为以下内容:

*output++ = (*input++) >> 8;
于 2012-06-26T09:24:59.070 回答