Display grayscale image from Uint16 data type
-
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):
-
Hi,
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.
-
The 8-bit part of the Pixel Manipulation chapter of QImage's documentation.
-
In that case you should consider using OpenGL.
-
@Donn
There's no way to loselessly convert 16 bit integers into 8 bit integers, so you can't useQImage
to 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.PS.
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.
http://forum.qt.io/topic/64650/display-2d-array-of-type-uint16-as-grayscale-image
http://forum.qt.io/topic/64657/display-uint16-image