[英]convert a uint16 dicom image to qimage
我嘗試轉換從gdcm圖像讀取器讀取的dicom圖像,該圖像讀取器的光度學解釋為“ monochrome2”,像素格式為unsigned 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);
問候
我想我看到你的問題了。 您正在將數據寫入輸出,並隨着操作不斷增加指針以輸出。
然后,創建指向位圖末端的QImage。
您需要執行以下操作:
imageQt = new QImage( reinterpret_cast< uchar* >( buffer ), dimX, dimY, QImage::Format_Indexed8);
編輯:同樣,您不前進輸入指針。
您需要將內部循環更改為以下內容:
*output++ = (*input++) >> 8;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.