Unsolved Display grayscale image from Uint16 data type
Donn last edited by Donn
I have Uint16 * pixelData and convert it to uchar:
uchar * char_point = reinterpret_cast<uchar*>(pixelData);
Then I do the folllowing:
QLabel myLabel; QImage * qi = new QImage(char_point, 288, 288, QImage::Format_Indexed8); myLabel.setPixmap(QPixmap::fromImage(*qi)); myLabel.show();
I cannot display a grayscale image - tried all the Format options but no use. I have also tried some solution provided before but also didn't work. How to do it? The best image I can get is using QImage::Format_RGB555 and the result is (of course, I need grayscale):
If haven't used that format but from the top of my head, you also need to provided the color map matching your indexes.
There's no need to allocate the qi on the heap especially since you pass it right away to QPixmap.
On a side note, you are not converting your data from uint16 to uchar, you are just changing the type of pointer used to access them.
Donn last edited by
need to provided the color map matching your indexes
what do you mean by that?
The 8-bit part of the Pixel Manipulation chapter of QImage's documentation.
Donn last edited by
Am I not loosing data from Uint16 going to 8-bit? It is very important to be able to display uint16 bit pixel data. The pixel data is extracted using DCMTK library from DICOM images and therefore, I need to display it appropriately.
In that case you should consider using OpenGL.
kshegunov Moderators last edited by kshegunov
There's no way to loselessly convert 16 bit integers into 8 bit integers, so you can't use
QImageto display your image without dropping some of the information. I advise to follow @SGaist's advice and research what OpenGL provides and if that will suit your needs.
Please don't post multiple times the same question! I see tree distinct instances of you asking the same thing over and over again in a few hours period.