我试图从Dicom文件打印图像。我将原始数据传递给convertToFormat_RGB888函数。据我所知,Qt无法处理单色的16位图像。如何在Qt中打印uint16单色图像?
这里的原始图像(转换为JPG这里): http://imageshack.us/photo/my-images/839/16bitc.jpg/
bool convertToFormat_RGB888(gdcm::Image const & gimage, char *buffer, QImage* &imageQt)
在这个函数中,我得到这里面......
...
else if (gimage.GetPixelFormat() == gdcm::PixelFormat::UINT16)
{
short *buffer16 = (short*)buffer;
unsigned char *ubuffer = new unsigned char[dimX*dimY*3];
unsigned char *pubuffer = ubuffer;
for (unsigned int i = 0; i < dimX*dimY; i++)
{
*pubuffer++ = *buffer16;
*pubuffer++ = *buffer16;
*pubuffer++ = *buffer16;
buffer16++;
}
imageQt = new QImage(ubuffer, dimX, dimY, QImage::Format_RGB888);
...
此代码是从这里开始有点不适应: gdcm.sourceforge.net/2.0/html/ConvertToQImage_8cxx-example.html
但是我原来的那个执行错误。至少我使用我的图像,但它不一样。
这里是新的图像(转换为JPG这里): http://imageshack.us/photo/my-images/204/8bitz.jpg/
我在做什么错? 谢谢。
使用第一个建议,我得到这个图像:http://imageshack.us/photo/my-images/802/answer.jpg/它很暗,但它更接近所需的。现在我试图改变颜色表,但我迷路了。我会阅读Qt的文档和Google,看看我能否改进。 – 2012-04-22 16:18:08
我试图改变颜色表,用QVector表(256);对于(int i = 0; i <256; ++ i) { table [i] = qRgb(i,i,i); } imageQt-> setColorTable(table); 我得到相同的图像。我卡住了。 –
2012-04-22 16:42:42
如何将buffer16的类型更改为unsigned short?从unsigned到signed的类型转换可能会搞砸。 – 2012-04-22 18:00:22