【问题标题】:convert a uint16 dicom image to qimage将 uint16 dicom 图像转换为 qimage
【发布时间】:2012-06-26 17:27:56
【问题描述】:

我尝试转换从 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);

问候

【问题讨论】:

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

标签: c++ qt qimage gdcm


【解决方案1】:

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

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

您需要执行以下操作:

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

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

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

*output++ = (*input++) >> 8;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-07-21
    • 1970-01-01
    • 2021-01-22
    • 1970-01-01
    • 2016-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多