【发布时间】: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);
问候
【问题讨论】:
-
你的输入输出是什么样的?多一点信息会很方便。显然,您正在降低颜色分辨率,因此您的最终图像看起来不会像原始图像那么好,但这本身不应该是一个大问题(虽然抖动可能会有所帮助)。