C++ 将uint16 dicom图像转换为qimage

C++ 将uint16 dicom图像转换为qimage,c++,qt,qimage,gdcm,C++,Qt,Qimage,Gdcm,我尝试转换从gdcm图像读取器读取的dicom图像,该读取器的光度解释为“单色2”,像素格式为无符号int 16或uint16,我尝试了以下代码,但没有给出所需的图像,请帮助 QVector<QRgb> table(2); for(int c=0;c<256;c++) { table.append(qRgb(c,c,c)); } std::cout << "thi

我尝试转换从gdcm图像读取器读取的dicom图像,该读取器的光度解释为“单色2”,像素格式为无符号int 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);
QVector表(2);
for(int c=0;csetColorTable(table);

关于

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

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

您需要执行以下操作:

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

您的输入和输出是什么样子的?多了解一些信息会很方便。显然,您正在降低颜色分辨率,这样最终图像看起来就不会像原始图像那么好,但这本身不应该是一个大问题(抖动可能会有所帮助)。