Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Display grayscale image from Uint16 data type

    General and Desktop
    display image grayscale qimage setpixmap
    3
    7
    4398
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Donn
      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):

      http://i.imgur.com/rmLMlK8.jpg

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • Donn
          Donn last edited by

          @SGaist said:

          need to provided the color map matching your indexes

          what do you mean by that?

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            The 8-bit part of the Pixel Manipulation chapter of QImage's documentation.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • Donn
              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.

              kshegunov 1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                In that case you should consider using OpenGL.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply Reply Quote 0
                • kshegunov
                  kshegunov Moderators @Donn last edited by kshegunov

                  @Donn
                  There's no way to loselessly convert 16 bit integers into 8 bit integers, so you can't use QImage 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

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post